Zenaique

PQ based distance computation outruns full float32 distance even after decoding the vectors. Why?

MCQ·Medium·4.0 · 0·~1 min·Asked atTech MahindraZillizZoho·Relevant atMicrosoftNVIDIA
Attempt it
TL;DR

Asymmetric Distance Computation (ADC): for each query, precompute a pq_m x 256 table of query to centroid distances.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Imagine you have a million items in a warehouse, each described by 32 'category tags'. A new query arrives and you want to find the closest items. The slow way is to fully expand every tag back into its full description and compare. The clever way: first, for each query, compute once how 'close' the query is to each of the 256 possible values of each tag. Now you have a small cheat-sheet. To score any warehouse item, just look up its 32 tags in the cheat-sheet and add up the 32 numbers. No real math per item, just lookups and adds. That is **asymmetric distance computation**.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

This question separates candidates who memorized 'PQ is fast' from candidates who understand why. The mechanism is asymmetric distance computation: precompute a query to codebook distance table once, then reduce every database-vector distance to a handful of cache-friendly lookups plus adds. That is the actual unlock for billion-scale ANN on CPU.

The arithmetic reduction

Full float distance against one 1024-dim vector: 1024 multiplies + 1024 adds = ~2048 float ops. ADC reduces this to pq_m = 32 lookups + 32 adds per database vector. That is roughly 30-60x fewer operations per vector. Combined with the smaller memory footprint (32 bytes vs 4096 bytes per vector), the effective scan throughput jumps by two orders of magnitude.

The per query setup amortizes over the entire scan. For a typical IVF-PQ deployment scanning a few percent of a billion-vector corpus, the setup cost is sub-millisecond and the scan cost dominates.

Why the lookup table fits in cache
Why distractors B, C, D are wrong
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.
ApproachPer query setupPer DB vector costRecall
Full float distance0O(d) multiplies + addsExact
Decode then compare PQ0O(d) multiplies + adds (after decode)Approx (quantization)
SDC (symmetric)0 (table precomputed at index time)pq_m lookups + addsApprox (both sides quantized)
ADC (asymmetric)pq_m * 256 distance opspq_m lookups + addsApprox (only DB quantized; best of the three approx options)

Real products, models, and research that use this idea.

  • Faiss IndexIVFPQ uses ADC by default; the fast path is hand-tuned SIMD that hits sub-10 ns per database vector.
  • Faiss PQ4 fast scan packs pq_m=64 nbits=4 codes for AVX-512, hitting >2 billion distance computations per second per core.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QWhy does ADC beat SDC on recall?
A

SDC quantizes both sides, introducing error on both. ADC keeps the query lossless. For the same code budget, ADC produces a more accurate distance estimate.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Assuming the speedup comes from compression alone. Smaller vectors do help with memory bandwidth, but the headline win is the table-lookup arithmetic: pq_m additions per vector instead of d float multiplies and adds.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • ADC = asymmetric distance computation

  • Query stays float; database stays in PQ codes

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
HNSW vs IVF, when…
Flashcard·Medium