advanced24 min studyLesson 652 in Engineering

Probe partitions without confusing them with answers

Derive IVF candidate selection, nprobe cost, boundary misses, and the conditions for exhaustive IVFFlat search.

On this page

What you’ll understand

  • Trace a coarse assignment and a missed nearest neighbor.
  • Relate searched-list sizes to actual candidate work.
  • State when probing every IVFFlat list restores exact search.

An inverted file index first groups database vectors into coarse cells, then searches selected cells for each query. The coarse representative is a routing device, not necessarily a good answer document. This distinction explains an important failure mode: the closest document can sit across a cell boundary even when its cell representative is farther away. Increasing nprobe searches more cells and often improves recall, but its cost depends on their populations. A partition count is therefore a search budget expressed indirectly through a particular trained distribution, rather than a universal number of distance evaluations.

Train routing separately from storing vectors

For a simple Euclidean IVF design, training learns nlist centroids from representative vectors. Adding a document assigns it to a centroid and stores its ID plus a representation inside that centroid’s inverted list. An IVFFlat list retains the original vector payload for exact distance computation within the lists that are scanned. Training quality matters because an unrepresentative sample can produce imbalanced or poorly placed cells, creating expensive hot lists and systematic routing misses.

A query is compared with the coarse centroids, and the selected nprobe lists supply candidates. Real implementations may use an approximate coarse quantizer or enforce extra scan limits; those create additional approximation boundaries. Separate these choices in your experiment. If a coarse quantizer misses a relevant list, exact scoring inside another list cannot recover the absent document. Likewise, reranking only the surviving candidates repairs distance estimates but not routing omissions.

ℓ(x)=argmin1≤j≤L∥x−cj∥22,C(q)=⋃j∈P(q)Lj\ell(x)=\mathop{\rm argmin}_{1\le j\le L}\lVert x-c_j\rVert_2^2,\qquad C(q)=\bigcup_{j\in P(q)}\mathcal L_j
L=nlist is a positive integer, c_j∈R^d are coarse centroids, and P(q) is the set of probed list indices. Each document is assigned once with a defined tie rule. C(q) is a candidate-ID set, not a guarantee of the true neighbors.↔ Scroll wide equations horizontally.

Budget the lists you actually visit

The number of scanned entries is the sum of the selected list lengths when every selected entry is inspected once. A balanced-list estimate replaces each length by N/nlist, but that approximation can badly underestimate a heavy cluster. Record the distribution of selected-list populations per query, not only the configured nprobe. Two query classes can share the same setting while producing very different memory traffic and tail latency because their routes encounter different regions.

In the deliberately simple case of IVFFlat with every list selected, no scan truncation, the same eligible snapshot, and exact distances, every stored vector is evaluated. That recovers exhaustive ranking subject to the stated floating-point and tie contract. It also loses the candidate-pruning advantage and can be slower than an ordinary Flat scan. Searching all IVFPQ lists is still not exact original-vector search because compressed distance estimates remain; the representation and routing approximation must be diagnosed separately.

Nscan(q)=∑j∈P(q)∣Lj∣ ≈ N nprobeLN_{\rm scan}(q)=\sum_{j\in P(q)}|\mathcal L_j|\ \approx\ \frac{N\,n_{\rm probe}}{L}
The equality assumes complete scans of the selected disjoint lists without early truncation. The approximation additionally assumes balanced lists. N, L, nprobe, and Nscan are counts; 1≤nprobe≤L. Filter checks may reduce distance computations without reducing all scanning overhead.↔ Scroll wide equations horizontally.

Tune against a stable baseline

Build exact ground truth once for a frozen corpus and query set, then sweep nprobe while holding the trained centroids and stored representation fixed. Track recall, latency percentiles, and candidates inspected. This isolates the effect of visiting more lists from the effect of retraining or changing the data. Include queries near known cell boundaries and rare document groups: an average over the dominant cluster can conceal a severe loss for another population.

