@vintcessun: 1000万向量31GB压到4GB,搜索还比FAISS快——这事有点离谱,但turbovec真做到了。核心是Google TurboQuant的数据无关量化,无需训练、不用调参,加向量即索引。手写NEON/AVX-512核实打实快12-20…
摘要
turbovec 基于 Google TurboQuant 算法,将 1000 万向量从 31GB 压缩到 4GB,搜索速度比 FAISS 快 12-20%,支持过滤搜索,提供 Rust 实现和 Python 包。
查看缓存全文
缓存时间: 2026/06/08 03:37
1000万向量31GB压到4GB,搜索还比FAISS快——这事有点离谱,但turbovec真做到了。核心是Google TurboQuant的数据无关量化,无需训练、不用调参,加向量即索引。手写NEON/AVX-512核实打实快12-20%,支持搜索时按id过滤,直接省掉大量后处理折腾。Rust底层 + pip install即用,维护成本压到极低。
RyanCodrai/turbovec
Source: https://github.com/RyanCodrai/turbovec
A 10 million document corpus takes 31 GB of RAM as float32. turbovec fits it in 4 GB - and searches it faster than FAISS.
turbovec is a Rust vector index with Python bindings, built on Google Research’s TurboQuant algorithm — a data-oblivious quantizer that matches the Shannon lower bound on distortion, with no codebook training and no separate train phase.
- Online ingest. Add vectors, they’re indexed — no train step, no parameter tuning, no rebuilds as the corpus grows.
- Faster than FAISS. Hand-written NEON (ARM) and AVX-512BW (x86) kernels beat FAISS IndexPQFastScan by 12–20% on ARM and match-or-beat it on x86.
- Filter at search time. Pass an id allowlist (or a slot bitmask) to
search()and the kernel honours it directly. You always get up tokresults from the allowed set — no over-fetching, no recall hit on selective filters. - Pure local. No managed service, no data leaving your machine or VPC. Pair with any open-source embedding model for a fully air-gapped RAG stack.
Building RAG where privacy, memory, or latency matters? You’re in the right place.
Python
pip install turbovec
from turbovec import TurboQuantIndex
index = TurboQuantIndex(dim=1536, bit_width=4)
index.add(vectors)
index.add(more_vectors)
scores, indices = index.search(query, k=10)
index.write("my_index.tq")
loaded = TurboQuantIndex.load("my_index.tq")
Need stable ids that survive deletes? Use IdMapIndex:
import numpy as np
from turbovec import IdMapIndex
index = IdMapIndex(dim=1536, bit_width=4)
index.add_with_ids(vectors, np.array([1001, 1002, 1003], dtype=np.uint64))
scores, ids = index.search(query, k=10) # ids are your uint64 external ids
index.remove(1002) # O(1) by id
index.write("my_index.tvim")
loaded = IdMapIndex.load("my_index.tvim")
Hybrid retrieval (filtered search)
Restrict results to a candidate set produced by another system (SQL, BM25, ACL, time window, …):
import numpy as np
from turbovec import IdMapIndex
idx = IdMapIndex(dim=1536, bit_width=4)
idx.add_with_ids(vectors, ids)
# Stage 1: external system narrows to candidate ids.
allowed = np.array(db.execute("SELECT id FROM docs WHERE tenant=?", (t,)).fetchall(),
dtype=np.uint64)
# Stage 2: dense rerank within the candidate set.
scores, ids = idx.search(query, k=10, allowlist=allowed)
Filtering happens inside the SIMD kernel at 32-vector block granularity: blocks with no allowed slots are short-circuited before any LUT lookup or scoring work, and individual non-allowed slots inside scored blocks are dropped at heap-insert. Selective allowlists (small fraction of the index allowed) therefore avoid most of the SIMD cost rather than paying it and discarding the result afterwards.
The output length is min(k, len(allowed)) — when the allowlist is smaller than k you get exactly len(allowed) results rather than padded fallbacks.
See docs/api.md for the full reference.
Framework integrations
Drop-in replacements for the in-tree reference vector / document stores in each framework. Same public surface, same persistence semantics, same retriever and pipeline wiring — swap the import and keep your pipeline.
- LangChain —
pip install turbovec[langchain]· replaceslangchain_core.vectorstores.InMemoryVectorStore - LlamaIndex —
pip install turbovec[llama-index]· replacesllama_index.core.vector_stores.SimpleVectorStore - Haystack —
pip install turbovec[haystack]· replaceshaystack.document_stores.in_memory.InMemoryDocumentStore - Agno —
pip install turbovec[agno]· replacesagno.vectordb.lancedb.LanceDb
Rust
cargo add turbovec
use turbovec::TurboQuantIndex;
let mut index = TurboQuantIndex::new(1536, 4);
index.add(&vectors);
let results = index.search(&queries, 10);
index.write("index.tv").unwrap();
let loaded = TurboQuantIndex::load("index.tv").unwrap();
For stable external ids that survive deletes:
use turbovec::IdMapIndex;
let mut index = IdMapIndex::new(1536, 4);
index.add_with_ids(&vectors, &[1001, 1002, 1003]);
let (scores, ids) = index.search(&queries, 10);
index.remove(1002);
index.write("index.tvim").unwrap();
let loaded = IdMapIndex::load("index.tvim").unwrap();
Recall
TurboQuant vs FAISS IndexPQ (LUT256, nbits=8) — the paper’s Section 4.4 baseline. 100K vectors, k=64. FAISS PQ sub-quantizer counts sized to match TurboQuant’s bit rate (m=d/4 at 2-bit, m=d/2 at 4-bit).
Across OpenAI d=1536 and d=3072, TurboQuant beats FAISS by 0.4–3.4 points at R@1 across 2-bit and 4-bit, and both converge to 1.0 by k=4. GloVe d=200 is the harder regime — at low dim the asymptotic Beta assumption is looser. TurboQuant beats FAISS by 0.3 points at 4-bit and trails by 1.2 points at 2-bit at R@1, both closing to FAISS by k≈16.
A note on baselines. We compare against FAISS IndexPQ (LUT256, nbits=8, float32 LUT) because it’s the default production-grade PQ most users would reach for. This is a stronger baseline than the custom u8-LUT PQ in the TurboQuant paper — FAISS uses a higher-precision LUT at scoring time and k-means++ for codebook training. We reproduce the paper’s TurboQuant numbers on OpenAI d=1536 / d=3072 and hit similar numbers to other community reference implementations on low-dim embeddings (see turboquant-py at d=384). The visible gap on GloVe reflects FAISS being a strong baseline, not a TurboQuant implementation issue.
Full results: d=1536 2-bit, d=1536 4-bit, d=3072 2-bit, d=3072 4-bit, GloVe 2-bit, GloVe 4-bit.
Compression
Search Speed
All benchmarks: 100K vectors, 1K queries, k=64, median of 5 runs.
ARM (Apple M3 Max)
On ARM, TurboQuant beats FAISS FastScan by 12–20% across every config.
x86 (Intel Xeon Platinum 8481C / Sapphire Rapids, 8 vCPUs)
On x86, TurboQuant wins every 4-bit config by 1–6% and runs within ~1% of FAISS on 2-bit ST. The 2-bit MT rows (d=1536 and d=3072) are the only configs sitting slightly behind FAISS (2–4%), where the inner accumulate loop is too short for unrolling amortization to match FAISS’s AVX-512 VBMI path.
How it works
Each vector is a direction on a high-dimensional hypersphere. TurboQuant compresses these directions using a simple insight: after applying a random rotation, every coordinate follows a known distribution – regardless of the input data.
1. Normalize. Strip the length (norm) from each vector and store it as a single float. Now every vector is a unit direction on the hypersphere.
2. Random rotation. Multiply all vectors by the same random orthogonal matrix. After rotation, each coordinate independently follows a Beta distribution that converges to Gaussian N(0, 1/d) in high dimensions. This holds for any input data – the rotation makes the coordinate distribution predictable.
3. Per-coordinate calibration (TQ+). The Beta distribution from step 2 is asymptotic — at finite dimensions, individual coordinates drift from the canonical shape (especially low-bit and word-vector-style embeddings). TQ+ fits two scalars per coordinate — a shift and a scale — during the first add, mapping each coordinate’s empirical 5/95% quantiles onto the canonical Beta marginal. The Lloyd-Max codebook then quantizes against the target distribution it was designed for. The calibration is frozen after the first add and reused by subsequent adds — no retraining, no rebuilds, no separate train phase. Recall gain: up to +1.4pp at @1 on the cells that drift most (e.g. GloVe at 2-bit).
4. Lloyd-Max scalar quantization. Since the distribution is known, we can precompute the optimal way to bucket each coordinate. For 2-bit, that’s 4 buckets; for 4-bit, 16 buckets. The Lloyd-Max algorithm finds bucket boundaries and centroids that minimize mean squared error. These are computed once from the math, not from the data.
5. Bit-pack. Each coordinate is now a small integer (0-3 for 2-bit, 0-15 for 4-bit). Pack these tightly into bytes. A 1536-dim vector goes from 6,144 bytes (FP32) to 384 bytes (2-bit). That’s 16x compression.
6. Length-renormalized scoring. Scalar quantization systematically underestimates inner products — the reconstructed unit direction is a little shorter than the original. We compute one scalar per vector at encode time — the inner product of the rotated unit vector with its own centroid reconstruction — and store ||v|| / ⟨u, x̂⟩ alongside each compressed vector. The search kernel multiplies the per-candidate score by this scalar before heap insertion, turning the inner-product estimator from downward-biased into unbiased at zero search-time cost and zero extra storage. The recall gain shows up most at low bit widths, where the quantization shrinkage is largest.
Encoding cost: one extra d-dimensional dot product per vector to compute ⟨u, x̂⟩. On 1M vectors at d=1536 this is sub-second of additional encode time — a one-shot price paid at ingest, not at query.
Search. Instead of decompressing every database vector, we rotate the query once into the same domain and score directly against the codebook values. The scoring kernel uses SIMD intrinsics (NEON on ARM, AVX-512BW on modern x86 with an AVX2 fallback) with nibble-split lookup tables for maximum throughput.
The Lloyd-Max codebook achieves distortion within a factor of 2.7x of the information-theoretic lower bound (Shannon’s distortion-rate limit); the length-renormalization step removes the residual bias the Lloyd-Max codebook introduces on the inner-product estimator itself.
Building
Python (via maturin)
pip install maturin
cd turbovec-python
maturin build --release
pip install target/wheels/*.whl
Rust
cargo build --release
All x86_64 builds target x86-64-v3 (AVX2 baseline, Haswell 2013+) via .cargo/config.toml. Any CPU that can run the AVX2 fallback kernel can run the whole crate — the AVX-512 kernel is gated at runtime via is_x86_feature_detected! and only kicks in on hardware that supports it.
Running benchmarks
Download datasets:
python3 benchmarks/download_data.py all # all datasets
python3 benchmarks/download_data.py glove # GloVe d=200
python3 benchmarks/download_data.py openai-1536 # OpenAI DBpedia d=1536
python3 benchmarks/download_data.py openai-3072 # OpenAI DBpedia d=3072
Each benchmark is a self-contained script in benchmarks/suite/. Run any one individually:
python3 benchmarks/suite/speed_d1536_2bit_arm_mt.py
python3 benchmarks/suite/recall_d1536_2bit.py
python3 benchmarks/suite/compression.py
Run all benchmarks for a category:
for f in benchmarks/suite/speed_*arm*.py; do python3 "$f"; done # all ARM speed
for f in benchmarks/suite/speed_*x86*.py; do python3 "$f"; done # all x86 speed
for f in benchmarks/suite/recall_*.py; do python3 "$f"; done # all recall
python3 benchmarks/suite/compression.py # compression
Results are saved as JSON to benchmarks/results/. Regenerate charts:
python3 benchmarks/create_diagrams.py
References
- TurboQuant: Online Vector Quantization with Near-optimal Distortion Rate (ICLR 2026) – the paper this implements
- RaBitQ: Quantizing High-Dimensional Vectors with a Theoretical Error Bound for Approximate Nearest Neighbor Search (SIGMOD 2024) – the source of the per-vector length-renormalization correction adapted in step 5
- FAISS Fast accumulation of PQ and AQ codes – turbovec’s x86 SIMD kernel adapts FastScan’s pack layout, nibble-LUT scoring, and u16 accumulator strategy
相似文章
@dr_cintas: 谷歌新算法将31GB内存压缩至4GB TurboVec是一款新的开源工具,用于存储数据……
谷歌的TurboVec是一款新的开源工具,能将AI搜索数据的内存占用从31GB降至4GB。它基于TurboQuant,实现比FAISS更快的搜索,可集成LangChain和LlamaIndex,并完全离线运行。
@techwith_ram:一个1000万文档的语料库以float32格式占用31GB内存。大多数团队遇到这一瓶颈后会转向托管向量数据库。每月400美元……
turbovec 是一个开源的 Rust 向量索引,使用 Google Research 的 TurboQuant 算法,实现了16倍压缩,搜索速度比 FAISS 更快,并且集成了 LangChain、LlamaIndex 和 Haystack 等 RAG 框架。
@hasantoxr:向量数据库不再是云产品。它们正在变成 pip install。一个名为 turbovec 的新开源项目……
一个名为 turbovec 的开源项目在 GitHub 上获得了 1 万星标。它是一个基于 Rust、带有 Python 绑定的向量索引,使用谷歌研究的 TurboQuant 算法将嵌入压缩到接近理论香农极限,使得完全本地的 RAG(检索增强生成)成为可能——1000 万文档仅需 4 GB RAM,且搜索速度快于 FAISS。
@thesupermanmx: SAM ALTMAN 疯了。Google 刚刚将 AI 内存从 31GB 压缩到 4GB。他们开源了一个向量索引,可容纳 10…
Google 开源了一个向量索引,将 31GB 的 AI 内存压缩到 4GB,可容纳 1000 万文档,搜索速度比 FAISS 更快,且无需训练或 GPU。
RyanCodrai/turbovec
turbovec 是一个基于 Rust 的向量索引,带有 Python 绑定,实现了谷歌的 TurboQuant 算法,提供高效的向量搜索,支持在线摄入,性能优于 FAISS,并具备过滤搜索能力。