A Product Quantization (PQ) codebook is the learned set of centroid vectors for a specific subspace within the PQ algorithm. During index training, the full vector space is split into independent subspaces, and a separate codebook is created for each via k-means clustering. Each codebook contains a small, representative set of centroids (e.g., 256) that act as prototypes for all vectors in that subspace, forming the basis for lossy compression.
Glossary
Product Quantization Codebooks

What is Product Quantization Codebooks?
Product Quantization codebooks are the sets of learned centroid vectors that enable the compression and fast search of high-dimensional data.
During search, these codebooks enable Asymmetric Distance Computation (ADC), where a raw query vector is compared directly to the stored centroids. This allows the system to approximate distances to compressed database vectors rapidly and with high memory efficiency. The quality and representativeness of the codebooks directly determine the recall-precision trade-off and the fidelity of the compressed search results.
Key Characteristics of PQ Codebooks
Product Quantization codebooks are the learned centroid sets that enable extreme vector compression. Their design directly governs the trade-off between search accuracy, memory efficiency, and query speed in billion-scale vector databases.
Subspace Decomposition
A PQ codebook is not a single set of centroids for the entire vector. Instead, the high-dimensional space is split into m disjoint subspaces (e.g., splitting a 128D vector into 8 subspaces of 16D each). A separate, smaller codebook is learned for each subspace via k-means clustering. This decomposition is critical because quantizing in full space would require an astronomically large codebook to maintain accuracy, whereas subspace quantization keeps the total number of centroids manageable (m * k).
Memory-Efficient Encoding
The primary function of a PQ codebook is to enable ultra-compact vector storage. Each original vector is compressed by:
- Finding the nearest centroid in each subspace's codebook.
- Replacing the original subvector with the centroid index (an integer).
- The final compressed representation is a concatenation of these m indices, called a PQ code. This code is extremely compact; for example, with m=8 and k=256 centroids per subspace, each index requires 8 bits (since 2^8=256). Thus, a 128-dimensional vector of 32-bit floats (512 bytes) is reduced to an 8-byte code, achieving a 64x compression ratio.
Asymmetric Distance Computation (ADC)
PQ codebooks enable fast approximate distance calculation without decompressing database vectors. During a query, the system performs Asymmetric Distance Computation (ADC):
- The raw, uncompressed query vector is split into its m subvectors.
- For each subspace, the precomputed distance between the query subvector and every centroid in that subspace's codebook is looked up from a distance table.
- The approximate distance to a database vector is the sum of the distances to the centroids indexed by its PQ code. This method is 'asymmetric' because the query is raw, while the database vectors are quantized, yielding more accurate distances than comparing two quantized (symmetric) representations.
Training and Distribution
PQ codebooks are trained offline on a representative sample of the dataset. The training process for each subspace's k-means is independent, allowing for parallelization. The quality of the codebooks is paramount; poor centroids lead to high quantization error. In practice, codebooks are often trained using a residual vector dataset after a first-stage coarse quantizer (as in the IVFADC index in Faiss), where the codebooks learn the distribution of error residuals, not the original vectors, for greater accuracy.
Trade-off: Accuracy vs. Efficiency
The configuration of PQ codebooks involves a fundamental trade-off governed by two parameters:
- m (number of subspaces): More subspaces increase the granularity of quantization, reducing error and improving recall, but also increase the distance table size queried during ADC.
- k (centroids per subspace): More centroids per subspace (e.g., k=256 vs. k=16) drastically reduces quantization error but linearly increases memory for the codebooks themselves and the precomputed distance table. Engineers tune (m, k) to balance search recall, query latency, and memory footprint for their specific accuracy and scale requirements.
Integration with Composite Indexes
PQ codebooks are rarely used in isolation. They are a core component of high-performance composite ANN indexes:
- IVF + PQ (IVFADC): An Inverted File (IVF) index uses a coarse quantizer to select a small subset of candidate vectors. PQ codebooks are then used to compress these candidates, enabling ADC for fast, accurate search within the list.
- HNSW + PQ: A Hierarchical Navigable Small World (HNSW) graph provides the candidate traversal, and PQ is used to compress the vectors stored in the graph nodes, dramatically reducing the index's memory footprint while maintaining high recall.
PQ Codebooks vs. Other Quantization Methods
A comparison of Product Quantization (PQ) codebooks against other common vector quantization methods used for compressing high-dimensional embeddings in approximate nearest neighbor search.
| Feature / Metric | Product Quantization (PQ) Codebooks | Scalar Quantization (SQ) | Residual Quantization (RQ) | Binary Quantization (BQ) |
|---|---|---|---|---|
Core Mechanism | Decomposes vector into M subspaces, quantizes each with a learned codebook. | Quantizes each vector component (dimension) independently to a lower-bit integer. | Hierarchically quantizes the residual error from previous quantization stages. | Projects vectors to binary codes (e.g., +1/-1) using learned or random hyperplanes. |
Compression Ratio | High (e.g., 32x to 64x). Represents vector as M integer codes. | Moderate (e.g., 4x to 8x). Reduces precision per dimension (e.g., float32 to int8). | Very High. Achieves lower error than PQ at similar compression via multi-stage refinement. | Extreme (e.g., 32x). Represents vector as a compact bitstring. |
Distance Computation | Asymmetric Distance Computation (ADC) or Lookup Tables. | Simple arithmetic on integers (fast CPU ops). | Asymmetric, multi-stage table lookups. | Hamming distance (bitwise XOR & popcount) or learned asymmetric distances. |
Search Accuracy (Recall) | High for its compression rate, especially with IVFADC composite index. | High (near-lossless) at moderate compression (e.g., 8-bit). | Highest among quantization methods for a given bit budget. | Lower, suitable for pre-filtering or high-speed, low-accuracy scenarios. |
Index Memory Footprint | Very Low. Stores only code indices and small codebooks. | Low. Stores integer arrays. | Low. Stores multi-stage code indices and codebooks. | Extremely Low. Stores only bits. |
Index Build Time | High. Requires k-means training on subspaces for each codebook. | Low. Simple min/max range calculation per dimension. | Very High. Requires sequential training of multiple codebook layers. | Low to Moderate. May require learning rotation matrices for optimization. |
Query Latency | Fast (with ADC table lookups). Latency scales with number of subspaces M. | Very Fast. Direct integer operations with no complex lookups. | Moderate. Multiple lookup stages add overhead. | Extremely Fast. Hamming distance is hardware-optimized. |
Handling of High Dimensions | Excellent. Subspace decomposition mitigates the curse of dimensionality. | Good. Independent per-dimension quantization scales linearly. | Excellent. Hierarchical approach effectively models high-D distributions. | Good, but information loss per dimension can be significant. |
Common Use Case | Billion-scale vector databases where memory efficiency is paramount (e.g., IVFADC, IVFPQ). | In-memory indices where near-exact accuracy is needed with reduced memory (e.g., Faiss SQ). | Applications requiring the highest possible accuracy under aggressive compression constraints. | First-stage filtering, retrieval in highly constrained (edge) environments, or with binary embeddings. |
Implementations & Libraries Using PQ Codebooks
Product Quantization (PQ) is a cornerstone of large-scale vector search. These are the primary libraries and systems that implement PQ codebooks for efficient similarity search and compression.
Vector Database Core Engines
Most modern vector databases use PQ-based indexes as a core component for memory-efficient, high-throughput search:
- Pinecone: Uses PQ within its proprietary single-stage and multi-stage indexes.
- Weaviate: Uses PQ compression in its HNSW implementation (
pqsegment type) to reduce the in-memory footprint of vectors, enabling larger datasets. - Milvus & Zilliz: Implement
IVF_PQas a primary index type, allowing configurablem(subvectors) andnbits(centroids per codebook). - Qdrant: Supports
Scalar QuantizationandProduct Quantizationas compression methods for its HNSW and IVF indices.
Frequently Asked Questions
Product Quantization (PQ) codebooks are the fundamental components that enable the compression of high-dimensional vectors for efficient storage and fast similarity search. This FAQ addresses their core mechanics, trade-offs, and role in modern vector databases.
A Product Quantization (PQ) codebook is a learned set of representative vectors, or centroids, for a specific subspace of the original high-dimensional vector space. The core algorithm works by splitting a full-dimensional vector (e.g., 128-D) into m distinct subvectors (e.g., 8 subvectors of 16-D each). For each of these m subspaces, a separate codebook is trained via k-means clustering, typically with k=256 centroids. This allows any vector in that subspace to be mapped to the index of its nearest centroid. A complete vector is thus compressed into a PQ code—a concatenation of m centroid indices (e.g., 8 bytes for m=8, k=256)—which is extremely memory-efficient.
During a search, distances are approximated using precomputed lookup tables. For a query, the distance to every centroid in each subspace codebook is computed once and stored. The approximate distance to a compressed database vector is then efficiently calculated by summing the precomputed distances for each subvector's assigned centroid index.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Product Quantization (PQ) is a core technique for compressing high-dimensional vectors. Its efficiency depends on several interconnected concepts, from the foundational quantization step to the composite indexing systems that leverage it.
Product Quantization (PQ)
Product Quantization (PQ) is a lossy compression technique for high-dimensional vectors. It works by splitting the original vector space into several independent subspaces, performing k-means clustering in each subspace to create a small set of representative centroid vectors, and then replacing any vector with a short code composed of the indices of its nearest centroid in each subspace. This dramatically reduces memory footprint, enabling billion-scale vector datasets to fit in RAM.
- Core Mechanism: Decompose, quantize per subspace, encode.
- Primary Benefit: Memory efficiency via extreme compression.
- Trade-off: Introduces quantization error, making distances approximate.
Asymmetric Distance Computation (ADC)
Asymmetric Distance Computation (ADC) is the standard method for calculating distances when using Product Quantization. It compares a raw, uncompressed query vector against database vectors that have been compressed using PQ. The distance is approximated by looking up pre-computed distances between the query's subvectors and the centroid vectors stored in the codebooks. This is more accurate than Symmetric Distance Computation (SDC), which would compare two compressed vectors, because it preserves full query precision.
- Key Advantage: Higher accuracy for a given compression level.
- Implementation: Relies on pre-computed distance tables between query subvectors and all centroids.
- Use Case: Essential for the search phase in IVF-PQ and similar indices.
Inverted File with Asymmetric Distance Computation (IVFADC)
IVFADC is a powerful, composite indexing structure that combines an Inverted File (IVF) index with Product Quantization (PQ) using Asymmetric Distance Computation (ADC). It operates in two stages: First, a coarse quantizer (like k-means) partitions the dataset into Voronoi cells (the inverted file). For a query, only vectors in the most promising cell(s) are examined. Second, these candidate vectors, which are stored in compressed PQ format, are compared to the query using ADC. This hybrid approach provides a critical speed-accuracy trade-off.
- Architecture: Coarse filter (IVF) + fine-grained, compressed comparison (PQ/ADC).
- Benefit: Enables fast search over billion-scale datasets with manageable accuracy loss.
- Foundation: The basis for many production ANN implementations in libraries like Faiss.
Coarse Quantizer
A coarse quantizer is the first-stage clustering model used in multi-level indexing structures like Inverted File (IVF). Typically implemented with k-means, it divides the entire high-dimensional vector dataset into a relatively small number of partitions (e.g., 1024 to 16384 clusters), each forming a Voronoi cell. During a search, the system identifies the cell whose centroid is nearest to the query vector and restricts the exhaustive search to vectors within that cell and possibly its neighbors. This is the 'coarse' step that enables sub-linear search time by drastically reducing the number of vectors that need to be compared in the finer, more expensive PQ stage.
- Role: Provides fast, approximate pre-filtering.
- Output: Defines the partitions (cells) for the inverted file.
- Trade-off: Larger number of cells = faster but potentially lower recall.
Quantization Error
Quantization error is the inevitable loss of information and distortion of distances incurred when compressing a continuous vector into a discrete representation, such as mapping it to the nearest centroid in a Product Quantization codebook. This error directly impacts the accuracy of an ANN system, as the distances calculated between compressed vectors (or a raw query and a compressed vector) are approximations of the true distances. The error is influenced by the number of centroids per subspace (k) and the number of subspaces (m). A core challenge in PQ configuration is balancing this error (which hurts recall) against the gains in memory efficiency and search speed.
- Source: Lossy compression from representing many vectors with a single centroid.
- Impact: Manifests as reduced Recall@K.
- Mitigation: Using more centroids per subspace or more subspaces, at the cost of memory.
Faiss (Facebook AI Similarity Search)
Faiss is a seminal open-source library from Meta AI for efficient similarity search and clustering of dense vectors. It provides highly optimized, production-grade CPU and GPU implementations of core ANN algorithms, including Product Quantization (PQ), Inverted File (IVF), and HNSW. Faiss was instrumental in popularizing the IVFADC index structure and provides comprehensive tools for training PQ codebooks, building composite indices, and tuning the recall-speed trade-off. It serves as the benchmarking standard and a common backend for many vector databases.
- Key Feature: Implements optimized PQ codebook training and ADC.
- Index Types: Supports
IndexIVFPQ, the direct implementation of IVFADC. - Ecosystem Role: The reference implementation for PQ-based vector search.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us