17/39
Part 3 of 6 · EstimationLearn

A graph index is bigger than the raw vectors

Now compare the bytes each kind of index stores for one vector.

Bytes for each vector
HNSW, M = 32
~1,280
flat float32
1,024
flat bf16
512
IVF-PQ, M = 64
72
IVF-PQ, M = 32
40

For a billion vectors, multiply by 10^9: about 1.3 TB, 1.02 TB, 512 GB, 72 GB and 40 GB.

HNSW, hierarchical navigable small world, is a graph index. Each vector links to its near neighbors in a layered graph, and a search walks the links toward the query.

Faiss lists HNSW at 4*d + x * M * 2 * 4 bytes per vector: the full vector, plus about 2M four-byte neighbor ids. The factor x is close to 1, and the bars use 1. In this formula M is the graph's neighbor count, not the number of PQ pieces. At d = 256 and M = 32, that's 1,024 bytes plus about 256, so roughly 1.3 TB for a billion vectors. That's more than the raw data.

The Faiss authors' advice follows from that arithmetic. Graph indexes suit cases with no limit on memory, typically indexes below a million vectors. For larger indexes, where compression is needed just to fit the vectors in memory, IVF is the only option.

Run the same arithmetic on a small catalog before you reach for compression. Five million vectors at 1,024 bytes is 5 GB. Store it flat, or put a graph on it, and spend the effort elsewhere.