Walk through how Product Quantization compresses a 1024-dim float32 vector down to 32 bytes, step by step.
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Explain the Product Quantization compression pipeline that takes a 1024-dim float32 vector (4096 bytes) and produces a 32-byte PQ-encoded representation. Cover the offline training step and the per vector encoding step.
Split the 1024-dim vector into 32 sub-vectors of 32 dims. For each subspace, k-means produced 256 centroids during offline training. Encode each sub-vector as the 1-byte index of its nearest centroid.
Imagine your 1024-number vector is a long bookshelf with 1024 books. **The chunked-codebook method** (called PQ) chops the shelf into 32 mini-shelves of 32 books each. For each mini-shelf, a librarian has already prepared a catalogue of 256 typical mini-shelf arrangements (the codebook). To compress your bookshelf, you look at each of your 32 mini-shelves, find the catalogue entry that looks most like it, and write down that catalogue number. Catalogue numbers go from 0 to 255, which fits in one byte. So your entire 1024-book shelf becomes 32 small numbers, one per mini-shelf. The cost is that two different mini-shelf arrangements may round to the same catalogue entry, so some detail is lost; that is the rounding error.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
4 min: phase split (offline codebooks vs per vector encoding) + the 256/byte alignment + compression math + quantization error + OPQ + production composition with IVF or HNSW.
| Aspect | Offline codebook training | Per-vector encoding |
|---|---|---|
| When it runs | Once per corpus (re-run on distribution shift) | On every insert |
| Input | 100k-1M training vectors | One float32 vector |
| Cost per call | Minutes (k-means convergence) | Microseconds (32 * 256 distance ops) |
| Output | 32 codebooks, 1 MB total | 32-byte PQ code |
| Failure mode | Training set unrepresentative -> bad centroids | None at encoding; recall loss is from codebook quality |
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Confusing the offline codebook training (run once per corpus, expensive) with per vector encoding (run on every insert, cheap). They are different phases with different costs and different inputs.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.