Training and evaluation should use disjoint query roles when parameters are selected. After choosing a setting on a validation set, assess it on held-out queries rather than reporting the best point selected on the final test set. When corpus drift changes list balance or encoder geometry, retune and potentially rebuild. Adding more vectors to a trained index is not equivalent to adapting its coarse centroids; their fixed positions may become a worse description of the new population.

A nearest document across the boundary

Use one-dimensional centroids c₁=0 and c₂=10. Store document A=4.9 and document B=6.0 using nearest-centroid assignment. Search q=5.1 with exact coarse distances and complete list scans, first with nprobe=1 and then with nprobe=2.

  1. Assign A to c₁ because its centroid distances are 4.9 and 5.1. Assign B to c₂ because its centroid distances are 6 and 4. The two lists each contain one document, so both assignments are unambiguous.

  2. The query is 5.1 from c₁ and 4.9 from c₂, so one probe chooses list 2. Only B is examined, with squared query distance (6−5.1)²=0.81. The true closer A has squared distance (5.1−4.9)²=0.04 but is absent.

  3. Two probes inspect both entries and return A with squared distance 0.04. Scanned candidates increase from one to two, and the exact nearest document is now included without changing any document scores.

The result

The one-probe miss comes from cell selection, not from inaccurate scoring. Probing both IVFFlat lists repairs this example because the scan becomes exhaustive.

Explore the model

Interactive lab

Interactive lab · cache

Candidate working sets can have different reuse

Reset, set Cache capacity C to 4 and Request stride s to 4. Predict a four-address period and, at the initial 16 requests, 4 misses plus 12 hits; Step adds one request, giving 13 hits. Reset, set C to 2 and s to 4, predict 16 initial misses and one further miss after Step. The trace caps at 4096 requests. This is a fixed 16-address LRU analogy for list-data reuse, not IVF routing or a retrieval benchmark.

Candidate working sets can have different reuseA fully associative LRU cache starts empty and requests address (i·s) mod 16. Hits move an address to the newest position; misses evict the oldest when full. Playback starts with 16 requests and adds two per second, capped at 4096 explicitly simulated requests. This toy stream is not a processor-cache benchmark. Current readings: Hits / requests: 0 / 16; Hit rate: 0%; Address-stream period: 16 addresses. All parameters are adjustable with the labeled controls below.Fully associative LRU cache after 16 deterministic requests: 0 hits and 16 misses.Most recent 16 requestsaddress = i × 3 mod 160M3M6M9M12M15M2M5M8M11M14M1M4M7M10M13MCurrent cache order · oldest → newest471013Latest address 13 · miss: inserted as newestToy address stream · period 16 · starts empty
Cached addressMiss / evictionMost recent request
Hits / requests
0 / 16
Hit rate
0%
Address-stream period
16 addresses
t = 0 s

A fully associative LRU cache starts empty and requests address (i·s) mod 16. Hits move an address to the newest position; misses evict the oldest when full. Playback starts with 16 requests and adds two per second, capped at 4096 explicitly simulated requests. This toy stream is not a processor-cache benchmark. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forEqual request counts can have different memory behavior when the working set exceeds capacity.

Check your understanding

Which configuration is exhaustive original-vector search under the stated assumptions?

Try it yourself

An index has four disjoint lists of sizes 2, 8, 3, and 7. A query probes lists 2 and 4 with no scan cap. Compare its actual scan count with the balanced-list estimate for N=20 and nprobe=2.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Add the chosen list sizes before substituting an average list length.

Compare with the solution

The actual count is 8+7=15 entries. The balanced estimate is 20×2/4=10 entries, so it underestimates this query by 5 entries, or one third of its actual scanned count. The configuration still probes only half the lists; unequal populations explain why it scans three quarters of the stored entries.

Take it with you

  • A coarse centroid routes a query; it does not certify the nearest document.
  • Candidate work depends on selected list populations.
  • All-list IVFFlat can be exhaustive; all-list PQ retains compression error.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.