IVF Explained: How Inverted-File Vector Indexes Work
IVF groups vectors into lists and searches a few of them. Learn how nlist and nprobe work, how Flat, SQ, PQ, OPQ and RaBitQ differ, and what compression, rescoring and storage placement cost.

IVF, short for inverted file, groups vectors around representative points called centroids. Each centroid has a list of the vectors assigned to it. A query selects a few nearby centroids, searches their lists and leaves the rest alone. Searching fewer vectors saves work, but a skipped list can contain a true nearest neighbour.
The suffixes describe other choices: IVF-Flat keeps full vectors, IVF-PQ (also written IVF+PQ) compresses them with product quantization, and IVF with RaBitQ uses a different compressed representation. You can also change how the centroids are searched, where the lists live and how candidates are rescored.
Our HNSW explainer follows a query through a graph. Here, we will follow it into a handful of lists.
How does an IVF index work?
In a text index, a term points to a posting list of matching documents. In a vector IVF index, a centroid points to a list of vector IDs and their stored representations. The lists play the same organizational role; there are no words involved in choosing them.
Building a conventional IVF index takes three steps:
- Train. Cluster a representative sample, usually with k-means for L2 search. The requested number of clusters is
nlist. Train any learned compression codebooks too, using training residuals when the codec represents differences from centroids. - Assign the vectors. Find a centroid for each vector. The basic scheme assigns each vector to one list.
- Encode and append. Store the vector's ID and representation in that list. IVF-Flat keeps the float vector. Compressed variants keep a code; many encode the residual, the difference between the vector and its assigned centroid.
At query time, the coarse quantizer chooses nprobe lists. With an exact centroid search, these are the lists whose centroids are nearest to the query under the routing metric. The engine scores entries in those lists and keeps the best k, or a larger shortlist for refinement. Faiss's IVF tutorial walks through the train, add and search sequence.
Why probe more than one list? A centroid represents a whole cluster. The nearest individual vector can belong to the cluster next door, especially when the query sits near a boundary.
A query near a cluster boundary can miss its nearest vector when it probes only the closest centroid. Searching the second list can recover that vector. Searching all lists with full vectors and no scan cap gives an exhaustive search.
The figure uses full vectors, so it isolates the first source of error: routing loss. No amount of accurate scoring inside one list can find a vector in another list that was never opened.
What do nlist, nprobe and the other settings control?
nlist sets the partitioning at build time. nprobe sets how much of that partitioning a query visits. Increasing nlist gives smaller lists on average, but creates more centroids to train, store and search. At a fixed nprobe, it also changes how much of the collection you visit. It is not a free recall improvement.
For N vectors in equally sized lists, scanning nprobe lists visits approximately N * nprobe / nlist vectors. For example, 10 million vectors, 4,096 lists and 32 probes give about 78,125 vector evaluations, plus routing work. This is arithmetic under a balanced-list assumption, not a latency prediction. Actual work is the sum of the lengths of the selected lists. Faiss's IVF interface defines the list selection and scanning operations.
| Setting | Set at | What changes |
|---|---|---|
nlist | Build | Number of coarse clusters; changes list sizes, training and routing cost |
| Training sample and iterations | Build | How well centroids and learned codebooks represent the collection |
nprobe | Query | Number of lists selected in a conventional single IVF index |
Scan budget, such as Faiss max_codes | Query | Limits scanning work; can stop a search before it examines all selected entries |
PQ m and bits per sub-code | Build | Code length and compression error; m must divide the encoded dimension in standard equal-block PQ |
| SQ or RaBitQ bit width | Build | Precision and bytes per vector; supported widths depend on the codec |
| Refinement pool | Query | How many shortlisted candidates receive a more accurate score |
| Coarse-search effort | Query | Accuracy and work when centroids themselves use an approximate index |
Changing trained centroids requires reassigning vectors; changing a codec requires re-encoding them. These are rebuild decisions. Probe and refinement budgets are query decisions where the engine exposes them. Faiss documents its per-query controls in search parameters.
Keep the metric consistent too. L2 ranks by distance; inner product ranks by the largest dot product. Cosine can use inner product after normalizing both database and query vectors to unit length. Normalizing a maximum-inner-product workload changes its meaning when vector norms carry information. The Faiss metric reference explains these distinctions. The figures here use L2.
What is the difference between IVF-Flat, SQ, PQ, OPQ and RaBitQ?
IVF decides which lists to search. The representation inside each list decides how many bytes to read and how accurately to score them. Compression adds a second source of error: a vector can be in a searched list and still rank too low because its estimated distance is wrong. These are the main families:
| Variant | What the lists hold | What to watch |
|---|---|---|
| IVF-Flat | Full float32 vectors and IDs | Exact distances within visited lists; large payload |
| IVF-SQ | Separately quantized coordinates, commonly 4, 6 or 8 bits, or a float16 representation | Simple compression, with precision depending on coordinate ranges and format |
| IVF-PQ / IVF+PQ / IVFADC | One codebook entry per subvector, usually encoding residuals | Much shorter codes; estimated distances can reorder neighbours |
| OPQ + IVF-PQ | PQ codes after a learned transform | Extra training and transformation work to reduce PQ distortion |
| IVF-PQR / IVFADC+R | A first PQ code plus a refinement code | More accurate shortlist scoring, still compressed |
| IVF-PQ FastScan | Blocked short PQ codes, typically 4-bit sub-codes | SIMD-friendly scanning; hardware, layout and precision affect the result |
| IVF with RaBitQ | Randomized low-bit codes plus correction data | Different distance estimator; probabilistic error bounds do not guarantee exact search |
These names describe families, not a universal configuration syntax. The linked codec references below explain their implementations.
IVF-Flat and IVF-SQ
IVF-Flat is the useful starting point: keep every coordinate and calculate its full distance when its list is visited. It saves comparisons, not vector storage. If it misses a neighbour, first check list coverage and scan limits. There is no compressed distance estimate to blame. With a small collection or enough probes to visit most of it, a plain exhaustive Flat index can be simpler and faster than routing through IVF first. See the Faiss IVF-Flat tutorial.
Scalar quantization is a smaller step away from the original vectors than PQ. Integer SQ replaces each coordinate with a low-bit value drawn from a calibrated range; float16 uses a lower-precision floating-point format instead. Standard 8-bit SQ uses one byte per coordinate, so a 768-dimensional vector takes 768 bytes before its ID. Faiss's IVF scalar quantizer can encode residuals and computes approximate distances from the encoded values. Unusual coordinate ranges and outliers deserve attention when choosing the calibration data.
How PQ compresses a vector
Product quantization splits a vector into m subvectors and trains a small codebook for each position. A subvector is replaced by the ID of its closest codebook entry. At 8 bits per ID, each codebook has 256 entries. A 768-dimensional vector split into 96 groups of eight dimensions becomes a 96-byte code, versus 3,072 bytes for float32 coordinates.
For squared L2, the query builds tables of distances to the sub-codebook entries. Scoring a stored code then sums m table lookups. The query need not be compressed in the same way as the stored vectors; this is asymmetric distance computation. In residual IVF-PQ, the comparison accounts for the list centroid: approximate x as centroid + decoded residual. The original PQ paper develops this construction.
With two 1D subquantizers, a residual is represented by one selected value on each axis. Coarse codebooks move reconstructed vectors farther from their originals. More entries improve reconstruction in this nested toy codebook, at the cost of more bits.
OPQ learns a transform that makes the split into subvectors less wasteful. A square orthogonal rotation preserves L2 distances before quantization, while changing how well independent codebooks can represent the data. An OPQ pipeline that also reduces dimensions introduces another approximation. See the OPQ paper and Faiss's transform options.
PQR adds another PQ encoding of the remaining reconstruction error and uses it to refine a shortlist. It does not turn those candidates back into their original vectors. The three-level quantization paper describes this extra stage. Full-vector rescoring is a separate option, and needs access to the retained vectors.
FastScan changes how short codes and lookup tables are arranged and processed so SIMD instructions can score many candidates efficiently. Four-bit codebooks fit the small in-register tables used by the Faiss implementation. Smaller codebooks and quantized lookup tables affect accuracy, so a faster scanner should still be measured at the required recall. See Faiss's FastScan notes.
RaBitQ uses randomized quantization rather than PQ's learned sub-codebooks. Its original form represents a normalized, rotated vector with one bit per dimension and stores additional factors for estimating distances. Used with IVF, it can encode residuals around centroids. A 768-dimensional one-bit code has 96 bytes of bit payload; correction data and IDs are extra. The RaBitQ paper derives probabilistic error bounds for its estimator, and the extended method spends more bits for greater accuracy. Neither result removes IVF routing loss.
There are other codecs. Faiss also supports IVF with additive quantizers, including residual and local-search quantization. These approximate a vector by adding codewords, with different training, encoding and distance-computation costs. Binary IVF instead searches packed binary vectors with Hamming distance; it is a different input and metric, not another name for running cosine search on RaBitQ codes.
Some options sit inside a codec. Residual versus direct encoding chooses whether to compress x - centroid or x; it changes training and scoring, not which list owns the vector. Query quantization spends fewer bits on the query during scanning, independently of the stored-code precision; WarpSearch exposes this as RaBitQ query_bits. Fast SIMD scanning is not exclusive to PQ: Faiss also offers RaBitQ FastScan. Polysemous PQ codes use a Hamming-distance prefilter before the more expensive PQ distance estimate. That can skip work, but its threshold can also discard useful candidates; see the polysemous codes paper.
What can rescoring fix?
Suppose you need ten neighbours. A compressed scan can retain 100 candidates, fetch their original vectors and return the best ten using exact distances. That can correct the ordering of those 100 candidates. It cannot recover a neighbour that fell outside the shortlist, or one whose list was skipped entirely.
The next figure separates those failures. Start with one list and one candidate. Raise the candidate budget to fix a compression miss; then open the second list to find the globally nearest vector.
| Search | Exact rescoring returns | Why it can miss |
|---|---|---|
| List 1, one candidate | B, distance 0.30 | A lost to an inaccurate estimate; C was not scanned |
| List 1, two candidates | A, distance 0.20 | C remains in the unopened list |
| Both lists, two candidates | C, distance 0.10 | The shortlist now contains the true nearest vector |
For IVF-Flat, visiting every list and scanning every entry gives an exhaustive search over the stored vectors. For IVF-PQ or RaBitQ, visiting every list still leaves compressed scoring and shortlist selection in the path. Use an exact scan when you need exact neighbours. Faiss's accuracy troubleshooting makes the same distinction: test IVF-Flat to isolate routing error, then exhaustive IVF-PQ to isolate compression error.
How much memory and storage does IVF need?
Separate the list payload from the rest of the index. With N vectors of dimension d, float32 centroids require 4 * d * nlist bytes. The list payload depends on the codec. Using 8-byte IDs, the following are calculated examples for 100 million 768-dimensional vectors:
| Representation | Bytes per vector, including ID | List payload |
|---|---|---|
| IVF-Flat | 3,080 | 308 GB |
| IVF-SQ8 | 776 | 77.6 GB |
| IVF-PQ, 96 × 8-bit sub-codes | 104 | 10.4 GB |
| One-bit codes, before correction data | 104 | 10.4 GB |
For the default example, 4,096 centroids add only about 12.6 MB. But retaining every original vector for rescoring adds another 307.2 GB to a compressed index. Compression makes the scanning representation small; it does not make the originals disappear. They can live on cheaper storage, with their fetch cost paid during refinement. The Flat, SQ and PQ formulas follow the Faiss storage table; the one-bit row deliberately omits codec-specific correction data.
PQ has a second memory bill: lookup and precomputed tables. For 8-bit residual L2 PQ, an optional Faiss precomputed table can contain 256 * nlist * m float entries. At 4,096 lists and m = 96, that is roughly 403 MB. It is shared, not per vector, and is not included above. The implementation notes explain when these tables are used.
Can IVF use HNSW, a multi-index, GPUs or disk?
Yes. These change different parts of the index, and several can be combined.
| Option | What changes | What stays the same |
|---|---|---|
| Flat centroid search | Compare the query with every centroid | Scan the selected inverted lists |
| HNSW over centroids | Use a graph to find promising centroids | The data vectors still live in lists; codec choice is separate |
| Inverted multi-index (IMI) | Form coarse cells from combinations of subspace centroids | Probe cells, then score their entries |
| On-disk IVF | Keep list contents on storage, with routing and metadata available in memory | Recall still depends on the lists and candidates examined |
| GPU IVF | Train, route or scan using GPU kernels | Placement and supported codecs depend on the implementation |
An HNSW coarse quantizer puts a graph over the centroids, not necessarily over every database vector. That can reduce routing work for a large nlist, but an approximate centroid search can miss useful lists. Its search effort needs tuning alongside nprobe. Faiss supports these compositions through its index factory.
The inverted multi-index uses a product quantizer for coarse partitioning. Two subspaces with 256 centroids each define 65,536 possible cells without learning 65,536 independent full-dimensional centroids. Some cells may be empty and others large. This is distinct from IVF-PQ: IMI changes the routing partition; PQ inside a list changes the stored representation.
Lists are convenient for storage because their entries can be laid out contiguously. Faiss's on-disk IVF uses memory-mapped inverted lists. An engine can also fetch list ranges from object storage through a cache. Neither arrangement makes a cold read free. List size, request count, cache hit rate and full-vector refinement reads all affect latency.
The Faiss GPU documentation describes GPU implementations of IVF-Flat, IVF-SQ and IVF-PQ. GPU memory capacity, host-device transfers and batching can matter as much as the index settings. A fast kernel cannot compensate for a workload that spends most of its time moving data.
Where does IVF struggle, and how should you tune it?
Unrepresentative training data and drift. A new language, customer population or embedding model can leave old centroids poorly placed. Lists become uneven, or queries need more probes to find their neighbours. Monitor list sizes and recall on recent queries. Retraining means rebuilding assignments and, where applicable, learned codes. See Faiss's training guidance.
Selective filters. Filtering the final top ten can leave two results even when thousands of eligible documents exist. Apply eligibility during candidate selection where supported, and measure recall against an exact search with the same filter. A matching neighbour may sit in a list that was not probed. Very small eligible sets can be cheaper to scan exactly. Faiss exposes ID selectors; an engine's filter execution strategy determines the actual savings.
Updates and deletes. IVF has no per-vector graph edges to repair, but it still needs to remove or mask old entries, reclaim storage and assign replacements. Direct maps, tombstones and segment merges are implementation choices with their own costs. Faiss's special operations describe the direct-map and deletion options in that implementation.
Start tuning with an exact ground-truth set, the production metric and representative filters. Recall@k is the fraction of the exact top-k neighbours that the approximate search returns, usually averaged across test queries. Then work in this order:
- Measure routing alone with IVF-Flat. Sweep
nprobeat a fixednlist. If recall is poor, changing the compression codec will not repair those missed lists. - Add compression. Compare SQ, PQ, OPQ or RaBitQ at the bytes you can afford. Hold routing effort steady to see what the codec costs in recall.
- Sweep the refinement pool. More candidates can repair shortlist loss, provided the useful vectors were scanned. Include original-vector reads in the timing.
- Measure the storage workload. Record scanned entries and bytes, cold and warm latency, tail latency and build cost. Equal probe counts do not mean equal work across indexes.
WarpSearch's approximate vector index uses IVF per segment, with RaBitQ by default and PQ available explicitly. It rescores selected candidates against stored vectors, while small segments use exact scans. The compact list representation suits a serverless engine where keeping every index resident in RAM would be expensive.
One API detail matters: WarpSearch's ivf.nprobe expresses probe effort relative to a single index with sqrt(live vectors) lists, distributed across segments. It is not a literal count of lists across the whole collection. num_candidates controls the requested refinement pool, subject to documented limits and minimums. Use exact: true for ground truth; probing all lists still leaves quantized candidate selection in the approximate path.
IVF is useful when selecting a few lists saves more work than routing and refinement cost. Choose the partitioning first, measure what compression loses, then spend probes and refinement reads where they recover recall. The setting to keep is the one that meets your recall target on your data within the latency and storage budget you actually have.
The next post, e-means: k-means in a Tenth of the Passes, and Why IVF Search Should Care, examines how cheaper centroid training could improve that build budget. Then The Next Generation of Vector Search Won't Fit in RAM brings the pieces together for billion-scale search and storage costs.