Skip to content

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.

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: start flat; if too slow choose RaBitQ or HNSW; if too large choose SQ8 or PQ start: flat too slow? too large? rabitq hnsw / ivf sq8 pq exact scores,no training sub-linear,approximate 4× smaller up to 32× smaller
Whatever you pick, measure recall against flat on a sample of your own data.
  1. Exact results, small or medium collection: flat.
  2. Scan too slow, want flat-like results, no training: RaBitQ.
  3. Large collection, sub-linear search: HNSW; IVF when the data is present before training.
  4. 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.

import random
import 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.

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.

IVF (train_ivf), SQ8 (min and max per dimension) and PQ (k-means codebooks). Flat, HNSW and RaBitQ need none.

Next: What is flat (exact) vector search?

Each concept page ends with the papers behind its method.