HNSW and SQ8 vector indexes
HNSW, the default, or SQ8 with clustered partitions, built per segment.
Building indexes
index builds an index for each live segment with at least min_rows rows (default 4,096) that has none yet, and publishes it in the manifest. Neither compaction nor maintain builds indexes, so schedule index after them. The Python maintainer can run it for you.
# An index is built per segment, for segments of at least min_rows rows.
print(ns.index()) // One document is under the default minimum, so nothing is indexed.
let report = ns.index(&IndexOptions::default()).await?;
assert_eq!((report.indexed, report.skipped_small), (0, 1));
// A minimum of zero indexes it.
let report = ns.index(&IndexOptions::default().min_rows(0)).await?;
assert_eq!(report.indexed, 1);The index kind is an option: HNSW by default, or SQ8 (kind="sq8" in Python, IndexKind::Sq8 in Rust). A namespace can hold both, and a rebuild can switch one segment’s kind. rebuild: true builds again over existing indexes. An index needs segment format 2 or above.
HNSW
HNSW is a graph over one-byte-per-dimension codes. A query fetches a segment’s whole index object in one request, then walks the graph out of those bytes, so it is cheap once the object is warm in a cache and costs one larger read cold. It takes longer to build than SQ8. At 32 segments it gave recall@10 of 0.987 on SIFT1M and 0.984 on GloVe-25.
SQ8
SQ8 stores each vector as one byte per dimension and reads only the partitions a query probes, which suits uncached reads. Segments of 100,000 rows or more are clustered into about sqrt(rows) partitions (nlist overrides), and a query reads about 2 * sqrt(nlist) of them by default. On SIFT1M and GloVe-25 the defaults gave recall@10 of 0.99 or more.
A clustered index is approximate unless nprobe reaches its partition count; recall is measured on SIFT1M and GloVe-25 only.
How does a query use an index?
Each segment with an index proposes candidates through it, and segments without one are scanned. Candidates are reranked on their exact vectors, so the answer never carries an approximate distance. See Querying for rerank, nprobe and exact.
