Smaller vectors for a large index
An index stores one vector per paragraph, so its memory and the cost of comparing grow with the vector's size. A 1,024-number float32 vector takes 4 KiB; a billion of them take about 4 TB. There are two ways to shrink it: keep fewer numbers, or store each number in fewer bits. This tab does both with one model, mxbai-embed-large-v1 (24 BERT blocks, 1,024 dimensions, 334 M parameters, [CLS] pooling), on the Embeddings tab's 2,067 SQuAD paragraphs and 300 questions, and measures what each setting keeps.
Nested vectors
Cutting an ordinary embedding to its first numbers loses a lot, because training spread the information over all of them. Matryoshka representation learning (Kusupati et al.) trains the prefixes to be embeddings in their own right: the loss is summed over a set of prefix lengths ,
where is the first numbers of the vector and the usual contrastive loss. The first numbers end up carrying the most. To use a prefix, cut the vector and renormalise it to length 1, as the One vector, nested panel does at 512, 256, 128 and 64 dimensions; each row is drawn at its true share of the 1,024.
In float32, nDCG@10 over the 300 questions is 0.830 with all 1,024 numbers, 0.818 with 512, 0.781 with 256, 0.742 with 128 and 0.649 with 64. Each halving loses more than the one before, yet an eighth of the vector still keeps 89 % of the full vector's nDCG@10.
int8: a byte per number
Scalar quantisation stores each number as one of 256 levels. For each dimension the corpus gives a range , its minimum and maximum, cut into 256 equal buckets of width ; a paragraph's number is stored as its bucket, and the search compares the full-precision question with the buckets' middles. Only the paragraphs are quantised, so the search is asymmetric.
The int8: a byte per number panel shows a vector's buckets and the cosine they give against the exact one. On this corpus int8 costs nothing measurable: nDCG@10 is 0.831 at 1,024 dimensions, against 0.830 in float32, in a quarter of the bytes.
Binary: a bit per number
Binary quantisation keeps only each number's sign, , so 1,024 numbers become 128 bytes. Two bit vectors are compared by their Hamming distance, the number of places where they differ, computed with an exclusive or and a bit count:
For random hyperplanes Charikar showed that two vectors at angle get different sign bits with probability , so the share of differing bits estimates the angle. An embedding's own coordinates are not random hyperplanes, but the same relation is why Hamming distance tracks cosine at all. The binary: a bit per number panel shows the question's and a paragraph's bits and their Hamming distance. Distances are whole numbers, so many paragraphs tie.
At 1,024 bits nDCG@10 is 0.801, 96.5 % of float32's in a 32nd of the bytes. Fewer dimensions hurt binary much more than float32: 0.500 at 128 bits and 0.294 at 64.
Rescoring and the trade-off
Binary search can be made more accurate without storing more: take its first 40 paragraphs and rescore them with the full-precision question against their bits, , as sentence-transformers' binary search does and as the Binary Passage Retriever of Yamada et al. trained for. Rescoring only reorders those 40, so Recall@100 does not change; nDCG@10 rises from 0.801 to 0.812 at 1,024 bits and from 0.500 to 0.591 at 128.
The Quality against bytes chart puts all 20 settings on one axis of bytes per vector. At equal bytes, fewer bits per number beat fewer numbers here: 1 KiB holds either 256 float32 numbers, nDCG@10 0.781, or 1,024 int8 numbers, 0.831. And the 128 bytes of 1,024 binary bits, 0.801, come close to the Embeddings tab's bge-small at 1,536 bytes, 0.810. The two methods combine: a Matryoshka prefix can itself be quantised, which mxbai-embed-large-v1's model card advertises.
Where it came from
Matryoshka representation learning was introduced in 2022 and taken up by text embedding models soon after. Binary codes for search are older: learning to hash and Charikar's random-hyperplane sketch, and in neural passage retrieval the Binary Passage Retriever (2021), which generates candidates with binary codes and reranks them with continuous vectors. The same trade of accuracy for memory and speed returns in the IVF-PQ tab, which quantises whole groups of numbers at once.
Papers
- Matryoshka Representation Learning Trains every prefix of an embedding as an embedding of its own, so vectors can be cut to fit a budget.
- Efficient Passage Retrieval with Hashing for Open-domain Question Answering Binary passage codes for candidate generation, reranked with the continuous question vector, the binary-plus-rescore setting here.
- Similarity estimation techniques from rounding algorithms Sign bits of random projections, whose Hamming distance estimates the angle between vectors.
- Binary and Scalar Embedding Quantization for Significantly Faster & Cheaper Retrieval The int8 and binary quantisation and rescoring in sentence-transformers that this tab reproduces and checks against.
- AnglE-optimized Text Embeddings The training objective mxbai-embed-large-v1's model card cites.