Embeddings & Representations intermediate 7 min read 12 flashcards

Binary and Int8 Embedding Quantisation

Storing each embedding dimension as one bit instead of thirty-two cuts index memory by 32x and, with a float rescoring pass over the shortlist, gives most of the retrieval quality back.

Forty-one million Wikipedia passages embedded at 1024 float32 dimensions is about 200GB of vectors. That does not fit in RAM on anything you want to pay for, and once the index spills to disk, query latency is dominated by I/O rather than by similarity computation. Embedding quantisation attacks this directly, and the compression ratios available are larger than most people expect.

Two schemes

Scalar (int8) quantisation keeps the dimensionality and shrinks each component from 32 bits to 8 by mapping a calibrated value range onto 256 buckets. A 1024-dimensional vector goes from 8,192 bytes to 2,048 bytes, a 4x reduction. Similarity is still a dot product, computed in int8 with an int32 accumulator.

Binary quantisation keeps only the sign. For L2-normalised embeddings, each component becomes 1 if positive and 0 otherwise, and a 1024-dimensional vector becomes 1024 bits, or 128 bytes: 32x smaller. Similarity is Hamming distance, which is an XOR and a popcount, so retrieval speed improves by a comparable factor (Sentence Transformers, Embedding Quantization).

Binarising a normalised vector is a projection onto the corners of a hypercube. It discards magnitude within each dimension and keeps only which orthant the vector occupies. That works because high-dimensional embedding geometry carries much of its discriminative signal in the sign pattern, and it fails when two documents share an orthant but differ in how strongly.

Rescoring is what makes it usable

Binary search alone loses real accuracy. The fix is a two-stage retrieval that mirrors the reranking pattern one level lower in the stack:

  1. Search the binary index for a shortlist, typically the top 100 to 1000.
  2. Rescore those candidates with the original float32 (or int8) vectors and re-order.
  3. Return the top k from the rescored list.

The binary index lives in memory; the float vectors can live on disk, because you only fetch a few hundred of them per query. With this step, binary quantisation preserves up to roughly 96% of total retrieval performance. The reference pipeline compresses 200GB of Wikipedia embeddings to about 5.2GB in memory plus 47.5GB on disk.

Rescoring turns quantisation from a lossy shortcut into a memory hierarchy: cheap, approximate, in-RAM for the first pass; exact, expensive, on-disk for the shortlist.

Composing with other reductions

Quantisation reduces bits per dimension. Matryoshka representation learning reduces the number of dimensions, and the two multiply: 1024 float32 dimensions truncated to 256 and then binarised is a 128x reduction before rescoring.

They also fail differently. Matryoshka truncation degrades gracefully because the model was trained so that prefixes are usable. Binarisation degrades abruptly once the sign pattern stops separating your corpus, which depends on the corpus, not the model.

Note the relationship with ANN index quantisation: product quantisation compresses vectors by learning a codebook from the data, which usually beats scalar quantisation at equal size but requires training and re-training as the corpus drifts. Binary quantisation is codebook-free and stateless, which is why it composes cleanly with HNSW.

When it breaks

Calibration is corpus-dependent for int8. The value range that defines the 256 buckets comes from a sample of your embeddings. If the corpus shifts, the calibration is wrong and quality drops silently. Binary quantisation has no such parameter, one of its underrated advantages.

Not every model binarises equally well. Models trained with a large temperature or without normalisation produce embeddings whose information is not concentrated in the signs. Measure the retention on your own data; the 96% figure is a benchmark result, not a guarantee.

Rescoring changes the failure mode, not the recall ceiling. If the true answer is not in the binary shortlist, no amount of rescoring recovers it. Shortlist depth is the knob that matters, and it trades directly against the disk reads you were trying to avoid.

Small corpora do not need this. Under a few million vectors, float32 fits comfortably and quantisation buys complexity you will pay for at debugging time.

Check yourself

12 flashcards for this concept

Click a card to reveal the answer.

Drill the whole track