Concepts
Which SrvDB index mode should I use?
Flat, HNSW, IVF, SQ8, PQ and RaBitQ side by side in SrvDB - how each searches, bytes per vector computed from the file formats, training needs, score exactness and when to pick it.
Start with flat, which is exact, and change mode only when search is too slow or files are too large. SrvDB gives you six ways to search the same durable, checksummed vector store, all in one embedded library with no server: pick by recall, speed and bytes per vector.
All modes at a glance
Section titled “All modes at a glance”Bytes per vector come from the record layouts in crates/srvdb/src/storage
and exclude metadata and the small CRC sidecars. D is the dimension.
| Mode | How it searches | Scores | Bytes per vector | At D = 768 | Training |
|---|---|---|---|---|---|
flat |
Scan of every vector | Exact | 4D |
3072 | None |
hnsw |
Layered graph walk | Exact cosine, approximate ranking | 4D + links (≤ 2m ids on layer 0) |
3072 + links | None |
ivf |
Probe nprobe partitions, HNSW in each |
Exact cosine, approximate ranking | 4D + links (+ centroids per index) |
3072 + links | train_ivf() |
sq8 |
Scan of 8-bit codes | Approximate | D |
768 | First batch or sample |
pq |
Scan with lookup tables | Approximate | D / 8 (or D / 4) |
96 | First batch ≥ 256 or sample |
rabitq1 |
Code scan, then rerank | Exact with rerank | 4D + 4 + ceil(D/8) |
3172 | None |
rabitq2 |
Code scan, then rerank | Exact with rerank | 4D + 4 + ceil(D/4) |
3268 | None |
rabitq4 |
Code scan, then rerank | Exact with rerank | 4D + 4 + ceil(D/2) |
3460 | None |
“Exact cosine, approximate ranking” means the returned scores are true cosine similarities, but a true neighbour can be missed. RaBitQ’s scan reads only the codes: 100, 196 or 388 bytes per vector at D = 768.
Decision guide
Section titled “Decision guide”- Exact results, small or medium collection: flat.
- Scan too slow, want flat-like results, no training: RaBitQ.
- Large collection, sub-linear search: HNSW; IVF when the data is present before training.
- Disk or memory is the limit: SQ8, then PQ.
Performance depends on your hardware and data. Published, reproducible measurements, with hardware, OS, dataset, commit and command, are on the benchmarks page. RaBitQ fast-scan timings are preliminary and not quoted here.
Try it in SrvDB
Section titled “Try it in SrvDB”import randomimport srvdb
rng = random.Random(7)vectors = [[rng.gauss(0, 1) for _ in range(128)] for _ in range(500)]ids = [f"doc-{i}" for i in range(len(vectors))]
for index in ["flat", "hnsw", "sq8", "rabitq"]: db = srvdb.create(f"./db-{index}", dimension=128, index=index) db.add(ids, vectors, ["{}"] * len(ids)) db.save() print(index, db.search(vectors[42], k=1)[0][0])Choosing an index mode has a recall_at_k
helper for comparing modes on your own data.
Which SrvDB mode should I start with?
Section titled “Which SrvDB mode should I start with?”Start with flat. It is exact, needs no training and is the baseline for measuring every other mode. Switch only when search is too slow or files are too large.
Which SrvDB modes return exact cosine scores?
Section titled “Which SrvDB modes return exact cosine scores?”Flat, HNSW, IVF and RaBitQ with rerank on score candidates against the full vectors. SQ8 and PQ score against compressed codes, and RaBitQ with rerank 0 returns estimates.
Which SrvDB modes need training?
Section titled “Which SrvDB modes need training?”IVF (train_ivf), SQ8 (min and max per dimension) and PQ (k-means
codebooks). Flat, HNSW and RaBitQ need none.
Related concepts
Section titled “Related concepts”Next: What is flat (exact) vector search?
Papers and further reading
Section titled “Papers and further reading”Each concept page ends with the papers behind its method.
Was this page helpful? Tell us in Discussions.