Inferensys

Glossary

Product Quantization (PQ)

A vector compression technique that decomposes high-dimensional vectors into smaller sub-vectors and quantizes them independently, drastically reducing memory footprint for approximate nearest neighbor search.
Engineer reviewing vector database search results on laptop, embeddings visualization on screen, home office coding session.
VECTOR COMPRESSION TECHNIQUE

What is Product Quantization (PQ)?

A lossy compression method for high-dimensional vectors that decomposes the original space into a Cartesian product of lower-dimensional subspaces and quantizes each independently.

Product Quantization (PQ) is a vector compression technique that splits a high-dimensional vector into distinct, lower-dimensional sub-vectors and quantizes each sub-vector independently using a separate codebook. This process drastically reduces the memory footprint required to store large vector datasets by representing the original vector as a compact sequence of codebook indices, enabling efficient approximate nearest neighbor (ANN) search in billion-scale collections.

During similarity search, the query vector is decomposed identically, and distances are computed efficiently using pre-calculated lookup tables between the query sub-vectors and the codebook centroids. This asymmetric distance computation avoids reconstructing the full vectors, trading a small amount of recall accuracy for substantial gains in speed and storage efficiency. PQ is a foundational component in scalable vector databases like FAISS.

VECTOR COMPRESSION

Key Features of Product Quantization

Product Quantization (PQ) decomposes high-dimensional vectors into orthogonal sub-vectors and quantizes each independently, achieving massive memory compression while preserving the geometry required for accurate approximate nearest neighbor search.

01

Sub-Vector Decomposition

The core mechanism of PQ is dimensionality splitting. A D-dimensional vector is divided into M disjoint sub-vectors of dimension D/M. Each sub-vector is then quantized independently using its own codebook of k centroids. This transforms the original vector into a compact tuple of M codebook indices, reducing storage from D×32 bits to M×log₂(k) bits. For a 128-dimensional vector split into 8 sub-vectors with 256 centroids each, the compressed representation requires only 64 bits—a 64× compression ratio.

02

Codebook Learning via K-Means

Each sub-space requires a codebook—a set of representative centroids learned offline using k-means clustering on a training set of sub-vectors. The process:

  • Partition the training vectors into their M constituent sub-vectors
  • Run independent k-means on each sub-space to produce k centroids
  • Store the M codebooks as the quantization model

The quality of the codebook directly determines search accuracy. Typically, k=256 is used, meaning each sub-vector index fits in a single byte, enabling extremely cache-friendly memory layouts.

03

Asymmetric Distance Computation

During query time, PQ employs Asymmetric Distance Computation (ADC) to approximate distances without decompressing the database vectors. The query vector is split into sub-vectors, and the exact distance from each query sub-vector to every centroid in the corresponding codebook is pre-computed into a lookup table. For each compressed database vector, the approximate distance is assembled by summing the pre-computed distances indexed by the stored codes. This avoids the costly operation of reconstructing the full vector, achieving sub-linear search complexity.

04

Memory Footprint Reduction

PQ delivers dramatic memory savings critical for billion-scale vector search. A typical 1024-dimensional float32 vector consumes 4 KB. With PQ using M=64 sub-vectors and k=256 centroids, the compressed representation requires only 64 bytes—a 64× reduction. For 1 billion vectors, this shrinks memory from 4 TB to 62.5 GB, enabling the entire index to reside in RAM on a single high-memory server. This eliminates the latency penalty of disk-based retrieval and makes real-time similarity search economically viable.

64×
Typical Compression Ratio
64 bytes
Per-Vector Storage (1024-d)
05

Trade-Off: Recall vs. Compression

PQ introduces a tunable accuracy-efficiency trade-off governed by two parameters:

  • M (number of sub-vectors): Higher M increases compression but reduces the dimensionality of each sub-space, potentially degrading distance approximation quality
  • k (codebook size): Larger k improves quantization fidelity but increases codebook storage and lookup costs

Typical configurations balance M between D/8 and D/2. For exact search, PQ serves as a coarse quantizer in inverted file systems, where candidate vectors are first filtered by a separate IVF index before PQ-based distance refinement. This two-stage approach routinely achieves >95% recall@10 with sub-millisecond latency.

06

Integration with Inverted File Indexes

PQ is rarely used in isolation for large-scale search. The IVF-PQ architecture combines an Inverted File (IVF) index for coarse partitioning with PQ for fine-grained compression:

  • A coarse quantizer partitions the vector space into Voronoi cells
  • Each database vector is assigned to its nearest coarse centroid and stored in the corresponding inverted list
  • Within each list, vectors are stored in PQ-compressed form
  • At query time, only the nprobe nearest coarse centroids are visited, and ADC is applied to the compressed vectors in those lists

This hierarchical approach enables billion-scale ANN search with memory footprints measured in tens of gigabytes.

PRODUCT QUANTIZATION EXPLAINED

Frequently Asked Questions

Clear, technical answers to the most common questions about Product Quantization (PQ), its mechanisms, and its role in high-performance vector search systems.

Product Quantization (PQ) is a vector compression technique that decomposes a high-dimensional vector into multiple lower-dimensional sub-vectors and quantizes each sub-vector independently using a distinct codebook. The original vector is then represented as a short code composed of the indices of the nearest centroids in each subspace. This process drastically reduces the memory footprint of a vector database, enabling billion-scale approximate nearest neighbor (ANN) search to fit entirely in RAM. The core mechanism involves three steps: subspace decomposition, independent clustering via k-means on each subspace, and encoding by concatenating the centroid IDs. During search, distances are computed efficiently using pre-calculated lookup tables, trading a small amount of recall for massive compression ratios, often reducing a 1024-dimensional float32 vector from 4096 bytes to just 64 bytes.

VECTOR COMPRESSION COMPARISON

Product Quantization vs. Other Compression Techniques

A technical comparison of Product Quantization against alternative vector compression and dimensionality reduction methods for approximate nearest neighbor search.

FeatureProduct Quantization (PQ)Scalar Quantization (SQ)Random Projection

Compression Mechanism

Sub-vector decomposition with independent codebook clustering

Uniform bit-width reduction per dimension (e.g., float32 to int8)

Johnson-Lindenstrauss lemma projection onto random lower-dimensional subspace

Memory Reduction Factor

8-32x typical (e.g., 128-dim float32 to 64 bytes)

2-4x typical (e.g., 32-bit to 8-bit per dimension)

Configurable by target dimension; 2-10x common

Distance Computation Method

Asymmetric Distance Computation (ADC) via precomputed lookup tables

Standard distance metrics on quantized integer representations

Euclidean distance in projected space with approximate distance preservation

Preserves Original Space Geometry

Requires Training/Clustering Phase

Recall@10 on SIFT1M (64 bytes/vector)

~95% with IVFADC index

~98% with 8-bit quantization

~85% at equivalent compression ratio

Query-Time Overhead

Table lookup + partial distance aggregation; < 1 ms per query typical

Negligible; direct integer arithmetic

Single matrix multiplication; < 0.5 ms typical

Susceptibility to Curse of Dimensionality

Mitigated by sub-vector partitioning; effective up to ~1000 dimensions

Unaffected; operates per-dimension independently

Strong theoretical guarantees; distortion bounded by O(log n / k) for target dimension k

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.