Inferensys

Glossary

Product Quantization (PQ)

A vector compression technique that decomposes high-dimensional vectors into smaller subvectors, quantizing each independently using a distinct codebook to dramatically reduce memory footprint and accelerate distance calculations.
Engineer reviewing vector database search results on laptop, embeddings visualization on screen, home office coding session.
VECTOR COMPRESSION TECHNIQUE

What is Product Quantization (PQ)?

Product Quantization (PQ) is a lossy compression technique that decomposes high-dimensional vectors into smaller subvectors, quantizing each independently using a distinct codebook to dramatically reduce memory footprint and accelerate approximate distance calculations.

Product Quantization (PQ) is a vector compression technique that decomposes a high-dimensional vector into several lower-dimensional subvectors. Each subvector is independently quantized by mapping it to the nearest centroid in a distinct, pre-trained codebook. The original vector is then stored as a short code—a tuple of centroid indices—reducing storage from floating-point precision to a few bytes per vector.

Distance computation is performed using Asymmetric Distance Computation (ADC) , where the full-precision query vector is compared against the compressed database codes via pre-computed lookup tables. This avoids decompression overhead. The primary tradeoff is quantization error: the distortion between the original vector and its quantized approximation, which directly impacts search recall.

VECTOR COMPRESSION MECHANICS

Key Characteristics of Product Quantization

Product Quantization (PQ) is a lossy compression technique that decomposes high-dimensional vectors into orthogonal subvectors and quantizes each independently. This section details the core mechanisms that enable massive memory reduction and fast approximate distance calculations.

01

Subspace Decomposition

The fundamental operation that splits a D-dimensional vector into M distinct subvectors of dimension D/M. Each subvector resides in its own orthogonal subspace, allowing independent quantization. This structural assumption—that the joint distribution factorizes across subspaces—is the key to PQ's efficiency, reducing the exponential complexity of full vector quantization to a linear combination of smaller problems.

02

Independent Codebook Learning

A distinct codebook of k centroids is learned for each of the M subspaces, typically via k-means clustering on the subvector training data. The full vector is then represented by a compact tuple of M centroid indices. With M=8 and k=256, a 128-dimensional float32 vector (512 bytes) compresses to just 8 bytes, achieving a 64x memory reduction.

03

Asymmetric Distance Computation (ADC)

The standard distance approximation strategy where the query vector is kept in full precision while database vectors are compressed. The query is split into subvectors, and distances to all centroids in each subspace's codebook are precomputed into lookup tables. The approximate distance to any compressed database vector is then assembled by summing M table lookups, avoiding explicit vector reconstruction.

04

Quantization Error Tradeoff

The distortion introduced by mapping continuous subvectors to discrete centroids. This error is the primary accuracy bottleneck and is controlled by two hyperparameters:

  • M (number of subspaces): More subspaces mean shorter codes but coarser quantization per subspace.
  • k (codebook size): Larger codebooks reduce error but increase training time and lookup table size. The optimal configuration balances memory footprint against recall degradation for the target application.
05

Optimized Product Quantization (OPQ)

An enhancement that applies an orthogonal rotation matrix to the original vector space before subspace decomposition. This rotation minimizes the statistical dependence between subspaces, making the factorization assumption more valid. OPQ learns the rotation jointly with the codebooks, significantly reducing quantization error for correlated dimensions without increasing the code length.

06

Distance Table Lookup Speed

The computational core of PQ search. For a query, M lookup tables of size k are precomputed once. The approximate distance to any database vector requires only M additions—reading precomputed values from each table using the stored centroid indices. This replaces a full D-dimensional float32 distance computation with simple integer-indexed additions, achieving orders-of-magnitude speedups on modern CPUs with SIMD.

VECTOR COMPRESSION COMPARISON

Product Quantization vs. Other Compression Techniques

A technical comparison of Product Quantization against scalar quantization and binary quantization for compressing high-dimensional vectors in ANN search.

FeatureProduct QuantizationScalar QuantizationBinary Quantization

Compression Mechanism

Subvector clustering with independent codebooks

Per-dimension value binning

Single-bit threshold per dimension

Typical Compression Ratio

8-32x

2-4x

32x

Distance Computation

Asymmetric Distance Computation (ADC)

Integer arithmetic

POPCNT / Hamming distance

Memory Footprint (128-dim float32)

16-64 bytes

128-256 bytes

16 bytes

Recall@10 vs. Brute-Force

95-99%

99-100%

80-90%

Codebook Training Required

Subvector Independence Assumption

Suitable for High-Precision Search

PRODUCT QUANTIZATION

Frequently Asked Questions

Clear, technical answers to the most common questions about Product Quantization, covering its mechanics, accuracy tradeoffs, and practical implementation in vector search systems.

Product Quantization (PQ) is a vector compression technique that decomposes a high-dimensional vector into several lower-dimensional subvectors and quantizes each independently using a distinct codebook. The process begins by splitting a D-dimensional vector into M subvectors of dimension D/M. A k-means clustering algorithm is then run on each subspace independently, generating M codebooks, each containing K centroids. An original vector is encoded as a short code of M integers, where each integer is the ID of the nearest centroid in that subspace's codebook. During search, distances between a query vector and database vectors are approximated using Asymmetric Distance Computation (ADC), where the query is kept in full precision and distances are precomputed against all centroids, then summed via lookup tables. This reduces memory from D × 32 bits per vector to M × log2(K) bits, often achieving compression ratios of 10-30x while preserving enough information for accurate approximate nearest neighbor search.

Prasad Kumkar

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.