Vector index memory planner
Most vector search runs from memory, so the first sizing question is how much RAM an index needs. The vectors themselves are only part of the answer: a graph index stores links beside every vector, a clustered index stores ids and centroids, and a compressed index trades precision for a much smaller code.
32 GB for 10,000,000 vectors with an HNSW graph. Largest part: Vectors, 96%.
| Part | Size | Share |
|---|---|---|
| Vectors | 30.7 GB | 95.9% |
| Graph links | 1.3 GB | 4.1% |
Data and index
768, 1,024 and 1,536 are common for text embeddings.
Payload kept in memory beside each vector, such as filter fields.
Full copies of the index, for throughput or availability.
hnswlib suggests 12 to 48 for most uses. A higher M raises recall and memory.
Detail
| Index type | Per replica | All replicas |
|---|---|---|
| Flat (exact search) | 30.7 GB | 30.7 GB |
| HNSW graph | 32 GB | 32 GB |
| IVF-flat | 30.8 GB | 30.8 GB |
| IVF-PQ | 1.1 GB | 1.1 GB |
Formulas used (all estimates)
- Estimate, vectors:
vectors × dimensions × bytes per dimension. Binary packs 8 dimensions per byte. - Estimate, graph links:
vectors × 4 × (2M + M ÷ (M − 1))= 132.3 bytes per vector. Layer 0 keeps 2M links; upper layers add about M ÷ (M − 1) on average. - Estimate, total: parts per replica, plus
vectors × metadata bytes, times replicas.
What it shows
Most vector search runs from memory, so index size decides how much RAM you need. The vectors are only part of it: graph indexes add links, clustered indexes add ids and centroids, and compressed indexes store smaller codes.
The tool adds these parts for one replica, then multiplies by replicas. All formulas are estimates from published rules of thumb.
How to read it
- Raw vectors is vectors × dimensions × bytes per dimension. float32 uses 4 bytes, float16 2, int8 1, and binary 1 bit.
- Index overhead is everything beyond vectors and metadata. HNSW adds graph links; IVF types add ids and centroids; IVF-PQ also adds codebooks.
- Quantising vectors does not shrink the HNSW graph, so overhead grows as a share of the total.
- IVF-PQ stores m codes per vector. The element type then only sets the raw size shown for comparison.
- Total is per-replica memory times replicas. Each replica holds a full copy.
- The table at the bottom compares all four index types at your settings.
Questions
Why does an HNSW index use more memory than the vectors alone?
Each vector keeps a list of neighbour ids at every layer it appears in. At layer 0 that is up to 2M ids of 4 bytes each, so M = 16 adds about 130 bytes per vector. The overhead is small next to a 768-dimension float32 vector, but large next to a quantised one.
Does quantising the vectors shrink the HNSW graph?
No. The links depend only on M and the number of vectors. Quantising from float32 to int8 cuts the vector bytes by four but leaves the links unchanged.
Why must dimensions divide evenly by m in product quantisation?
Product quantisation splits each vector into m equal sub-vectors and learns a separate codebook for each. If the dimensions did not divide evenly, the sub-vectors would differ in length. The planner lists only the values of m that work for your dimensions.
What does this estimate leave out?
Memory used while building the index, query buffers, the operating system, filtering structures, and any full-precision copy of the vectors kept to re-rank results. A disk-backed index also holds less in RAM than shown here.
How accurate are these numbers?
They follow the bytes-per-vector rules in the faiss wiki and the memory note in the hnswlib documentation, plus the layer-probability result from the HNSW paper for the upper layers. Real libraries add headers, alignment and allocator overhead, so expect the measured size to be somewhat higher.
Sources
- Malkov, Y. A. and Yashunin, D. A. (2016). Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs. arXiv:1603.09320.
- Jégou, H., Douze, M. and Schmid, C. (2011). Product quantization for nearest neighbor search. IEEE TPAMI 33(1).
- Faiss wiki: Guidelines to choose an index.
- Faiss wiki: Faiss indexes (bytes per vector for each index).
- hnswlib: ALGO_PARAMS.md (the M parameter and its memory use).
Explore further
- ANN-BenchmarksCompares approximate nearest neighbour libraries on recall against queries per second.
Last updated
More tools
All tools- estimatorLLM cost estimatorCost per request and per month across LLM APIs, with caching, batch pricing and routing.Open tool
- estimatorAgent run cost estimatorCost of an agent run by model, steps and prompt caching, with context growth and the step where the window fills.Open tool
- calculatorRetrieval metrics calculatorGrade a ranked list and see precision, recall, hit rate, MRR, average precision and nDCG react to each move.Open tool