RAG & Retrieval · Ground answers in evidence
HNSW vs IVF: how do you choose an index?
Short answer
HNSW gives strong recall and low latency but uses more memory and is slower to build. IVF clusters vectors and searches a subset, which can be cheaper at very large scale but needs tuning.
HNSW builds a layered graph and navigates it greedily, which makes queries fast and accurate at the cost of memory for graph links. IVF partitions vectors into clusters, then searches only the nearest clusters; it is memory-friendlier but sensitive to cluster count and data distribution.
- HNSW: default choice for low-latency, high-recall retrieval that fits in memory.
- IVF: attractive for very large, cost-sensitive indexes with acceptable recall tuning.
- Both need recall measurement against exact search on representative queries.
- Update patterns matter: frequent deletes and inserts stress some indexes more than others.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1How would you tune IVF's number of probes?
- 2Why does HNSW use so much memory?
- 3How do updates and deletes affect index performance?
Say it in the interview
HNSW is a graph index with excellent recall and latency, but it keeps a lot in memory. IVF clusters vectors and searches the nearest clusters, which can be cheaper at very large scale if I tune the probe count. I choose by benchmarking recall, latency, memory and update behaviour on my own data. The algorithm matters less than how the managed service implements filters and deletes.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live RAG & Retrieval mock interview and get scored feedback on depth, clarity and confidence.