RAG and vector searchLoading progress…

Probing and candidate counts

Trace IVF and HNSW search and explain how candidate exploration trades latency for recall.

Probing and candidate counts

nprobe sets how many lists are visited. A higher value scans more candidates and usually raises recall, up to the exact result when every list is probed. But cost depends on the sizes of the probed lists, not on their count: if lists are skewed, two big lists can hold most of the corpus.

k (neighbours wanted)2
nprobecandidates scannedfraction of corpusreturned idsrecall@2
130.33, 40.5
260.62, 31
31012, 31

True top-2 for q = 5.1: ids 2, 3. More probes means more work and (usually) more recall.

list sizes: 250, 250, 250, 250 probing the two nearest lists (order 0 then 3) scans 500 of 1000 vectors the same nprobe costs different work depending on which lists are probed
Same query, increasing nprobe; then compare even and skewed lists.

Predict first. Does an equal number of lists imply equal actual list sizes?

Chapter context

An approximate index organizes vectors so a query can avoid most comparisons. Clustering and graph navigation use different mechanisms to choose candidates, and their build settings influence later search quality.

Chapter reference: math, worked example & code

This section belongs to the whole chapter, so it is the same on every lesson in it and may cover a different lesson's topic. The code for the experiment you just ran is inside the experiment itself.

Math and notation

Under the simplifying assumption of equally sized IVF lists, N vectors, C cells and p probes produce approximately

Ncandidates≈Np/C.N_{candidates}\approx Np/C.

Add coarse scoring, uneven list sizes and any reranking costs separately. HNSW has no equivalent universal fixed candidate-count formula.

Worked example

For 102,400 vectors evenly divided among 1024 cells, a cell has 100 vectors. Probing eight cells scans about 800 candidates, compared with 102,400 in a full scan. This excludes coarse-centroid comparisons and says nothing by itself about recall.

Reference code

The following example uses the Python standard library and does not call a remote service.

total,cells,probes=102400,1024,8
assert total/cells == 100
assert total*probes/cells == 800
assert total/(total*probes/cells) == 128

Python examples are provided for study and local execution; this page does not execute Python.

Common mistakes

An average candidate count is not an actual worst-case bound. More graph edges consume memory. Approximate search settings must be evaluated against the current corpus and metric.