14/36
Part 2 of 5 · Stages and retrievalLearn and do

IVF scans only the clusters nearest the query

The second design skips the graph and sorts the vectors into clusters instead.

IVF groups the vectors into clusters, and scans only the nearest
clusters
cluster 1cluster 2cluster 3cluster 4

The query lands between clusters 2 and 3, so only those two are scanned. 1 and 4 are skipped.

IVF (inverted file) groups the vectors into clusters with k-means. At query time it scans only the vectors in the few clusters whose centers sit nearest the query.

How many clusters it probes is the dial between speed and recall. The Faiss paper says most indexes have settings like this, chosen at search time, that trade speed against accuracy. IVF misses a true neighbor when that neighbor's cluster isn't one of the ones probed.

In the editor, write probe(query, nprobe), the clusters a search scans, and ivf_nearest(query, nprobe), the nearest vector inside them. The stub holds a tiny index: 4 cluster centers, 7 vectors in vecs, and assign, each vector's cluster. The query (5.2, 0) sits nearest cluster 1, but its true neighbor, vector 4 at (4.9, 0.2), is in cluster 0.