28/35
Part 6 of 6 · A worked example and follow-upsLearn and do

Keep float16 vectors, and search compressed codes in an inverted file

A billion vectors need a storage plan before they need a search.

A billion 768-dimension vectors, in all
HNSW graph, M = 32
3.3 TB
float32
3.1 TB
float16
1.5 TB
int8
768 GB
PQ, 64 bytes
64 GB
PDQ hash
32 GB

Bytes for each vector: 3,328, 3,072, 1,536, 768, 64 and 32.

Keep the float16 vectors in object storage as the source of truth, and build compressed indexes for search.

At this size, compression isn't optional. The Faiss documentation says every Faiss index is stored in RAM. Its page on billion-scale indexes says that for 10 million to a billion vectors per server, compression becomes mandatory.

Product quantization (PQ) stores each vector as a short code. Faiss's PQ index makes M-byte codes, so with M = 64 a vector takes 64 bytes. Then 64 GB of codes plus 8 GB of 64-bit IDs fits on one large machine.

The popular graph index, HNSW, doesn't fit: it's the top bar. Faiss gives its memory use as d×4+M×2×4d \times 4 + M \times 2 \times 4 bytes per vector, where dd is the dimension and MM the number of links per vector. With d=768d = 768 and M=32M = 32, that's 3,072+256=3,3283{,}072 + 256 = 3{,}328 bytes, or 3.3 TB of RAM for a billion.

For 100 million to a billion vectors, the same guide recommends an inverted file with about a million lists over compressed codes, IVF1048576_HNSW32. Read the name in two parts:

  • IVF1048576 is the inverted file, with 2202^{20} lists.
  • HNSW32 is an HNSW graph over the million list centroids. It finds the lists nearest a query.

The design method lesson shows how IVF and HNSW work inside. What matters here is which searches you need.

In the editor, write bytes_per_vector(kind) for the five ways to store one vector in the chart, and total_tb(n, per_vector) for a billion of them.