IVFPQ Explained: How IVF-PQ Trades Recall for Memory and Speed

IVFPQ explained: how nlist, nprobe, m and nbits trade recall for memory and speed, when HNSW fits better, and when drift calls for a rebuild.

IVFPQ Explained: How IVF-PQ Trades Recall for Memory and Speed
Written by TechnoLynx Published on 11 Jul 2026

IVF-PQ (written IVFPQ in Faiss index names) is an approximate nearest-neighbour index built from two lossy steps. An inverted file clusters the vectors so that a query only scans a few clusters, and product quantisation stores each vector as a short code instead of full-precision floats. The first step buys speed by skipping most of the database, the second buys memory by shrinking what is left, and both cost recall. Four parameters control that trade: nlist, nprobe, m and nbits. It does not stay fixed after the build either. When the indexed data shifts, the clusters and codes fitted at training time stop matching it, and search quality degrades unless the index is updated.

What Is IVF-PQ, and How Does It Work Inside a Vector Database?

IVF-PQ lets a vector database search a collection too large to hold uncompressed in RAM or GPU memory. It does this by pruning the search to a few clusters and scoring compressed codes inside them. The Faiss library describes itself as a toolkit for searching, clustering, compressing and transforming vectors, which is the core of a vector database. Its index table lists IndexIVFPQ under the description “coarse quantizer + PQ on residuals”. The Faiss wiki calls IndexIVFPQ probably the most useful indexing structure for large-scale search. OpenSearch exposes product quantisation through its Faiss engine, paired with either IVF or HNSW.

Size is where IVF-PQ earns its place. NVIDIA’s cuVS team reports a billion-record, 96-dimension fp32 dataset of 360 GiB compressed by a typical IVF-PQ configuration into a 54 GiB index, small enough to fit in GPU memory, with no significant impact on search performance. If you want the partitioning half on its own, as used in a robotics retrieval stack, our explainer on the inverted file index covers it in depth.

How Is the IVF Partitioning Step Different from the PQ Compression Step?

The IVF step decides which vectors a query looks at, and the PQ step decides how precisely each of those vectors is stored. They lose recall in different ways, as the table shows.

  IVF (inverted file) step PQ (product quantisation) step
What it does k-means clusters the database into nlist cells; each vector is filed under its nearest centroid Splits each residual vector into m sub-vectors and replaces each with the index of its nearest sub-centroid
What it saves Distance computations: only about nprobe/nlist of the data is scanned Memory: a vector costs m × log2(k*) bits instead of 32 bits per dimension
How it loses recall A true neighbour in a cell the query never probes is missed Distances are estimated from codes, so even an exhaustive probe never reaches perfect recall
Search-time knob nprobe, set at query time m and nbits, set when the index is constructed
What drift does to it Cells go lopsided and drift away from their centroids Codebook quality decays as the data changes

The two steps meet at the residual. IVF-PQ does not quantise the raw vector. It quantises the vector’s offset from its cell centroid, so PQ only has to describe fine detail that the centroid has not already captured. The Faiss authors report that residual encoding is generally more accurate and helps most for shorter codes. It is on by default through the by_residual flag. Jégou et al. learn one product quantiser on residuals pooled from all cells rather than one per cell, because storing a codebook for every cell would be memory-intractable.

What Does Product Quantisation Do to a Vector, and What Is a PQ Code?

Product quantisation turns a D-dimensional float vector into m small integers. It does this by cutting the vector into m sub-vectors of D/m dimensions and quantising each one separately against its own codebook. The PQ code is the list of those m sub-centroid indices. If each sub-quantiser has k* centroids, the code takes m × log2(k) bits. With m = 8 and k = 256 (8 bits per sub-quantiser), which Jégou et al. call a reasonable choice, that comes to 64 bits per vector.

The trick is that m small codebooks represent (k)^m possible reconstructions while storing only m × k centroids. That is why PQ needs memory several orders of magnitude smaller than a single vector quantiser of the same resolution. The Faiss authors note that plain k-means becomes impractical beyond roughly 3-byte codes, or 16 million centroids.

How Does IVF-PQ Work in Practice, from Query to Result?

At query time IVF-PQ never decompresses the stored vectors. It scores them through lookup tables in a fixed sequence of steps.

  1. Coarse assignment. The query is compared with the nlist centroids, and the nprobe nearest cells are selected.
  2. Residual per cell. For each selected cell, the query’s offset from that cell’s centroid is computed.
  3. Lookup tables. For each probed cell, distances from the query’s sub-vectors to all k* sub-centroids are precomputed, costing nprobe × d × k* FLOPs per query.
  4. Asymmetric distance scan. Each stored code is scored by summing m table entries. That replaces an O(D) distance with an O(m) one.
  5. Sort. Candidates are ranked by the estimated distance, and the top k are returned.
  6. Optional re-rank. A larger shortlist is rescored with exact distances against full-precision vectors.

