IVF Index: Clustering-Based Vector Search & Partitioning › Choosing the Number of Centroids
Language AI HandbookAll chapters IVF Index: Clustering-Based Vector Search & Partitioning › Choosing the Number of CentroidsOne section · Sections in this chapter6 / 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 number of centroids affects both the granularity of the partitioning and the overhead of the centroid comparison step. To develop intuition for what happens when is set poorly, it helps to examine the two extremes. The choice involves several considerations.
Too few centroids (e.g., for 1 million vectors):
When the number of centroids is much too small relative to the dataset size, each cell becomes enormous. Each cell contains approximately:
where:
- : the total number of vectors in the dataset
- : the number of centroids (cells)
- : the average number of vectors per cell
With such large cells, even a single probe requires scanning 100,000 vectors, which offers minimal speedup over brute force. The cell is too large to narrow the search space enough to help.
Even with (searching just one cell), you scan:
where:
- : the fraction of cells searched when , approximating the fraction of the dataset examined
- : the number of centroids in this example
The centroid comparison step requires only distance computations, which is cheap. However, the list scanning step dominates since you must compute distances to 100,000 vectors. The problem is clear: the savings from coarse filtering are negligible because the cells are too coarse to filter effectively.
Too many centroids (e.g., for 1 million vectors):
At the opposite extreme, when we create far too many centroids, the cells become tiny and the overhead of simply finding the right cells becomes a bottleneck. Each cell contains approximately:
where:
- : the total number of vectors
- : the number of centroids, an excessive number for this dataset
- : the average number of vectors per cell, too small for efficient search
With cells this small, the true nearest neighbors are likely scattered across many cells, requiring a large to reach good recall. The reason is geometric: when cells are very small, even a slight offset between the query and the nearest neighbor can place them in different cells. Additionally, comparing the query to 100,000 centroids itself becomes a bottleneck.
The centroid comparison step itself becomes expensive, and you need a very large to avoid missing nearby cells that contain true neighbors. The cost of Step 1 (finding nearest centroids) may even exceed the savings from Step 2 (scanning smaller lists) and defeat the purpose of the index entirely.

The right choice of lies between these extremes, at a point where both the centroid comparison cost and the list scanning cost are manageable. In practice, the guidelines for choosing are:
- Small datasets (): to
- Medium datasets (): to
- Large datasets ( to ): to
FAISS documentation recommends starting with between and and tuning from there based on your recall and latency requirements.