Build your own vector database
The two structures HNSW rests on·10 min

The distribution is geometric

0 / 1
# grade this stage (from your course directory)
npx theinference test --stage verify-the-distribution --watch

A quick structural smoke test before any graph exists. Over the full insertion order, count how many elements reach each layer and confirm the counts match the seeded draw exactly. layerCounts[l] = number of elements whose drawn level is ≥ l.

With M = 8 you should see a clean geometric staircase: every element on layer 0, roughly an eighth of them on layer 1, an eighth of those on layer 2, and so on, down to one or two at the apex.

What to build

Your task

Print per-layer node counts

Implement layerCounts(levels) and wire the structure subcommand in src/cli.ts. It reads the data file, draws all levels with the seed, and prints one JSON line:

{ "layers": <count>, "counts": { "l0": ..., "l1": ... }, "top": <topLayer> }
your_program.sh
./your_program.sh structure <fixture>/chapters/01-data-structures/steps/06-verify-the-distribution/fixtures/data.json
Integer-exact, no tolerance

These counts are not a sample you tolerance-check — they come straight from the deterministic seeded draws (the exact level array from the previous step). So they must equal the reference integer-exact (same seed, same mulberry32, same insertion order). A ±5% band here would only mask a wrong PRNG. (The ±5% idea belongs to the post-build structural check in Chapter 4, where edge-shrinking can legitimately nudge a count — not to this pure level-draw histogram.)

How it's graded

Process mode: stdout_json_match of your printed object against the frozen reference, atol 0 — a deep, exact compare of every per-layer count.