Implement INSERT
# grade this stage (from your course directory)
npx theinference test --stage insert-full --watchCompose everything into the full insert, then buildIndex to insert the whole corpus in the fixed order. This is the moment a real HNSW graph comes into existence — and you grade it on its structure, not yet on search.
What to build
Implement INSERT + buildIndex
Implement HNSW.insert(id, level) (the Algorithm 1 loop using your search-layer, select-heuristic, and connect) and buildIndex(vs, params) (assign all levels, insert 0..n-1). Wire the build-structure subcommand in src/cli.ts to build and print structural invariants.
./your_program.sh build-structure <fixture>/chapters/04-insert/steps/03-insert-full/fixtures/data.json
{ "topLayer": L, "maxDeg0": <= Mmax0, "maxDegUp": <= Mmax,
"degreeCapsOk": 1, "layer0Connected": 1, "layerCounts": { "l0": ... } }
Process mode: stdout_json_match against the frozen reference. The checks: every degree within its cap (Mmax0 at layer 0, Mmax above), layer 0 fully connected (BFS from the entry point reaches all nodes), and the per-layer counts match. Because the build is deterministic, your structure equals the reference exactly.
Your shrink step is probably dropping the only link to a node. Re-selecting with the heuristic and keeping pruned connections — which tops a shrunken neighborhood back up to capacity rather than discarding the surplus outright — is what preserves connectivity. That is the exact behavior the connect step asked you to build.