Lab / Vector search
A vector index that demonstrates itself.
An HNSW graph I wrote in Rust, 18.5 KB over the wire, searching 67 chunks of this site inside your browser. Everything below is measured in this tab, including the part where the graph loses.
What this is
Search here has two stages. BM25 over an 80 KB inverted index answers the first keystroke and is the only stage almost anyone reaches. This is the second: a hierarchical navigable small world graph over int8 vectors, built by Index::build when you opened this page.
I wrote the graph rather than installed it. Construction, the neighbour-selection heuristic, the search, the quantised vector format and the WebAssembly bindings are in crates/hnsw/src/, in about 1,200 lines of Rust with the paper’s algorithm numbers in the comments. What the browser downloads for it is 18.5 KB.
The honest part comes first, because it is the part a demo page usually buries: at 67 chunks, a brute-force scan is already sub-millisecond, so the graph is not saving meaningful time here and the measurements below will show it doing roughly the same amount of arithmetic as the scan it replaces. It earns its place because the structure is the point: the traversal that costs nothing to run at this size is the one that matters once a corpus outgrows a linear scan. And because an index that cannot be checked is a claim rather than evidence: brute_force is a first-class method of the crate, not a test helper, and it is the ground truth every recall number below is computed against.
loading the index…
Where the code is
crates/hnsw/src/hnsw.rs is the algorithm, with no WebAssembly in it: construction, ALG 4’s neighbour heuristic, the layer descent, and a brute-force scan kept for grading. quant.rs is the on-the-wire vector format. lib.rs is nothing but marshalling across the JS boundary, plus the introspection API this page renders. The Rust test suite asserts recall against ground truth rather than asserting that search returned ten things.
Other things you can run are in the lab.