Step 4 is called asymmetric because the query stays unquantised and only the database side is encoded. This gives lower distance distortion than encoding both sides, at similar cost, which is why IVFADC uses it and most Faiss indexes default to it.

Step 6 recovers recall lost to the compression. In NVIDIA’s cuVS tuning experiments, re-ranking twice as many candidates as requested reached 0.99 recall at roughly a 25% cost in queries per second. On the Faiss SIFT1M and Deep1M benchmarks, the most effective methods included a refinement stage.

How Do Nlist, Nprobe, M and Nbits Trade Recall Against Latency and Memory?

Two of the parameters control the IVF step and two control the PQ step. The Faiss authors describe search-time hyperparameters such as nprobe as monotonic: a higher value is slower and more accurate. So the useful question is never “what recall does IVF-PQ give” but “what recall at which settings”. A recall figure without its parameters tells you nothing.

Nlist and Nprobe: How Much of the Database Each Query Sees

nlist is the number of cells. More cells give a finer partition but take longer to train. pgvector’s guidance for its IVF index puts the cell count at rows ÷ 1,000 below a million rows and at the square root of the row count above that, with the probe count starting at the square root of the cell count. The Faiss authors list three reasons the cost model behind these rules is only a rough approximation: nprobe has to grow with nlist to hold accuracy, inverted lists are not balanced, and the coarse quantiser is often not exhaustive itself.

nprobe is the number of cells a query scans. The fraction of the database touched is roughly nprobe/nlist, and that estimate usually runs low because list lengths are uneven. Faiss’s GPU IVFPQ class defaults nprobe to 1. A 2019 GPU benchmark paper calls 64 a typical value in Faiss.

Jégou et al.’s original IVFADC table shows the shape of the trade. On SIFT with 1,024 cells, recall@100 rose from 0.308 at one probed cell (1.5 ms) to 0.682 at eight (8.8 ms) and 0.744 at sixty-four (65.9 ms). The same paper warns that a longer code is wasted if too few cells are probed, because neighbours outside the probed cells are lost regardless of code quality.

M and Nbits: How Precisely Each Vector Is Stored

m is the number of sub-quantisers and nbits the bits per sub-code. Together they set the code size, which Faiss gives as ceil(m × nbits / 8) bytes plus 8 bytes for the vector ID. The embedding dimension must be divisible by m.

Jégou et al. and the Faiss authors agree on how to spend a fixed bit budget: use fewer sub-quantisers with more centroids each, not many sub-quantisers with few bits. OpenSearch recommends fixing code_size (nbits) at 8 and tuning m to trade memory against recall. NVIDIA suggests starting pq_dim (its name for m) at a quarter of the feature count and increasing it in steps. Dropping nbits from 8 to 4 halves the index size. It also shrinks the lookup table, which grows with 2^nbits, and NVIDIA notes this has a drastic effect on recall.

In AWS’s billion-vector OpenSearch benchmark, increasing m improved IVFPQ recall the most. Raising nprobes improved recall only marginally and increased latency significantly. That fits a structural limit: for a fixed PQ configuration, recall plateaus once quantisation error rather than cell coverage becomes the binding constraint. When raising nprobe stops helping, the next lever is code size or re-ranking, not more probes.

One overhead is easy to miss. Faiss can precompute tables to speed up query preprocessing, and those tables take 256 × nlist × m entries. Faiss only uses them if they fit under a memory threshold.

How Much Memory Does IVF-PQ Save per Million Vectors?

Per vector, a flat float32 index stores 4 × d bytes, while IVF-PQ stores ceil(m × nbits / 8) + 8 bytes. Centroids and codebooks add a fixed cost on top that does not grow with the vector count.

Worked Example: One Million 768-Dimensional Embeddings

These are the assumptions of this example, not a recommendation.

Component Formula Size
IVF-PQ codes + IDs (64 × 8 / 8 + 8) bytes × 1M ≈ 72 MB
Coarse centroids 4 × 4096 × 768 bytes ≈ 12.6 MB
PQ codebook 2^8 × 4 × 768 bytes ≈ 0.79 MB

The code-size formula comes from the Faiss index table, and the centroid and codebook terms follow the OpenSearch memory estimate. OpenSearch’s formula charges 24 bytes of per-vector overhead rather than Faiss’s 8 and adds a 1.1 multiplier, so engine overhead changes the absolute figure. AWS used that formula to estimate a billion 128-dimensional vectors at 70 GB with two copies as IVFPQ (m = 8, code_size = 8, nlist = 4096), against roughly 1,126 GB as plain IVF.

