VECTOR SEARCH & ANN
Section 26.3
03

RaBitQ and TurboQuant — rotation-based quantization

PQ requires training codebooks per subvector — that’s an infrastructure cost (you need to retrain whenever the embedding model changes). Binary quantization is fast but loses recall. RaBitQ (Gao 2024 “RaBitQ: Quantizing High-Dimensional Vectors with a Theoretical Error Bound for Approximate Nearest Neighbor Search”) — the headline 2024 breakthrough — showed that randomly ROTATING vectors before binary quantization gives provable recall guarantees: the rotated binary code preserves enough geometric structure to recover near-fp32 search quality. TurboQuant (post-RaBitQ work) extends with learned rotations. This is the active research seam in vector search — and, as the user noted at the start of this book, where the original conversation about “TurboQuant intuition” began. Closing this loop, with the math now grounded.

Why rotation matters (Ch.2 §3 revisited)

Recall from Ch.2 §3 that random orthogonal rotations preserve distances exactly:

If R is an orthogonal matrix (R^T · R = I), then for any two vectors x, y: ||R·x - R·y||² = (R·(x-y))^T · (R·(x-y)) = (x-y)^T · R^T · R · (x-y) = (x-y)^T · (x-y) = ||x - y||² Inner products too: <R·x, R·y> = <x, y>. So a random rotation R doesn't change ANY distance or angle. The search problem is INVARIANT under random rotation. Then why bother rotating? - Because after rotation, the COORDINATE-LEVEL statistics change. - The rotated vectors have UNIFORMLY distributed coordinates (no preferred direction). - This makes binary quantization (sign of each coordinate) capture MAXIMAL information — every bit is equally important.

The cleverness: rotation doesn’t change distances, but it makes binary quantization work better. Naive binary on the original vectors might lose more information from some dimensions than others (because the embedding model concentrated information in specific directions). After rotation, ALL dimensions carry equal information.

RaBitQ — the rotation insight

Gao 2024 “RaBitQ”: rotate vectors with a random orthogonal R; quantize each rotated coordinate to 1 bit (sign). The recovered binary distance ESTIMATES the true distance with provable error bound.

