Estimate the memory size of an approximate nearest neighbor search index.
An HNSW (Hierarchical Navigable Small World) index stores raw vectors plus a graph structure connecting each vector to M neighbors across multiple layers. Total memory = vector storage + graph overhead. Higher M improves recall but increases memory and build time.
HNSW Index Size
size = (n × d × bytes_per_float) + (n × M × 2 × 4)
M=16 is a good default balancing recall and memory. Higher M (32-64) improves recall@k but increases memory linearly. For production, benchmark recall vs memory on your data.
HNSW graph overhead is typically 5-15% of raw vector storage for M=16. The dominant cost is always the vectors themselves.