Measured indexes do not always show savings that large. In the 2025 GovScape system’s Faiss comparison, IVFPQ came to 1,588 MB at 0.9829 recall@10, flat to 2,933 MB at exact recall, and HNSW to 3,062 MB at 0.9998. Since IDs, centroids and engine overhead count against the total, measure the index you actually built rather than the arithmetic.

Re-ranking can also quietly undo the saving if the raw vectors stay in RAM. In the IVF-TQ authors’ SIFT-1M measurement, a 4-bit index plus re-rank needed about 569 MB once the raw float32 vectors were included, against 111 MB for a 6-bit index with the same recall and no re-rank. The storage bill depends on where the full-precision copies live, not only on the code size. In one binary-quantisation HNSW example, keeping them outside RAM let a re-rank bring top-10 recall back above 95% with far less memory.

How Do You Build and Query an IVF-PQ Index in Python with FAISS?

In Python, FAISS builds an IVF-PQ index in four calls: create a flat coarse quantiser, wrap it in IndexIVFPQ with nlist, m and nbits, train on a representative sample, then add the vectors. nprobe is set at query time.

import numpy as np
import faiss

d, nlist, m, nbits = 768, 4096, 64, 8      # d must be divisible by m

xb = np.load("corpus.npy").astype("float32")    # database vectors (N, d)
xq = np.load("queries.npy").astype("float32")   # held-out queries

# Train on a representative sample of the data you will actually index
sample = xb[np.random.choice(len(xb), size=min(len(xb), 1_000_000), replace=False)]

coarse = faiss.IndexFlatL2(d)
index = faiss.IndexIVFPQ(coarse, d, nlist, m, nbits)
index.train(sample)
index.add(xb)

# Ground truth from exact search, used to measure recall
flat = faiss.IndexFlatL2(d)
flat.add(xb)
_, gt = flat.search(xq, 10)

for nprobe in (1, 8, 32, 64, 128):
    index.nprobe = nprobe
    _, I = index.search(xq, 10)
    recall = np.mean([len(set(I[i]) & set(gt[i])) / 10 for i in range(len(xq))])
    print(nprobe, round(recall, 4))

Training-set size scales with nlist. OpenSearch recommends max(1000 × nlist, 2^code_size × 1000) training vectors for IVF-based indexes. AWS applied Faiss’s training-set guidance to get 122,880 to 1,048,576 vectors for nlist = 4096.

The same index can be declared as a factory string. The Faiss authors give PCA160,IVF20000_HNSW,PQ20x10,RFlat as an example: PCA to 160 dimensions, 20,000 cells with an HNSW coarse quantiser, a 20 × 10-bit product quantiser, and exact re-ranking. An HNSW coarse quantiser is worth considering at large nlist, because it makes coarse assignment cheap. The loop above measures recall against exact-search ground truth at each nprobe, since a recall figure means nothing without its parameters; latency under load is covered under serving performance.

IVF-PQ vs HNSW: Which Index Fits Your Memory Budget?

HNSW is the better index when RAM is plentiful or the dataset is small. IVF-PQ is the one to use when memory is the hard constraint. AWS’s billion-scale benchmark found that the HNSW cluster gave lower latency and better recall, while the IVFPQ indexes used significantly less memory. The Faiss authors put it more sharply: beyond 10 million vectors, graph construction time typically becomes the limiting factor, and where compression is needed just to fit the vectors in memory, IVF indexes are the only option.

Condition Lean towards Why
Vectors fit in RAM with room to spare, high recall target HNSW Fast and accurate; memory is (d × 4 + M × 2 × 4) bytes per vector
Full-precision vectors do not fit in RAM or GPU memory IVF-PQ, ideally with re-rank Compression is required to fit; IVF is the only option at that point
No training step possible HNSW HNSW needs no training; IVF and PQ both must be trained first
Frequent deletes or updates Not Faiss HNSW HNSW in Faiss does not support removing vectors
Low-accuracy, high-throughput regime Fast-scan PQ variants Best trade-off at low accuracy on Faiss’s 1M benchmarks, with HNSW best at high accuracy

GovScape’s measurements show the price of the switch: IVFPQ used about half of HNSW’s memory and gave up about 1.7 points of recall@10 (0.9829 against 0.9998).

How Does Query-Distribution Drift Degrade IVF-PQ Recall After Deployment, and What Should the Drift Monitor Watch?

