Glossary
Product quantisation
A vector compression method that splits each embedding into sub-vectors and replaces each one with the ID of its nearest learned centroid, cutting memory by 16 to 64 times.
Product quantisation (PQ) is a way of compressing embeddings so that very large collections fit in memory and can still be searched quickly. It cuts each vector into a fixed number of sub-vectors, learns a small codebook of representative points for each sub-vector position, and stores every sub-vector as the one-byte ID of its closest codebook entry. A 768-dimensional float32 vector of 3,072 bytes can become a 48-byte code. Distances between a query and millions of codes are then estimated with precomputed lookup tables instead of floating-point maths. PQ is the method that made billion-scale vector search practical on ordinary hardware, and it remains a standard part of large indexes.
The idea behind it
Plain vector quantisation with a single codebook would map each whole vector to its nearest centroid. To represent embeddings precisely that way you would need an enormous number of centroids, far too many to train or store. Product quantisation avoids that by treating the vector as several smaller vectors and quantising each one separately. If each of 48 sub-vectors has 256 possible codes, the number of distinct combinations is 256 to the power of 48, a codebook far larger than any single one you could build, yet the stored codebooks hold only 48 times 256 small centroids.
The name comes from that structure. The full codebook is the Cartesian product of the small per-segment codebooks, so the method can express a huge number of reconstruction points while keeping training and storage cheap.
How product quantisation works, step by step
Splitting. Choose a number of segments, usually written m, that divides the dimension count evenly. A 768-dimensional embedding with m = 48 becomes 48 sub-vectors of 16 dimensions each.
Training. Take a sample of the corpus, often a few hundred thousand vectors, and run k-means clustering separately on each segment. With 8 bits per code, each segment gets 256 centroids. The result is 48 small codebooks. Training needs to see data that resembles what will be indexed, which is why PQ indexes have a training step that flat or graph indexes do not.
Encoding. For every vector in the collection, find the nearest centroid in each segment’s codebook and record its index. The vector is now 48 bytes. The original floats can be discarded or moved to cheaper storage.
Searching. When a query arrives, split it the same way. For each segment, compute the distance from the query’s sub-vector to all 256 centroids in that segment, which produces a lookup table of 48 rows by 256 columns. The estimated distance between the query and any stored code is the sum of 48 table entries, one per segment, chosen by the code’s bytes. That is called asymmetric distance computation, because the query stays exact while the documents are compressed. It is both faster and more accurate than compressing the query as well.
Choosing the parameters
Two numbers control almost everything: the number of segments and the bits per code.
Setting (768-dim vectors) | Code size | Compression vs float32 | Typical effect |
|---|---|---|---|
m = 96, 8 bits | 96 bytes | 32x | Higher accuracy, larger index |
m = 48, 8 bits | 48 bytes | 64x | Common balance |
m = 24, 8 bits | 24 bytes | 128x | Strong compression, lower recall |
m = 48, 4 bits | 24 bytes | 128x | Faster tables, coarser codes |
More segments preserve more detail but make codes bigger and lookups slower. Fewer bits per code make tables smaller and faster to scan, especially with SIMD-friendly 4-bit layouts, at a cost in precision. The right point depends on the embedding model, the corpus and how much accuracy the application can give up, so teams benchmark recall at k for several settings before committing.
Combining PQ with an index
Scanning every compressed code is fast, but at hundreds of millions of vectors it is still too slow for interactive search. PQ is therefore almost always paired with a structure that narrows the search first.
The classic pairing is IVF-PQ. An IVF index clusters the collection into a few thousand coarse partitions; at query time only the closest partitions are scanned, and the vectors inside them are stored as PQ codes. Many implementations encode the residual, the difference between each vector and its partition centroid, rather than the vector itself, because residuals are smaller and quantise more accurately. FAISS popularised this design and provides it as a standard index type.
PQ also combines with graph indexes such as HNSW, where the graph is navigated using compressed distances and the final candidates are checked against fuller vectors. Disk-based indexes use a similar trick: PQ codes in memory guide the search, and full vectors on SSD are read only for the last few candidates. All of these are forms of approximate nearest neighbour search, trading some exactness for speed and memory.
Improving accuracy: rotations and refinement
Product quantisation works best when the information in a vector is spread evenly across segments. Real embeddings often concentrate variance in some dimensions, so a few segments carry most of the signal and the rest waste their codes. Optimised product quantisation (OPQ) learns a rotation of the vector space before splitting, so that variance is balanced across segments. It adds a matrix multiplication per vector and usually improves recall noticeably at the same code size. Applying dimensionality reduction such as PCA before PQ has a related effect.
The other standard fix is refinement. The PQ stage returns a few hundred candidates by approximate distance, and the system recomputes exact distances for those candidates from stored full-precision or int8 vectors. As with binary quantisation, this recovers most of the lost ranking accuracy at the cost of reading a small number of larger vectors per query. A reranking model can follow for the final order.
Strengths and limits
PQ offers more compression per unit of accuracy than most alternatives. At the same memory budget, it generally beats binary codes on recall, because its codebooks are fitted to the data rather than fixed. It handles any distance that decomposes across segments, which includes squared Euclidean distance and inner product, and so it supports dot product similarity and, with normalised vectors, cosine similarity.
Its limits come from the training step. Codebooks reflect the data they were trained on. If the corpus changes character, for example after a switch of embedding model or a large ingest from a new domain, distortion rises quietly and recall drops until the codebooks are retrained and the collection re-encoded. That ties PQ to the operational work described under re-indexing and embedding drift. Training also needs a representative sample, which is awkward for a brand-new collection or for many small tenants with little data each.
PQ also amplifies the near-tie problem found in large corpora. When many documents sit at almost the same distance from a query, as in semantic collapse, compression errors are large enough to reorder them. Refinement helps, but only for candidates the compressed stage found.
When product quantisation is the right choice
PQ earns its complexity when a collection is too large for full-precision vectors in memory and too accuracy-sensitive for binary codes. That usually means tens of millions of vectors or more, a fixed or slowly changing corpus, and a team that can own the training and rebuild cycle. Search over a static archive, a large product catalogue or a web-scale document set fits that description well.
It is a poor fit for small or fast-changing collections. Below a few million vectors, int8 scalar quantisation or no compression at all is simpler, and the accuracy is higher. Where each tenant has its own small index, there may not be enough data per tenant to train useful codebooks. And where the size of each vector is the real cost driver, cutting embedding dimensions first is often the cheaper fix. In every case, the deciding measure is precision and recall on real queries, since vector search that returns the wrong top-k candidates cannot be rescued by later stages.
A worked example
A research platform indexes 300 million paragraph embeddings at 768 dimensions. At float32 that is about 920 GB of raw vectors. The team builds an IVF index with 65,536 partitions and PQ with m = 48 and 8-bit codes, encoding residuals after an OPQ rotation. The codes take about 14 GB, plus partition lists and IDs, and the index fits in memory on one large node. Full vectors stay in object storage.
Each query probes 64 partitions, ranks around 20,000 compressed codes with lookup tables and refines the top 500 using int8 copies kept on local SSD. Recall at 10 lands at 0.92 against an exact baseline, with latency in the tens of milliseconds. When the team later moves to a new embedding model, they retrain codebooks on a fresh sample and rebuild the index over a weekend, which is the recurring cost of the approach.
Where Exabase fits
Exabase does not ask developers to train codebooks, size segments or plan re-encoding. Content stored as Resources in a Base is extracted and indexed automatically when it is written, and Deep Search returns the matching paragraph, page, timestamp or video scene with a relevance score. Retrieval is hybrid, combining semantic search with typo-tolerant keyword matching, and a precision parameter between 0 and 1 controls how wide or narrow the results are. Each Base has its own index, so a new tenant needs no training data before its content is searchable.
That makes Exabase the retrieval substrate, not a tunable vector engine. Teams that need direct control over PQ parameters, memory layout and refinement will run a dedicated engine, and the best vector databases roundup and Exabase vs Milvus compare that route. Teams that want sub-document retrieval over documents and media without maintaining an index can follow the searching resources guide, and the RAG accuracy page explains why finding the right passage matters more than shaving bytes per vector. For the broader argument, how we index millions of files without an embedding pipeline covers the approach.
Frequently asked questions
What is product quantization in simple terms?
Product quantisation compresses each embedding by cutting it into pieces and replacing each piece with the ID of its closest representative point from a learned list. A vector of thousands of bytes becomes a few dozen bytes that can still be compared quickly.
Why is it called product quantization?
The full set of possible reconstructions is the Cartesian product of the small per-segment codebooks. That lets the method express a very large codebook while only storing and training small ones.
How much memory does product quantization save?
Typically 16 to 64 times compared with float32, and more with aggressive settings. A 768-dimensional vector stored as 48 one-byte codes is 64 times smaller.
What is the difference between product quantization and scalar quantization?
Scalar quantisation compresses each dimension on its own, usually to one byte, for a 4-fold saving with little accuracy loss. Product quantisation compresses groups of dimensions with learned codebooks for much higher compression and a larger accuracy cost.
What is IVF-PQ?
IVF-PQ combines an inverted file index, which limits search to a few clusters, with product quantisation codes for the vectors inside them. It is a standard design for very large collections.
Does product quantization need retraining?
Yes, when the data changes substantially. Codebooks are fitted to a training sample, so a new embedding model or a shift in corpus content means retraining and re-encoding the collection.
Do I need product quantization with Exabase?
No. Exabase indexes stored content automatically and Deep Search handles retrieval, so there are no codebooks or compression settings to manage.
Related pages: Vector quantisation, Binary quantisation, IVF index, FAISS, Vector index, HNSW, Vector database, Best vector databases, RAG accuracy