Inferensys

Glossary

Product Quantization (PQ)

Product Quantization (PQ) is a vector compression technique that decomposes high-dimensional vectors into smaller sub-vectors and quantizes each independently using a learned codebook, dramatically reducing the memory footprint of an index for large-scale similarity search.
Engineer reviewing vector database search results on laptop, embeddings visualization on screen, home office coding session.
VECTOR COMPRESSION

What is Product Quantization (PQ)?

Product Quantization (PQ) is a vector compression technique that decomposes high-dimensional vectors into smaller sub-vectors and quantizes each independently using a learned codebook, dramatically reducing the memory footprint of an index for large-scale similarity search.

Product Quantization (PQ) is a lossy compression method for high-dimensional vectors that splits a vector into M distinct sub-vectors. Each sub-vector is independently quantized by mapping it to the nearest centroid in a pre-trained codebook of k codewords. The original vector is then stored as a compact code—a sequence of M integer indices—reducing memory from D * 32 bits to M * log2(k) bits, enabling billion-scale approximate nearest neighbor (ANN) search entirely in RAM.

During search, the query vector is similarly decomposed, and distances are computed efficiently using pre-calculated lookup tables between query sub-vectors and codebook centroids. This asymmetric distance computation (ADC) avoids reconstructing full vectors, trading a small accuracy loss for massive speed gains. PQ is often combined with an inverted file index (IVF-PQ) for coarse pre-filtering, forming the backbone of memory-efficient vector databases like Faiss.

Vector Compression

Key Features of Product Quantization

Product Quantization (PQ) is a lossy compression technique that decomposes high-dimensional vectors into smaller sub-vectors and quantizes each independently using a learned codebook. This dramatically reduces the memory footprint of an index for large-scale similarity search.

01

Sub-Vector Decomposition

The core mechanism of PQ involves splitting a high-dimensional vector (e.g., 1024 dimensions) into M distinct, lower-dimensional sub-vectors (e.g., 8 sub-vectors of 128 dimensions each). This decomposition is the foundational step that makes independent quantization possible. The original vector is reconstructed by concatenating the quantized representations of its sub-vectors.

02

Independent Codebook Learning

For each of the M sub-spaces, a separate codebook is learned using k-means clustering on the training data. Each codebook contains k centroid vectors (e.g., 256 centroids). During quantization, each original sub-vector is replaced by the ID of its nearest centroid in that sub-space's codebook. This replaces floating-point vectors with compact integer codes.

03

Memory Footprint Reduction

PQ achieves massive compression by storing only the centroid IDs instead of the original floating-point vectors.

  • Original vector: 1024 dimensions × 4 bytes (float32) = 4096 bytes
  • PQ-compressed: 8 sub-vectors × 1 byte (for k=256) = 8 bytes This represents a 512x reduction in storage, enabling billion-scale vector indexes to fit entirely in RAM.
512x
Typical Compression Ratio
8 bytes
Compressed Vector Size
04

Asymmetric Distance Computation (ADC)

To perform similarity search without decompressing the entire database, PQ uses Asymmetric Distance Computation. The query vector is kept in full precision and split into sub-vectors. The distances between each query sub-vector and all centroids in the corresponding codebook are pre-computed into a lookup table. The distance to any compressed database vector is then approximated by summing the pre-computed distances from the lookup table using the stored centroid IDs.

05

Trade-off: Compression vs. Recall

PQ is a lossy compression method. The approximation error is controlled by two hyperparameters:

  • M (number of sub-vectors): Fewer sub-vectors means coarser quantization and higher compression but lower accuracy.
  • k (number of centroids per codebook): More centroids provide finer granularity but require more bits per code (e.g., k=256 requires 8 bits). Tuning these parameters balances the memory-accuracy trade-off for a specific application.
06

Integration with Inverted File Index (IVF)

PQ is often combined with an Inverted File (IVF) structure to avoid exhaustive search. The vector space is first partitioned into Voronoi cells using coarse quantization. A query only visits the nearest cells. Within each cell, vectors are stored in PQ-compressed form. This two-stage approach—coarse partitioning followed by fine PQ compression—is the foundation of the IVFPQ index, a standard for billion-scale ANN search.

VECTOR COMPRESSION

Frequently Asked Questions

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

Product Quantization (PQ) is a vector compression technique that decomposes a high-dimensional vector into smaller, independent sub-vectors and quantizes each one using a distinct, pre-learned codebook. The process begins by splitting a D-dimensional vector into M sub-vectors of dimension D/M. A k-means clustering algorithm is run on each sub-space independently to generate a codebook of k centroids. The original vector is then represented not by its floating-point values, but by the M short codes (typically 8-bit integers) that identify the nearest centroid for each sub-vector. This replaces the full-precision vector with a compact code, dramatically reducing memory usage while enabling fast approximate distance calculations via table lookups.

VECTOR COMPRESSION COMPARISON

Product Quantization vs. Other Compression Techniques

A technical comparison of Product Quantization against alternative vector compression methods for approximate nearest neighbor search, evaluating memory footprint, recall, and computational trade-offs.

FeatureProduct Quantization (PQ)Scalar Quantization (SQ)Binary Embeddings

Compression Mechanism

Sub-vector clustering with learned codebooks

Per-dimension float-to-int8 mapping

Per-dimension thresholding to single bit

Memory Reduction Factor

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

4x (float32 to int8)

32x (float32 to 1 bit)

Distance Computation

Asymmetric Distance Computation (ADC) via lookup tables

Integer arithmetic or dequantized float math

Hamming distance via XOR and popcount

Recall@10 vs. Exact Search

90-98% with optimal parameters

99%+ with minimal loss

70-85% on complex semantic tasks

Codebook Training Required

Supports Inner Product Search

Sub-vector Independence Assumption

Typical Use Case

Billion-scale ANN indexes with tight memory budgets

Moderate compression with near-lossless recall

Edge devices and ultra-fast filtering stages

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.