Product Quantization: Vector Compression for ANN Search › PQ Accuracy Trade-offs in Depth
Language AI HandbookAll chapters Product Quantization: Vector Compression for ANN Search › PQ Accuracy Trade-offs in DepthOne section · Sections in this chapter8 / 12 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Understanding when PQ works well and when it struggles helps you configure it appropriately. The accuracy of PQ is not a fixed property of the algorithm but a function of how well the learned codebooks match your data distribution, how many subspaces you use, and whether the geometric structure of your embeddings aligns with the product decomposition that PQ assumes.
The fundamental source of error is the quantization step: by replacing each subvector with its nearest centroid, you introduce a residual error that corrupts the distance estimate. Whether this matters for recall depends on how large the residual errors are relative to the distances separating the true nearest neighbors from their non-neighbor competitors. If the true nearest neighbor is much closer to the query than the second-closest vector, PQ can afford substantial quantization error without disrupting the ranking. If many vectors are nearly equidistant from the query, even small quantization errors can flip the ranking and cause true neighbors to be missed.
The Quantization Error
When we compress a vector using PQ, the stored centroid indices only approximate the original subvectors. The quantization error measures how much information is lost: it is the total squared distance between each original subvector and the centroid used to represent it. Minimizing this error during codebook training (via k-means) directly improves the quality of approximate distance computations at search time. When quantization error is large, the centroids are poor representatives of the data points they are assigned to, and the approximate distances computed by ADC will deviate substantially from the true distances.
For a vector encoded as code , the quantization error is:
where:
- : the total quantization error for vector , measuring how far the compressed representation deviates from the original
- : the original (uncompressed) -th subvector of
- : the centroid assigned to represent , i.e., the nearest centroid found during encoding
- : the per-subspace reconstruction error for subspace
This reconstruction error is always non-negative. It does not, however, simply get added to every ADC distance. The difference between the approximate and true distances also contains a signed cross-term, derived below, so ADC can either overestimate or underestimate an individual distance. Smaller reconstruction error still tends to make the approximate distances more accurate and improve recall.
To understand how quantization error affects the approximate distance, consider that ADC computes the distance from the full-precision query to the centroid representing , rather than to itself. This means the result differs from the true distance by correction terms that depend on the quantization of . Specifically, the approximate distance can be written as:
where:
- : the approximate distance returned by ADC
- : the true squared Euclidean distance between and
- : a cross-term arising from the interaction between the true displacement and the quantization error of
- : the quantization error of database vector , i.e., the total squared distance between and its assigned centroids
The algebraic expansion above is more than a curiosity. It shows precisely which quantities control the quality of the approximation. The term is the true distance, which is what we want. The non-negative term depends only on how well is quantized, while the signed cross-term also depends on the query and can reinforce or offset it. ADC therefore has no universal overestimation guarantee for individual query-vector pairs. When the cross-term is small in expectation, lower reconstruction error makes the approximate distances more stable and reduces ranking mistakes among nearby candidates.

What Hurts Recall
Several factors degrade PQ recall. Understanding these failure modes helps you diagnose poor performance and choose the right remediation:
- Too few code bits: At fixed
nbits, a small gives each vector a short code. A 128-dimensional vector with andnbits=8, for example, receives only 16 total bits, so each 64-dimensional subvector must be represented by one of just 256 centroids. Increasing lowers this distortion by spending more bits per vector. - Insufficient training data: K-means needs at least a few hundred training points per subspace to converge well. With and , you need on the order of 200,000 training vectors minimum. With fewer, some centroids will be initialized in empty regions and never attract any training points, leaving voids in the codebook coverage.
- Non-uniform distributions: If your embeddings have strong correlations between dimensions that span subspace boundaries, independent per-subspace quantization misses that structure. Optimized PQ (OPQ) applies a rotation to the embedding space before quantization to reduce such correlations, at the cost of a rotation step at query time.
- Mismatched preprocessing or metric: Cosine search requires consistent normalization of training, database, and query vectors. For unit-normalized vectors, exact cosine and squared-Euclidean rankings agree; without that normalization, changing metrics changes the neighbor ordering that the index is trying to preserve.
Symmetric vs. Asymmetric Distance Computation
ADC keeps the query in full precision, which is why it outperforms Symmetric Distance Computation (SDC), where both the query and database vectors are quantized before comparison. With SDC, you accumulate quantization error from both sides: the query contributes its own per-subspace reconstruction errors on top of those from the database vector. Looking at the error expansion above, SDC adds an additional cross-term and an additional quantization error term for the query, making the approximation systematically worse.
In practice, ADC is almost always preferred. The only advantage of SDC is that you do not need to keep the codebooks in memory during search, which rarely matters compared to the recall cost. The memory overhead of the codebooks is negligible compared to the index itself: for , , , the codebooks occupy only bytes, less than 1 MB. There is virtually never a practical reason to accept the accuracy penalty of SDC when the codebooks are so cheap to store. ADC is always the right choice unless you are operating under severe memory constraints at truly extraordinary scale.