IVF vs HNSW on 200k Vectors: Speed, Build, Memory, Deletes
Updated: Nov 16
Short answer. I ran IVF-Flat (faiss, 1,024 lists) and HNSW (hnswlib, M=16) on the same 200,000 vectors, one thread, one machine. HNSW searched faster at every recall level I could compare: 3,729 queries per second against 1,594 at about 0.99 recall@10, which is 2.3 times as fast. IVF built faster, about 5 times on one thread (10.4 s against 50.3 s) and 2 times on four threads (7.5 s against 15.7 s). It also stored each vector in fewer bytes (520 against 661), and coped with new data and deletes more simply. If the index fits in RAM and your data mostly grows, HNSW is my default. If build time, memory or heavy churn is the problem, look at IVF first. Either way, measure recall on your own data before you commit.

What these two indexes do
Both are approximate nearest-neighbour indexes. They skip most of the data and accept that some true neighbours will be missed.
IVF (inverted file) runs k-means once to split the vectors into nlist cells, each with a list of its vectors. A search compares the query with all nlist centroids, then scans only the nprobe closest lists. The cost is roughly:
distance computations = nlist + nprobe x N / nlistOn my data (1,024 lists, 64 probed) the formula gives 13,524 and I measured 14,373, about 6% more, because real lists are not equal in size.
HNSW (hierarchical navigable small world) builds a graph in which every vector links to about M neighbours. Each new vector draws a random top layer, so most nodes live only on the bottom layer. Inserting a vector is itself a search, efConstruction wide, followed by choosing which neighbours to link. Querying walks the graph greedily with a beam of width efSearch. In a simplified 2-D model of the linking rule (an illustration, not hnswlib's code), plain closest-M linking left the graph disconnected in all of 30 random insertion orders, while HNSW's diversity rule kept it connected in all of them with about 27% fewer edges (147 against 202 on average).
How I ran the comparison
Data: the first 200,000 base vectors of SIFT1M (128-dimensional image descriptors, L2 distance) and the first 1,000 of the 10,000 official test queries. These are image features, not text embeddings.
Ground truth and metric: exact top 10 from a brute-force flat index. Recall@10 is the share of that exact top 10 the index returns.
Software and settings: faiss-cpu 1.15.1 for IVF-Flat (1,024 lists, nprobe 1 to 128) and hnswlib 0.8.0 for HNSW (M=16, efConstruction 100, efSearch 16 to 256).
Timing: one thread, best of 2 to 3 passes over the 1,000 queries, seed 42. I ran the whole benchmark twice and report the second, clean run. Recall and memory matched between runs. Timings moved by 10 to 30%, and I flag where that matters below.
Machine: a 4 vCPU AMD EPYC virtual machine with 7.6 GB of RAM. The clean run started with the machine nearly idle (load average 1.3). An earlier run started under heavy load and gave noisier timings.
Search speed at matched recall
The two indexes use different dials, so no two settings give identical recall. Each row pairs an IVF setting with the nearest HNSW setting whose recall is equal or higher.
Settings (IVF vs HNSW) | Recall@10 (IVF / HNSW) | Queries per second (IVF / HNSW) | HNSW speed ratio |
nprobe 8 vs efSearch 16 | 0.7836 / 0.8466 | 11,254 / 19,743 | 1.8x |
nprobe 16 vs efSearch 32 | 0.8970 / 0.9330 | 6,300 / 10,700 | 1.7x |
nprobe 32 vs efSearch 64 | 0.9658 / 0.9769 | 3,067 / 7,267 | 2.4x |
nprobe 64 vs efSearch 128 | 0.9940 / 0.9942 | 1,594 / 3,729 | 2.3x |
In every row HNSW has both the higher recall and the higher speed. I also compared the HNSW curve, by interpolation, with my 256-list, 1,024-list and 4,096-list IVF sweeps. HNSW was ahead at all 9 IVF points that fall inside the range it covered (recall 0.8466 to 0.9989). I did not run HNSW below 0.85 recall, so I claim nothing there.
For an outside reference, the FAISS wiki's SIFT1M benchmark (20 threads) reports about 0.020 ms per query for HNSW against about 0.14 ms for IVFFlat at recall@1 above 0.9. That is a third-party number on different hardware and thread count, so I treat it as direction only.
The IVF dial is steep. At nprobe 1 with 1,024 lists, recall@10 was 0.3095, because for 61.0% of queries the true nearest neighbour sat in a different cell from the query's nearest centroid. Moving from 0.90 to 0.99 recall (nprobe 16 to 64) cut throughput from 6,300 to 1,594 queries per second, a factor of about 4. The HNSW dials flatten out instead: raising efConstruction from 100 to 200 added 0.0034 recall@10 at efSearch 64 (0.9769 to 0.9803) and raised single-thread build time from 50.3 s to 85.3 s.

Build time and memory
Measure | IVF-Flat, 1,024 lists | HNSW, M=16, efConstruction 100 |
Build, 1 thread | 10.4 s (train 9.38 s, add 1.02 s) | 50.3 s |
Build, 4 threads | 7.53 s | 15.7 s |
Bytes per vector | 520 (128 x 4, plus 8 for the id) | 661 (index file of 132,106,944 bytes / 200,000) |
Queries/s at about 0.99 recall | 1,594 (recall 0.9940) | 3,729 (recall 0.9942) |
Mean time to add one vector | 0.025 ms | 0.362 ms |
HNSW cost about 5 times the build time on one thread (about 2 times on four) and about 27% more memory at 128 dimensions. Adding one vector took about 15 times as long as appending it to an IVF list, though both stayed under a millisecond. The insert timing is the median of 3 repeats of 1,000 single-vector adds.
Two caveats. IVF must see data before it can be built, because its centroids come from the data, while HNSW can start empty. And the memory gap shrinks with longer vectors. By the FAISS formula the M=16 links add 128 bytes per vector, which is 25% on top of a 128-dimensional vector but about 4% on top of a 768-dimensional one. That second figure is arithmetic, not something I measured.
What happens when data changes
New data that looks different (IVF drift)
IVF centroids are frozen at training time. To see the cost, I sorted the 200,000 vectors along their first principal component, trained IVF on the lower half, then added the upper half without retraining. This is a manufactured shift, not natural drift.
Measure (1,024 lists, nprobe 8) | Trained on half, then fed the rest | Retrained on all 200,000 |
Largest list | 7,657 | 598 |
Vectors scanned per query | 11,086 | 1,756 |
Recall@10 | 0.841 | 0.784 |
Queries/s | 2,352 | 12,123 |
The retrained column is a separate build and timing pass inside the drift experiment. Its 12,123 queries per second sits about 8% above the 11,254 in the speed table for the same settings, which I read as run-to-run timing noise.
Drift did not show up as worse answers. Recall at fixed nprobe went up, because a few huge lists were scanned. The price was speed: 6.3 times as many vectors scanned and 5.2 times fewer queries per second. If you only monitor recall, you would miss it. Retraining took 7.0 s on 4 threads.
One honest note. In my first run the largest stale list was 16,558, not 7,657. The size of the biggest list depends on where k-means starts, so treat it as "several thousand, against a few hundred when retrained". The scanned-per-query ratio and the recall pattern held in both runs.
Deletes in HNSW
HNSW nodes are also roads that other searches use, so most implementations mark a node as deleted instead of removing it. I tested hnswlib's mark_deleted (M=16, efConstruction 200, efSearch 64) and compared it with a fresh rebuild of the remaining vectors.
Measure | 10% deleted | 30% deleted | 50% deleted |
Recall@10, marked deleted | 0.9827 | 0.9882 | 0.9932 |
Recall@10, fresh rebuild | 0.9817 | 0.9846 | 0.9879 |
Queries/s, marked deleted | 5,396 | 3,997 | 3,414 |
Queries/s, fresh rebuild | 5,328 | 6,378 | 6,247 |

Recall did not drop. Speed did once a large share was deleted: at 50% deleted the tombstoned graph ran at 55% of the rebuilt index's throughput, and at 30% at 63%. At 10% I saw no difference. My first run gave a different ratio at 10% and 50% (0.84 and 0.43), so read this as "roughly half speed at half deleted", not as a precise curve.
I also tried replace_deleted, which reuses freed slots for new vectors. Recall stayed within 0.6 points of a fresh rebuild, but my timing comparison was not like for like, so I draw no speed conclusion.
My runs did not reproduce the worse case from the literature. Xiao et al. (2024) repeatedly deleted and re-inserted 5% of SIFT over 3,000 iterations and report that 3-4% of points became unreachable and recall fell by about 3%. They state that raising efSearch does not fix this. That is the paper's figure, not my run. I did not measure IVF deletes. Removing a row from one list is simple by construction, but I have no number for it.
How production engines take new writes
In the vendor docs I read (not my tests), Qdrant and turbopuffer say recent writes sit in an unindexed structure that queries scan exhaustively until a background job indexes it, and Milvus describes growing segments that are indexed only after they are sealed. I did not check other engines. Qdrant also skips the vector index for small segments, with cutoffs set in kilobytes of vector data rather than a point count.
Do the layers matter?
A 2025 paper presented at the ICML Workshop on Vector Databases (Munyampirwa et al., "Down with the Hierarchy", arXiv 2412.01940) found that on high-dimensional data a flat graph with no layers matched HNSW on latency and recall, with less memory. I did not test that. In my runs the upper layers held only 6.3% of the points, so they are cheap, and the open question is how much of the speed they explain.

When to choose which
I use these questions in order. They are rules of thumb from building both, not laws.
Fewer than about 10,000 vectors? Skip the index and scan everything. According to their docs, Weaviate's dynamic index switches to HNSW above 10,000 objects by default, and Qdrant uses a full scan below a size threshold set in kilobytes.
Does the index fit in RAM? If yes, HNSW is the fast default. If not, compress or move to disk. By arithmetic, 1 million vectors of 768 numbers take about 3.08 GB as IVF-Flat (768 x 4 + 8 bytes each) and about 72 MB as IVF-PQ with 64 sub-quantizers (64 + 8 bytes each). Compression costs recall, so re-rank the top results on full vectors and measure.
Does your data churn? For heavy deletes and rewrites, pick IVF with a retraining schedule, or plan regular HNSW rebuilds. For mostly appended data, HNSW is fine. My own line, from one run: once 30% of the vectors were deleted, the tombstoned HNSW index ran at 63% of a fresh rebuild's speed, and at 50% deleted, 55%. If more than about 30% of your index is deleted between rebuilds, plan rebuilds or look at IVF.
A case like 5 million vectors that change every day sits between the rules. I would test both on a sample of my own data and schedule rebuilds for whichever I picked.

What I did not test
Scale: 200,000 vectors, not 1 million or 100 million.
Data type: SIFT image descriptors at 128 dimensions, not 768-dimensional text embeddings.
Two libraries: faiss for IVF and hnswlib for HNSW, so part of the gap may be implementation, not algorithm. Read the speed ratio as rough. It is not a verdict on either library.
Load: one search thread, no concurrent queries, no GPU, on a 4 vCPU virtual machine.
Metric: recall@10 only, not end-to-end RAG answer quality, and no metadata filters.
Other index types: no IVF-PQ or compressed-HNSW runs (the 72 MB figure is arithmetic), no DiskANN.
Low recall: HNSW below 0.85 recall@10.
Drift: constructed along one axis of one dataset.
IVF deletes: not measured.
Repeat variation: two full runs, one seed each. Timings moved by 10 to 30% between them.
Neighbour selection: a 2-D toy model, not hnswlib's code.
How to reproduce this
Everything is in one repository: github.com/trehansalil/ivf-vs-hnsw-benchmark.
git clone https://github.com/trehansalil/ivf-vs-hnsw-benchmark.git && cd ivf-vs-hnsw-benchmark
uv venv --python 3.13 .venv && source .venv/bin/activate
uv pip install -r requirements.txt
wget http://ann-benchmarks.com/sift-128-euclidean.hdf5 -P data/
python run_benchmark.pyThe run takes about 17 minutes on 4 cores and writes results/results.json and results/results.csv. The repository also holds my first run's results and a comparison of the two. Pinned versions: Python 3.13.12, faiss-cpu 1.15.1, hnswlib 0.8.0, numpy 2.5.4, h5py 3.16.0, scikit-learn 1.9.1.
FAQ
Is HNSW always faster than IVF?
Not always, and I did not test every case. On my SIFT set it answered faster than IVF-Flat at every recall level I could compare, from 0.85 to 0.999 recall@10. Below that range, at larger scale, or against IVF-PQ, the answer may change.
Which should I use for a RAG app with text embeddings?
I tested image descriptors, so I have no measured answer. My starting point is HNSW when the index fits in RAM and the data mostly grows. Then I test recall at a few settings on a sample of real embeddings.
Does HNSW use much more memory than IVF?
At 128 dimensions it did: 661 bytes per vector against 520, about 27% more. For longer vectors the links are a smaller share, about 4% over a 768-dimensional vector by the FAISS formula. Compression such as IVF-PQ is a bigger lever than the choice between the two.
What happens to HNSW when I delete vectors?
Most implementations keep the node in the graph and mark it deleted. In my hnswlib runs recall held, but at 50% deleted the index ran at about 55% of the speed of a fresh rebuild. Published work (Xiao et al., 2024) reports that after 3,000 rounds of deleting and re-adding 5% of SIFT, 3-4% of points were unreachable. Schedule rebuilds if your data churns.
Do I need an index at all?
Not for small collections. Weaviate's dynamic index starts flat and switches to HNSW above 10,000 objects by default, and Qdrant's documentation says a full scan is cheaper than building an index for a small segment.
Another benchmark write-up in the same style, on weight edits versus LoRA and prompting: Weight-space editing vs fine-tuning: 64 demos won on 0.8B.
About the author
Salil Trehan builds AI and ML systems, writes up the measurements, and runs a lot of experiments.
Code for this post: github.com/trehansalil/ivf-vs-hnsw-benchmark.
Questions or corrections: LinkedIn or book a call on Topmate.



Comments