Scalar quantization

Also known as: int8 embedding quantization

On this page 7

Scalar quantization is a vector compression technique that maps each dimension of an embedding independently from a 32-bit floating-point value to a low-precision integer, most often an 8-bit integer. In Retrieval & knowledge systems, it is the standard way to shrink vector indexes by about four times while keeping search quality close to that of the original vectors, which is why it is also called int8 embedding quantization.

The technique trades a small, measurable loss of precision for lower memory use, cheaper storage and faster distance computation. It is supported by most vector databases and libraries and is usually the first compression step teams apply before considering more aggressive methods such as product quantization or binary embeddings.

How scalar quantization encodes each dimension

Scalar quantization treats every vector component as a single number and places it on a fixed grid of integer levels. For 8-bit quantization there are 256 levels. The encoder first determines a value range for each dimension or for the whole collection, then rescales each float into that range and rounds it to the nearest level.

A common formulation is q = round((x - min) / (max - min) * 255), optionally shifted by 128 to produce a signed int8. Decoding reverses the scale and offset, so each value is reconstructed with a rounding error of at most half a step. Because each dimension is handled separately, encoding is fast, needs no codebook training and works incrementally as new documents are added.

Distances between quantized vectors can be computed directly on integers. Modern CPUs process 8-bit values with SIMD instructions that pack many more operations per cycle than 32-bit floats, so similarity search often becomes faster as well as smaller.

Two distance modes are common. In symmetric distance computation, both the query and the stored vectors are quantized, which maximizes speed. In asymmetric distance computation, the query stays in full precision and only the stored vectors are compressed, which removes the query-side rounding error and usually improves recall at a modest cost. Dot product and cosine similarity also need a correction for the offset and scale terms, which libraries apply automatically so that ranking stays consistent with the float32 ordering.

Bit widths and their trade-offs

The number of bits per dimension determines the compression ratio and the precision loss. The table summarizes the variants seen in production vector search, for a typical 1,024-dimensional embedding.

FormatBytes per vectorCompression vs float32Typical recall impact
float32 (baseline)4,0961xNone
float16 or bfloat162,0482xNegligible
int8 scalar1,0244xSmall, often 1-3 points of recall
int4 scalar5128xModerate, needs rescoring
Binary (1 bit)12832xLarge, strongly model dependent
Common scalar quantization levels for a 1,024-dimensional vector

Recall figures vary with the embedding model, the dimension count and the dataset, so they should be measured on a representative query set rather than assumed. Models trained with quantization in mind usually lose less.

Calibration and handling of outliers

The quality of scalar quantization depends mostly on how the value range is chosen. If a few extreme values set the minimum and maximum, most real values crowd into a handful of levels and precision is wasted. Implementations therefore use a calibration sample of vectors to estimate ranges.

StrategyHow it worksWhen it fits
Global min-maxOne range for all dimensionsNormalized embeddings with even spread
Per-dimension min-maxSeparate range for each dimensionDimensions with very different scales
Quantile clippingRange set at, for example, the 0.99 quantileData with rare outliers
Learned or optimized rangesRanges tuned to minimize errorHigh-recall production indexes
Range estimation strategies

Quantile clipping saturates rare outliers at the edge of the range, accepting a large error on a few values to gain precision on all others. When the embedding distribution shifts, for example after a model upgrade, the ranges must be recalibrated and the index rebuilt.

Scalar quantization compared with other compression methods

Scalar quantization is one of several approaches to compressing a vector index. It differs from product quantization, which splits vectors into subvectors and replaces each with a codebook entry, and from binary embeddings, which keep only the sign of each value.

MethodUnit of compressionTraining neededTypical compression
Scalar quantizationEach single dimensionRange calibration only2x to 8x
Product quantizationGroups of dimensionsk-means codebooks16x to 64x or more
Binary embeddingsEach dimension to one bitNone32x
Matryoshka truncationWhole trailing dimensionsSpecial model training2x to 12x
Vector compression methods in retrieval

These methods combine well. A common design truncates a Matryoshka embedding, stores it as int8, searches with an HNSW or IVF index and then reranks the best candidates. Scalar quantization keeps simplicity and predictable accuracy, while product quantization wins when memory is the dominant constraint.

Using scalar quantization in a retrieval pipeline

In practice, scalar quantization is enabled as an index option rather than implemented by hand. FAISS offers scalar quantizer indexes, Lucene-based engines provide int8 and int4 HNSW variants, and several vector databases expose a quantile setting for scalar compression.

  • Keep the original float vectors on disk when possible, so the top candidates can be rescored at full precision.
  • Oversample before rescoring, for example retrieving 3 to 5 times the final k from the quantized index.
  • Evaluate recall@k and nDCG against an exact float32 baseline before switching production traffic.
  • Recalibrate after re-embedding, because ranges learned for one model do not fit another.
  • Avoid int4 without rescoring for high-stakes retrieval augmented generation, where a missed passage can cause a wrong answer.

A frequent mistake is to judge quantization only by memory savings while ignoring the downstream effect on generated answers. Small recall losses can matter when a RAG system depends on one critical passage.

Put simply

Search systems store each document as a long list of numbers. Each number normally uses plenty of space. Scalar quantization rounds every number to a shorter version. It works like measuring a room in whole centimeters instead of tiny fractions of a millimeter.

The rounded numbers take about a quarter of the space. The search still finds almost the same documents. The small loss of precision is usually worth the savings, and the system can double-check the best results with the full numbers.

In practice

A legal research company runs semantic search over 40 million passages, each embedded as a 1,024-dimensional float32 vector. The raw vectors need about 164 GB of memory, which forces the team to use several large servers just to hold the index in RAM.

The engineers enable int8 scalar quantization with quantile clipping at 0.99 in their vector database and keep the original vectors on disk. Each query retrieves 100 candidates from the quantized HNSW index and rescores them with full-precision vectors before returning the top 20. Vector memory falls to about 41 GB, query latency drops slightly thanks to integer arithmetic, and recall@20 on their test set stays within one point of the float32 baseline. The savings let the company consolidate onto fewer servers without changing the answers lawyers see.