Chapter 27Down the Rabbit Hole: One Bit per Dimension, With an Error Bar
A million 960-d float32 embeddings is 3.84 GB. A billion 1,024-d vectors is 4 TB. Keeping only the sign of each coordinate is a 32x shrink, and everyone knows it's crude. What pulled me in was a 2024 SIGMOD paper by Gao and Long, RaBitQ, which does exactly that and then claims the distance estimate is unbiased, with a provable error bound.
It's in production: Milvus IVF_RABITQ, Faiss IndexIVFRaBitQ, LanceDB IVF_RQ, NVIDIA cuVS, and Elasticsearch's "Better Binary Quantization" grew from it. So where does the guarantee come from?
Why product quantization has no guarantee#
PQ (Jégou et al., 2011) splits a vector into M chunks, runs k-means per chunk, and stores one centroid id each. Fast-scan variants use 4-bit ids so a 16-entry table fits in a SIMD register and scores 32 codes at once. Fast, but k-means is a heuristic, so error depends on how your data clusters.
- On most of the paper's six datasets, 4-bit fast-scan PQ and OPQ hit max relative distance error around 100%; on MSong, past 200%.
- On GIST, OPQ's estimated squared distances fit a line of slope 0.72 against the truth. That's systematic shrinkage, not noise.
- With no error bar, systems rerank a fixed count and hope. On MSong, IVF-PQ reranking even 2,500 candidates topped out near 60% recall.
Snapping to a corner#
Normalize a vector to an arrow from the centre of a sphere. The 2^D corners of a hypercube on that sphere are the possible 1-bit codes, and taking signs snaps the arrow to its nearest corner.
In high dimension that corner is always about 37 degrees away, cosine roughly 0.80. The inner product with the snapped corner is the sum of absolute coordinates over √D. Coordinates are roughly Gaussian with variance 1/D, each averaging √(2/(πD)) in absolute value, so:
E[ <o_bar, o> ] ≈ sqrt(2/pi) ≈ 0.798It doesn't depend on D; the exact form stays within 0.798 to 0.800 from 100 dimensions to a million.
corner o_bar
●
╱│
╱ │ perpendicular part:
╱ │ length ~0.60, random direction
╱ 37°
centre ●─────────▶ o (your vector)
└── <o_bar, o> ≈ 0.80 ──┘Score a query q against the corner instead of o. The paper's Lemma 3.1:
<o_bar, q> = <o_bar, o> * <o, q> + <o_bar, e1> * sqrt(1 - <o, q>^2)Read it as: a known shrink factor times the truth, plus a wobble.
Why the rotation is the point#
RaBitQ applies one uniformly random orthogonal rotation to everything, once, at index time. Then the part of o_bar perpendicular to o points in a uniformly random direction, so its projection onto the fixed direction e1 is equally likely positive or negative. The wobble has mean zero.
So divide by the shrink factor, computed at index time and stored per vector, and the estimate is right on average:
<o, q> ≈ <o_bar, q> / <o_bar, o> and E[ <o_bar, q> / <o_bar, o> ] = <o, q>Skip the division and scores come out about 20% too small. The paper's ablation: slope 0.80 without it, 1.00 with it.
Without the rotation you're back to plain sign binarization, and the wobble isn't zero-mean for a fixed pair. The older lineage (ITQ, OPQ) learns a rotation to fit the data. RaBitQ picks a random one and trades a little average accuracy for an error distribution that doesn't depend on the data.
How wrong can it be?#
The perpendicular part has length √(1 - 0.8²) ≈ 0.60, spread over D-1 directions, so its projection onto any fixed direction has deviation shrinking like 1/√D. After the division:
sigma ≈ 0.75 * sqrt(1 - <o, q>^2) / sqrt(D - 1)Quadruple the dimension, halve the error. Concentration of measure gives a sub-Gaussian tail: half-width grows linearly in ε₀ while the miss probability drops like exp(-ε₀²). The paper uses ε₀ = 1.9, where recall saturates. Citing Alon and Klartag, it also argues no D-bit code beats O(1/√D) error at constant failure probability, so RaBitQ is optimal in order.
The dive's 40-line numpy check at ⟨o,q⟩ ≈ 0.83:
| D | ⟨o_bar,o⟩ mean | RaBitQ bias | std | naive bias | std·√D |
|---|---|---|---|---|---|
| 128 | 0.799 | -0.0005 | 0.0364 | -0.1672 | 0.41 |
| 256 | 0.798 | +0.0008 | 0.0258 | -0.1671 | 0.41 |
| 960 | 0.798 | +0.0002 | 0.0133 | -0.1680 | 0.41 |
| 1536 | 0.798 | +0.0003 | 0.0107 | -0.1678 | 0.42 |
The shrink factor sits at √(2/π) for every D, and the undivided estimator is off by 0.83 × (0.8 - 1) ≈ -0.17, as predicted. σ·√D is flat at 0.41, against 0.42 from the formula.
What the error bar is for#
I'd misunderstood this. The bound isn't a number for a paper; it's a pruning rule. The rerank set comes from math, not a magic count tuned per dataset.
The hot loop: a 4-bit query against 1-bit codes
The query is not binarized. It's rounded to 4 bits per dimension, free in memory since there's only one query, and split into four bit-planes:
sum(bits * q_bar) = sum over j of 2^j * popcount(bits AND q_bar_plane_j)Four AND-plus-popcount passes over D bits, at D = 960 that's 4 × 15 64-bit words. Batched scans reuse PQ's fast-scan machinery: 16-entry tables in a SIMD register, 32 codes at a time. Same hardware trick, different numbers in the tables.
Where it breaks#
Five caveats, and why they matter
- Small D. Half-width on the inner product is about 1.425/√(D-1): ±0.18 at D = 64, too wide to prune much. Elastic requires D greater than 64 for BBQ. In the dive's toy trace at D = 8 the interval was ±0.5, so nothing could be pruned. The bound is honest about tiny dimensions.
- Honest isn't small. Elastic reports recall@10 about 0.83 for 1-bit codes on one dataset, and about 0.999 only after reranking. The guarantee is that the bars are correct, not narrow. "32x compression, so 32x faster" falls apart if candidates need reranks from slower storage.
- Norms amplify everything. Distance error is the inner-product error times 2 × (vector-to-centroid distance) × (query-to-centroid distance). In the toy trace the inner product was off by 0.04 but the squared distance by 0.5.
- "Unbiased" is over the rotation. One index uses one rotation, so some specific pairs are consistently off by more than average. The bound is per estimate, not uniform over a billion candidates.
- Rotation cost. A dense rotation is D² multiply-adds per query, 921,600 at D = 960. Everyone ships fast Hadamard-style rotations at O(D log D), but the original proof assumes a truly uniform rotation.
The question I'm left with#
Can a per-distance guarantee become a recall guarantee? The bound only covers scanned candidates. IVF still misses neighbours in clusters you didn't probe, and graph indexes miss nodes they never visit. Those misses depend on the data's geometry, not the quantizer, and as far as I can tell this is still open.
Close behind: a 2026 paper studies provable bounds under randomized Hadamard transforms, what production actually uses. I haven't checked its results.
And the competition has moved to 3 to 5 bit codes. Extended RaBitQ claims asymptotic optimality in error per bit; SAQ reports up to 80% lower error and 80x faster encoding. Both are self-reported, and I found no independent benchmark. Many headline figures here, including the RaBitQ group's re-run against TurboQuant, come from interested parties. I'd love a neutral one.
Sources#
- Gao and Long, RaBitQ: Quantizing High-Dimensional Vectors with a Theoretical Error Bound for Approximate Nearest Neighbor Search (SIGMOD 2024)
- Extended RaBitQ and SAQ
- IVF-RaBitQ on GPU and RaBitQ vs TurboQuant
- Randomized Hadamard provable quantization
- Jégou, Douze, Schmid, Product Quantization for Nearest Neighbor Search (TPAMI 2011)
- RaBitQ-Library
- Milvus IVF_RABITQ docs and LanceDB quantization docs
- Faiss and its FastScan wiki
- Elastic, Better Binary Quantization in Lucene and Elasticsearch and RaBitQ explainer