Subspace codebooks replace floating-point coordinates

Product quantization divides each vector into equal subspaces. A clustering step learns a codebook for each subspace, and an indexed vector stores the nearest centroid identifier from every codebook instead of all original coordinates.

At search time, the system estimates distances through lookup tables built from the query and those centroids. Compression saves memory and bandwidth at the cost of quantization error.

A toy code shows the storage shape

If a vector is divided into four sub-vectors and each codebook has entries addressed by one byte, the compressed representation contains four centroid identifiers plus any index overhead. The example explains the shape, not a universal compression ratio, because production choices depend on dimension, codebook size, and metadata.

PQ compresses vectors; HNSW navigates neighbors

HNSW is a graph index, while PQ is an encoding. Matryoshka representation learning trains useful vector prefixes, and scalar quantization reduces the precision of individual values.

The embedding model guide explains why dimension and model behavior must be evaluated together. Product quantization is unnecessary when full vectors fit comfortably in memory, and the common misuse is reporting space savings without measuring recall on the compressed index.

Codebooks inherit the distribution they learned

A codebook trained on one embedding model or domain may represent a changed distribution poorly. Replacing the embedding model, normalizing vectors differently, or adding a distinct document population can make the old centroids a worse approximation.

Migration planning should therefore include codebook retraining and side-by-side recall checks. Keeping original vectors elsewhere may also be necessary when the system needs exact reranking or future re-encoding.

Continue with these glossary entries: