Paper 59~11 min readTPAMI 2011worked math + runnable code
Paper Breakdown

Product quantization,
explained.

A billion embeddings at full precision is terabytes of memory — too much to search fast. Product quantization is the trick that shrinks them, and it's cleverer than rounding: chop each vector into a few pieces, and replace every piece with the nearest entry from a tiny catalog of typical pieces. Store the catalog indices, not the numbers, and a 512-byte vector becomes 8 bytes — while a handful of small catalogs still tell billions of vectors apart. Here's how, and why the distances stay usable.

Video breakdown
The animated walkthrough is in production.
Read the full breakdown below in the meantime ↓
01

The memory wall

Nearest-neighbour search over embeddings — find the vectors closest to a query — is the engine under semantic search, recommendations, and retrieval. At small scale you just store every vector and compare. But a modern embedding might be 128 or 768 dimensions of float32, and a billion of them is hundreds of gigabytes to terabytes. That won't fit in fast memory, and scanning it is slow. The bottleneck is not the math; it's the bytes.

The obvious fix — store fewer bits per number — is crude: uniformly rounding each dimension loses too much accuracy for too little saving. Product quantization does something smarter. It compresses groups of dimensions together by learning what typical groups look like, so each group is replaced by a pointer to its closest learned prototype. The savings are enormous and the distances survive well enough to search — which is exactly the balance vector search needs.

The one-sentence version

Cut each vector into pieces, replace every piece with the nearest entry from a small learned codebook, and store the tiny indices — huge compression, distances mostly intact.

02

Split and quantize

The recipe: split a D-dimensional vector into m contiguous subvectors. For each subspace, learn a codebook of k centroids (by k-means over the training data). To compress a vector, replace each subvector with the index of its nearest centroid in that subspace's codebook. The stored representation is just m indices. With the conventional k = 256, each index is one byte:

raw = 4·D bytes  ·  PQ = m · ⌈log₂ k / 8⌉ bytes  →  k=256: m bytes  ·  ratio = 4D / m

A 128-dim float vector is 512 bytes; split into m = 8 subvectors with 256-entry codebooks, it becomes 8 bytes — 64× smaller. The subvectors are quantized independently, which is what keeps the codebooks tiny (each covers only D/m dimensions) while still capturing the structure within each slice. The runnable version below computes the compression and the reconstruction.

03

A huge code space

Here's the beautiful part, and the reason it's called a product quantizer. Each subspace has only k centroids — a small catalog. But a full vector is an independent choice of centroid in every subspace, so the number of distinct vectors the scheme can represent is the product of the per-subspace choices: km. Small catalogs, combined, span an astronomically large space.

representable codes = km  →  2568 ≈ 1.8 × 1019

Eight one-byte codebooks of 256 entries each yield 256⁸ ≈ 1.8 × 10¹⁹ possible codes — far more than any dataset you'd ever index, all from storing 8 bytes. That combinatorial explosion is why product quantization compresses so aggressively without collapsing distinct vectors onto the same code. You get the resolution of an enormous codebook at the storage cost of a tiny one.

04

Fast distances

Compression is only useful if you can still compare quickly. Product quantization uses asymmetric distance computation: keep the query at full precision, but for each subspace precompute the distance from the query's subvector to every centroid in that subspace's codebook — a small lookup table of m × k numbers, built once per query.

Scoring a compressed vector
Per queryBuild tables: distance from each query subvector to all k centroids, per subspace.
Per vectorIts distance ≈ sum of m table lookups, indexed by its m codes.
CostA few additions per database vector — no decompression, no full-precision math.
AsymmetricQuery stays exact; only the database is quantized → more accurate than compressing both.

So scoring a billion compressed vectors is a billion sums of m small lookups — cache-friendly and blazing fast. Keeping the query uncompressed (the "asymmetric" part) makes the approximation noticeably more accurate than the symmetric alternative of quantizing the query too, at no extra storage cost.

RUN IT YOURSELF

Compress a vector, keep the distances

Product quantization is a few lines of arithmetic. This prices the compression — a 128-dim float vector (512 bytes) stored as 8 one-byte codes, 64× smaller — and confirms the combinatorial code space (256⁸ ≈ 1.8×10¹⁹ from 8 bytes). It then quantizes subvectors to their nearest centroid and scores a full-precision query by asymmetric distance: summing per-subspace lookups, where the correct code lands at distance 0 and a wrong code doesn't. Change m, k, or the codebooks and watch the storage and distances move.

CPython · WebAssembly
05

In practice

Product quantization rarely works alone; it pairs with a coarse index to avoid scanning the whole dataset:

PieceRole
Coarse quantizer (IVF)An inverted file partitions vectors into cells; a query only scans a few nearby cells, not everything.
Product quantizationCompresses the vectors inside those cells so they fit in memory and score fast.
IVFPQThe combination — coarse cells + PQ codes — is a workhorse of large-scale ANN, e.g. in FAISS.
Re-rankingOptionally re-score the top candidates with exact vectors for precision.

The knobs are intuitive: more subquantizers m or a larger k lowers distortion (better recall) at the cost of more bytes and slower scoring. Tuning m and k against a memory and recall budget is the core of deploying PQ-based search.

06

Why it endures

Product quantization predates the deep-learning embedding boom — it came from image retrieval in 2011 — but it became foundational precisely when everything turned into vectors. When you embed a billion documents, images, or products, you hit exactly the memory wall PQ was built for, and its combination of aggressive compression with fast, decompression-free distances is hard to beat. Libraries like FAISS made it a default, and it lives inside many production vector databases today.

Its lasting idea is compression by learned structure. Generic bit-reduction throws away information blindly; product quantization instead learns what the data actually looks like, subspace by subspace, and spends its bits describing which learned prototype each piece resembles. That "quantize against a learned codebook" pattern recurs across the field — in model weight quantization, in KV-cache compression, and beyond — and this paper is one of its clearest, most enduring expressions.

Worth knowing

The same "product of small codebooks" idea powers residual and additive quantization (used to compress LLM weights to a few bits): stack several codebooks and sum their contributions for even finer resolution at low bit-rates.

Frequently asked

Quick answers

What does product quantization do?

Splits a vector into m subvectors, quantizes each to one of k codebook centroids, and stores the m indices — compressing a 4D-byte vector to m bytes (m at k=256).

Why is it so compact?

m small codebooks combine to represent k^m distinct vectors, so tiny per-subspace catalogs span an enormous space — huge resolution at the storage cost of a few bytes.

How are distances computed?

Asymmetric distance: keep the query exact, precompute its distance to every centroid per subspace, then sum m table lookups per database vector — fast, no decompression.

Where is it used?

Inside large-scale vector search, usually as IVFPQ (inverted file + PQ) in libraries like FAISS and many production vector databases.

Product Quantization for Nearest Neighbor Search · Jégou, Douze, Schmid · IEEE TPAMI 2011 · read the original paper → · Vibe Engines · 2026
Finished this one? 0 / 101 Paper Breakdowns done

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Paper Breakdowns