RaBitQ algorithm: Preprocessing (per database): 1. Generate random orthogonal R ∈ ℝ^{d × d} (e.g., via random Gaussian + QR). 2. For each database vector x: rotated = R · x. quantized[x] = sign(rotated) ∈ {-1, +1}^d (or {0, 1}^d as binary). Also store norm: ||x||. At query time: 1. Compute rotated query: q' = R · q. 2. For each database vector x: - Compute estimated similarity: sim_est(q, x) ≈ (1/d) · sum_i sign(q'_i) · sign(x'_i) · ||x|| · ||q|| (geometric structure preserved through rotation + binary quantization) The key theoretical result (Gao 2024): E[ sim_est ] = (2/π) · sim_exact (an unbiased estimator after scaling) Var[ sim_est ] = O(1/d) (variance decreases with d) For high-d (d ≥ 256): the variance is small enough that recall@10 reaches 90-95% with just 1 bit per dim.

RaBitQ is the most recent major advance in ANN. It achieves binary-level compression (32× vs fp32) with PQ-level recall — the two were previously thought to be a trade-off.

The connection to Ch.7 (Johnson-Lindenstrauss): random rotations are a special case of random projections. The JL lemma says random projections preserve distances with bounded error. RaBitQ shows that random rotations + binary quantization preserve enough structure for ANN.

Now make it concrete

RaBitQ vs other methods on a typical embedding benchmark (SIFT1M): Method Bytes/vector Recall@10 Search speedup vs exact fp32 exact 1024 100% 1× PQ16 16 95% 50× Binary (no rotation) 128 50% 100× RaBitQ 128 92% 100× RaBitQ + re-rank 128 + spill 97% 80× RaBitQ achieves binary's speed with PQ's recall. No codebooks to train (the random R works for ANY data distribution). Theoretical guarantees on error rate. In practice: deployed in Milvus, Vespa, some Cohere products.
— think, then check —

The mathematical core:

For two vectors x, y ∈ ℝ^d, the dot product (or cosine similarity, or L2 distance — all related) is invariant under orthogonal rotation:

⟨R·x, R·y⟩ = ⟨x, y⟩ for any orthogonal R.

So we can rotate any vectors without losing similarity information.

Why naive binary quantization loses recall:

For un-rotated vectors, the coordinate distribution is NOT uniform — embedding models concentrate information in specific subspaces. Some coordinates have high variance (rich information); others have near-zero variance (noisy).

Binary quantization (sign) treats every coordinate equally. For low-variance coordinates: the sign is essentially noise; the binary bit carries no info. For high-variance coordinates: the binary bit captures most of the info.

Net: ~30-50% of the bits in a binary code carry the signal; the rest are noise. Recall is hurt.

What rotation does:

A random rotation R MIXES all dimensions together. After rotation:

  • Every coordinate of R·x is a random linear combination of all original coordinates.
  • The variance per coordinate is now roughly UNIFORM across all d coordinates.
  • Each binary bit (sign of a rotated coordinate) carries roughly the same amount of information.

Net: ALL d bits contribute equally. Effective information is maximised.

The JL connection (Ch.7):

Johnson-Lindenstrauss: random projections from ℝ^d to ℝ^k (k > (log N)/ε²) preserve pairwise distances with error ε.

Special case: random ORTHOGONAL rotation in ℝ^d (k = d). Preserves distances EXACTLY.

Why the rotation helps: same argument as JL. A random rotation is uniformly distributed in the orthogonal group. With high probability, this rotation spreads any specific data distribution to be CONCENTRATED (most coordinates have similar magnitude). Binary quantization of concentrated distributions loses LESS information than binary quantization of skewed distributions.

The provable bound:

Gao 2024 shows that for random R and rotated vectors x’ = R·x, y’ = R·y:

E[ sign(x’_i) · sign(y’_i) ] = (2/π) · arcsin(⟨x, y⟩ / (||x|| ||y||))

This is the “Grothendieck inequality” / “sign-product expectation.” For high cosines (closer vectors), the binary sign agreement is high (linear in cosine); for low cosines, it’s low.

Estimator: sum the agreements across d bits; divide by d. With d ≥ 256, this estimator converges to the true similarity within ~1-2% standard error.

For ANN: a 1-2% error in similarity estimate is sufficient to rank candidates correctly — recall@10 stays at 90%+.

Why this couldn’t have been seen earlier:

The mathematics has been around for decades (Grothendieck’s inequality, JL). What’s recent is the empirical demonstration that random rotation + 1-bit quantization is COMPETITIVE WITH PQ at billion-scale. Previously, researchers assumed you needed more bits per dim or learned codebooks. RaBitQ showed that random rotation alone unlocks binary-level efficiency at PQ-level quality. The simplicity is what makes it impactful.

TurboQuant — learned rotations

Liu 2024 “TurboQuant: Optimal Linear Quantization for Vector Search” took the rotation idea further: rather than RANDOM rotation, LEARN the rotation to minimise quantization error for a specific data distribution.

TurboQuant setup: Learn an orthogonal matrix R that: - Preserves the orthogonality constraint (R^T · R = I). - Minimises the loss: ||x - decode(quantize(R · x))||² over the training data. Solve via constrained optimisation: - Project R onto the orthogonal manifold after each gradient step. - Or parameterise R via Householder reflections / Cayley transform / etc. After training: R is FIXED. Same one R for all database vectors and queries. Benefit over random R: - Lower variance of distance estimates. - Higher recall at the same bit budget. - Particularly helpful when the data has STRONG anisotropy (e.g., text embeddings often have a few dominant directions). Tradeoff: - Training time: 10-60 minutes on a single GPU for typical datasets. - Distribution sensitivity: R is tuned to a specific data distribution. New data outside that distribution loses some quality. - Compared to random R: a few percentage points better recall (~93→96%).

TurboQuant is the natural evolution of RaBitQ. The trade-off: learning is data-specific (works less well on out-of-distribution data) but achieves higher recall on the trained distribution.

The frontier — where the book began

This brings us full-circle to the conversation that started this book. The user’s original interest was:

The math has now been built up: Ch.2 §3 (orthogonal invariance), Ch.7 (Johnson-Lindenstrauss random projections), Ch.21 §1 (memory hierarchy and bandwidth), Ch.24 (quantization formats), Ch.26 (vector search itself). Each piece is a foundation for understanding the larger picture.

The TurboQuant intuition: rotation preserves distances; binary quantization of rotated vectors loses less information than binary quantization of the original; and ANN search on the binary codes achieves PQ-level recall at binary-level efficiency. This is the synthesis.

— think, then check —

The unifying principle:

Orthogonal rotations preserve all distances and angles between vectors. So they don’t change anything geometrically — only the coordinate representation.

But the COORDINATE representation matters for many practical operations: SIMD efficiency, quantization quality, projection compression. A “good” coordinate system makes these operations work well; a “bad” one doesn’t.

Three uses in this book:

1. Ch.2 §3 (geometric invariance): rotated vectors have the same inner products. So orientation-invariant tasks (classification, similarity) work the same in any frame. Useful for INTERPRETATION: rotated weights and activations have the same effect.

2. Ch.7 (Johnson-Lindenstrauss): random projections from ℝ^d to ℝ^k (k = O(log N / ε²)) preserve pairwise distances with error ε. Orthogonal rotations are a special case (k = d). Useful for COMPRESSION: dimensionality reduction without sacrificing geometric structure.

3. Ch.26 §3 (RaBitQ): random orthogonal rotation followed by 1-bit quantization preserves enough structure for nearest-neighbor search. The rotation MIXES dimensions so each bit carries equal information. Useful for QUANTIZATION: lossy compression with controlled quality loss.

The deeper insight:

Many ML operations are “geometry-invariant” in some sense. Classification depends on the angle to a hyperplane; clustering depends on pairwise distances; nearest-neighbor depends on rank ordering by distance. All these are preserved by rotations.

So if you’re operating on coordinates that are “geometrically irrelevant” (e.g., dimensions with low variance), they’re CONSUMING storage and compute without contributing. Rotating to a more uniform coordinate system maximises the use of every bit.

This is also why “learnable” rotations (like TurboQuant’s) can be even better than random — they specifically optimise the coordinate system to be uniform for YOUR data.

The trajectory:

  • 1980s-2000s: random projections (JL) for theoretical work, occasionally for practical compression.
  • 2010s: PQ and related methods that train codebooks (effectively a kind of structured “rotation”).
  • 2020s: graph methods (HNSW, NSG) dominate ANN.
  • 2024+: rotation-based binary quantization (RaBitQ, TurboQuant) returns as a major direction, leveraging modern hardware (popcount, SIMD).

The cycle: each generation rediscovers and refines the rotation insight for the current hardware and data scale. RaBitQ is the most recent iteration; the principle stays the same.

— think, then check —

Open seams (2025-2026):

1. Quantization-aware training. Train embedding models with awareness of the quantization scheme they’ll be used with. Cohere’s work on binary-friendly embeddings, plus academic work on QAT for retrieval, suggests this is a 5-10% recall improvement per technique cycle.

2. Learned rotations on TurboQuant’s path. What’s the optimal rotation for a given embedding distribution? Can it generalise across distributions? Some papers in 2025 propose “universal rotations” that work across many data types.

3. Streaming and incremental updates. Most ANN libraries assume static databases. Real systems have continuous insertion / update / delete. How to maintain HNSW + PQ under streaming? Active research area.

4. Multi-vector retrieval. ColBERT-style late-interaction (multiple vectors per document, max-sim across) gives substantially better retrieval quality but is much more expensive. New compression schemes for multi-vector storage and search.

5. Specialised hardware. SambaNova, Cerebras, and various startups build accelerators tuned for ANN-like workloads. Open question: can a “ANN ASIC” be 100× faster than CPU at the cost of flexibility?

6. Approximate matrix multiplication. For embedding tables that are too large to fit in HBM, can you do “fuzzy matmul” via sketches? Tied to the broader question of sub-quadratic attention and LLM efficiency.

7. Hybrid retrieval-and-generation. RAG systems are a hybrid of vector search and LLM. Joint optimisation (retrieve a draft, refine via LLM) could shift the work split. Active research direction.

8. Disk-based ANN at scale. When the database doesn’t fit in RAM, how to search efficiently? DiskANN (Microsoft) provides one answer; others are exploring asymmetric memory hierarchies.

What’s worth working on:

If you have systems/ML engineering background:

  • Quantization-aware embedding training — high impact, accessible if you can train an embedding model.
  • Streaming ANN updates — practical engineering problem with broad applicability.
  • Specialised hardware kernels for RaBitQ-style binary search — combines low-level engineering with new algorithms.

If you have pure ML / theory background:

  • Theory of rotation-based quantization — understanding optimal rotations, distribution sensitivity.
  • Multi-vector retrieval — generalisations beyond ColBERT.
  • Joint RAG optimisation — making retrieval and generation co-optimised.

If you’re building a startup / product:

  • Vector search infrastructure for emerging modalities (audio, video, multimodal embeddings) — open market.
  • Domain-specific ANN (legal, medical, code) — where quality requirements are stricter than generic.

The vector search field is mature in its core (HNSW + PQ are the workhorses) but actively evolving at the margins (learned rotations, multi-vector, hardware). It’s been a productive area for 15+ years and shows no signs of slowing.

END OF CH.26 — Vector search and ANN.
§1 (exact kNN → HNSW: graph-based small-world navigation, sub-linear search) · §2 (PQ and binary codes: compression for billion-scale, FAISS IVF+PQ recipe) · §3 (RaBitQ and TurboQuant: rotation-based quantization, the closing of the loop to the book’s opening conversation).

Next: Ch.27 — Reading research like a researcher. The close of the book.