A vector database indexes vectors with an algorithm such as HNSW, a graph-based index, or IVF, an inverted-file index that partitions the space into clusters. Both serve approximate nearest neighbour search, and the trade-off is between recall, query speed, build cost and memory. HNSW is the common default for high recall and fast queries; IVF is cheaper to build and uses less memory, at the cost of probing several clusters per query. The choice should follow your recall target and your update pattern, not a default.
What you need
- Your recall target, for example 95 percent of the true top 10
- How often vectors are added or updated
- Your memory and build-time budget
Step 1: Set the recall target first
Decide what recall you need at your top-k. If the product must almost always return the true nearest neighbours, HNSW is the safer default; if approximate is acceptable, IVF can be enough.
Step 2: Check the update pattern
HNSW handles inserts and updates more gracefully, since new vectors join the graph. IVF needs re-clustering when the collection changes a lot, so a fast-changing collection makes IVF maintenance heavier.
Step 3: Compare memory and build cost
HNSW keeps a graph in memory, which costs more RAM; IVF stores cluster centroids and is lighter. If memory is the binding constraint and recall is adequate, IVF wins.
Worked example: three synthetic workloads matched to an index
The table below is a synthetic example. It shows the expected result of matching workloads to indexes; no index was built.
| Workload | Recall need | Index |
|---|---|---|
| Customer support search | High – 95 percent | HNSW |
| Nightly batch analytics | Medium – 85 percent | IVF |
| Live recommendations | High, fast updates | HNSW |
| Archive search | Medium, rare updates | IVF |
Expected result (UNTESTED). the two high-recall workloads use HNSW and the two medium-recall workloads use IVF. This check was not run live; the table shows the expected result for the synthetic example.
Limits
- Both indexes are approximate: neither guarantees the true nearest neighbours on every query.
- Index parameters such as the HNSW graph degree and the IVF probe count tune the recall and speed trade-off; measure them on your own data.
- A payload index is separate from the vector index, and filtering needs its own index to be fast.
- Rebuilding an index after creating a payload index can be required for the filter to benefit from it.
