IVF Index: Clustering-Based Vector Search & Partitioning › Probe Count: The Accuracy-Speed Tradeoff
Language AI HandbookAll chapters IVF Index: Clustering-Based Vector Search & Partitioning › Probe Count: The Accuracy-Speed TradeoffOne section · Sections in this chapter3 / 12 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
The parameter is the primary knob for controlling the tradeoff between search accuracy (recall) and search speed. To build clear intuition for how this parameter works, it helps to consider the two extreme settings and then reason about what happens in between.
When , you search only the single closest cell. This is the fastest setting but also the least accurate because any nearest neighbor that happens to sit in an adjacent cell will be missed. When (all cells), you search every vector in the dataset, which is equivalent to brute-force search with perfect recall but no speed benefit.
where:
- : the number of cells (clusters) searched at query time, ranging from 1 (fastest, least accurate) to (slowest, perfect accuracy)
- : the total number of centroids (cells) in the IVF index
These extremes illustrate the basic tradeoff: interpolates between a single-cell approximation and exhaustive search. Every value in between is a different point on the accuracy-speed curve, and using IVF well means finding the right balance for your application.
In practice, you typically want values that give you high recall (say, 90-99%) while searching only a small fraction of the data. The sweet spot depends on several factors:
- How well the data clusters: If the data forms tight, well-separated clusters, even can reach high recall. If the data is uniformly distributed with no natural clusters, you need more probes.
- The number of centroids: More centroids means smaller cells, which means more probes are needed for the same recall level. But more centroids also means each cell is smaller, so each probe is cheaper.
- The dimensionality of the vectors: Higher-dimensional spaces exhibit the "curse of dimensionality," where distances become more uniform and cluster boundaries become less real, generally requiring more probes.
A useful mental model is to think of recall as a function of the fraction of data searched. If you have centroids and set , you search roughly:
where:
- : the number of centroids in this example
- : the number of cells we choose to search
- : the fraction of cells searched, which approximates the fraction of the dataset examined (exact if cells are perfectly balanced)
In practice, this often yields 80-95% recall depending on the dataset, because nearby cells tend to contain the true nearest neighbors. The reason recall is much higher than the fraction of data searched is precisely because IVF's clustering is not random: it groups similar vectors together, so the closest cells to the query are disproportionately likely to contain the nearest neighbors.
Analyzing the Computational Cost
Now that we understand the qualitative tradeoff, let us make it precise by analyzing the computational cost step by step. This analysis will reveal exactly where the savings come from and how the different parameters interact. For a dataset of vectors in dimensions partitioned into centroids, a query requires:
Step 1: Find nearest centroids
We compare the query vector to all centroids. Each comparison computes the distance between two -dimensional vectors. For Euclidean distance, this requires computing squared differences and summing them plus a square root (which we ignore in big-O notation). Therefore, this step costs:
where:
- : the number of centroids in the IVF index
- : the dimensionality of each vector (and each centroid)
- : the total number of operations needed to compare the query against all centroids
This cost is fixed regardless of dataset size . Whether you have one million or one billion vectors, comparing against centroids costs the same. This is one of the elegant properties of IVF: the coarse filtering step is completely independent of the number of data vectors.
Step 2: Scan inverted lists
We scan the vectors in the selected cells. Assuming roughly equal-sized cells, each cell contains approximately vectors. Thus, we scan vectors total. Each distance computation again requires operations, giving:
where:
- : the number of cells we search
- : the total number of vectors in the dataset
- : the total number of centroids (cells)
- : the average number of vectors per cell, assuming balanced clustering
- : the dimensionality of each vector
This is typically the dominant cost, since is usually much larger than . The key observation is that this cost scales linearly with . Doubling the number of probed cells exactly doubles the number of vectors we must examine, which is why query time grows linearly with as we observed in the experiments.
Total query cost
Combining both steps gives us the complete picture of what a single query costs:
where:
- : cost of comparing the query to all centroids (Step 1)
- : cost of scanning vectors in the selected cells (Step 2)
- : the number of centroids
- : the number of cells searched
- : the total number of vectors
- : the dimensionality of each vector
The two terms in this expression correspond to the two phases of the search. In most practical settings, the second term dominates because the number of vectors scanned in the inverted lists far exceeds the number of centroids. However, when is very large (for instance, at billion scale with tens of thousands of centroids), the first term can become significant and may itself require acceleration, for example by using an HNSW index over the centroids.
Speedup over brute-force
Brute-force search requires operations. The speedup factor compares this to IVF's cost. Since the dimensionality appears in both numerator and denominator, it cancels out:
where:
- : total number of vectors in the dataset
- : number of centroids (cells) in the IVF index
- : number of cells searched at query time
- : dimensionality of each vector, which cancels out in the speedup ratio
This speedup formula reveals several insights that are worth examining individually. First, as increases, the speedup decreases because we search more cells. This makes intuitive sense: the more of the dataset we examine, the closer we get to brute-force cost. Second, increasing (more centroids, finer partitioning) improves speedup. However, there are diminishing returns due to the term in the denominator, which grows faster than the in the numerator. Third, and perhaps most surprisingly, the dimensionality cancels out entirely, meaning the speedup is independent of vector dimension. Whether your vectors are 64-dimensional or 1024-dimensional, the fraction of vectors you avoid examining remains the same.
For typical values (say , , ), the denominator is dominated by , giving a speedup of about . This is a substantial improvement, and it scales well: doubling doubles the brute-force cost but leaves the IVF speedup ratio in effect unchanged (assuming you scale accordingly). This scaling property is what makes IVF practical at very large scales: the relative advantage over brute-force search is preserved as the dataset grows.