Drift degrades an IVF index in two ways. Cells become imbalanced, so queries scan more vectors for the same recall. Vectors also sit further from their centroids, so queries must scan more partitions to reach a target recall. The Faiss authors state that any technique fitted to a data distribution degrades when that distribution changes significantly, and that this includes both IVF and PQ. The DeDrift authors (2023) found the IVF partition, not the vector codec, to be the vulnerable part: codecs were relatively robust to natural content drift, and IVF structures were not. If you need to separate data drift from model drift first, our piece on types of drift covers the definitions and monitoring design.

Faiss defines an imbalance factor, the relative variance of inverted-list sizes, and the expected number of distance computations is multiplied by it.

Drift is not the only cause. In an IVF-TQ preprint (2026), IVF-PQ still lost about 3.9 points of recall on SIFT-1M under shuffled, same-distribution ingestion. The same authors found that at higher PQ bit budgets a stale codebook gained recall under streaming instead.

Centroid Update, Codebook Retrain or Full Rebuild

Choose the repair by which layer has gone stale and how much you can afford to re-add.

  • Update the coarse centroids. DeDrift’s lazy variant recomputes each centroid from the vectors already assigned to it without reassigning them. On YFCC it improved recall by 5.4% and 1.3% at two compute budgets and was about two orders of magnitude cheaper than reconstruction. A single update step worked best; more iterations moved centroids away from the stored vectors and degraded recall. For an index with OPQ-compressed vectors, the efficiency gain fell to 3× to 10×, because the update reloaded original data from disk.
  • Retrain the PQ codebook. In the IVF-TQ streaming experiments, retraining and re-encoding the codebook every batch on Deep-10M cost 309 seconds of cumulative compute and still lost 3.22 points, against 3.37 for the stale index. When the embedding model itself was swapped, though, the stale index collapsed to 51.6% recall@10, and retraining recovered 21 points.
  • Rebuild the index. DeDrift calls a full rebuild the optimal update by definition, but it re-adds all N vectors and disrupts dependent services. Ada-IVF’s authors (2024) report rebuilds taking days at billion scale. Their maintenance scheme triggers a rebuild when the observed reconstruction error drifts far enough from an estimate of what a fresh k-means would achieve.

The sources disagree on one point. The IVF-TQ authors argue that refreshing the coarse partition without retraining the PQ codebook invalidates the stored residual codes and needs a full re-encode. DeDrift measured lazy centroid updates improving residual-encoded indexes. We weigh DeDrift’s direct measurement more heavily, with one caveat: test a centroid update on a held-out query set before rolling it out. DeDrift found residual encoding more sensitive to content drift.

Is It the Index or the Embedding Model?

An IVF-PQ recall drop points to a retrieval problem when exact search over the same embeddings still returns the expected neighbours and the approximate index does not. If exact search also returns poor matches, the index is not the cause. That one comparison tells you whether to retune or rebuild the index or to retrain the embedder. The exception is a deliberate embedder change, which collapsed a stale IVF-PQ index to about 51% recall in the IVF-TQ authors’ harshest encoder-swap test.

What a Reliability Audit and Drift Monitor Should Measure

A retriever is part of the production AI infrastructure it serves. The discipline that catches silent regressions there (eval harnesses, regression suites, drift detection) applies to the index as much as to the model. A production AI reliability audit should put the retrieval layer in its eval-coverage map and drift-monitor inventory, measuring at least these:

  • recall@k against an exact-search baseline on a fixed held-out query set, recorded with nprobe, m, nbits and any re-rank factor;
  • p95 retrieval latency at the deployed nprobe, tracked alongside recall, since nprobe moves both;
  • index memory per million vectors, including IDs, centroids and any raw vectors kept for re-ranking;
  • the spread of inverted-list sizes (the imbalance factor);
  • average distance from vectors to their assigned centroid, the reconstruction error Ada-IVF uses as its maintenance signal;
  • the share of the corpus modified since the last rebuild, which the Ada-IVF paper used as a rebuild trigger at 2.5%.

Turning these signals into alerts and owners is the job of a production AI monitoring harness. The recall threshold itself belongs in the release-readiness decision for any feature that depends on the retriever.

FAQ

What Does IVF Stand For?

IVF stands for inverted file. It is an index whose keys are cluster centroids and whose lists hold the vectors assigned to each cluster, so a search reads only a few lists.

What Is a Faiss Index?

A Faiss index is one of the indexing structures in Meta’s Faiss library for vector similarity search, such as flat (exact), IVF, IVFPQ or HNSW. Each approximate index trades search time, memory and accuracy through its own parameters.

Which Vector Index Is the Fastest?

None is fastest at every setting, because recall, latency and memory trade against each other through each index’s parameters. A speed comparison only means something at a stated recall target.