Find the nearest vectors by squared Euclidean distance. Two IVF-Flat layouts isolate the cost of gathering coordinates by record position versus scanning a cluster contiguously. Residual IVF-PQ searches the same clusters using compressed vector codes. Disk-backed IVF-PQ can search a supplied set of eligible IDs. HNSW searches a hierarchy of in-memory proximity graphs. DiskANN traverses a disk-backed Vamana graph, scoring its frontier with PQ. An exhaustive scan supplies the exact answer.
On SIFT10K, HNSW at width 32 reaches 99.4% held-out recall@10 at 0.21 ms p95, against 1.5 ms for exhaustive search
knotkit/inverted-index : Indexes records by exact keys and scans sorted record IDs for one key or the union of several, using packed posting lists
knotkit/heap : Provides binary and k-ary min/max heaps plus indexed priority queues, ordered by caller-supplied comparators
knotkit/bitset : Provides exact membership, cardinality, set algebra, and order statistics over unsigned 32-bit ids, in one flat bitmap or 65,536-id chunks
knotkit/cache : Bounds an in-memory key-value store by entry count or total weight, with least-recently-used, SIEVE, S3-FIFO, or caller-supplied eviction and optional expiry
knotkit/distance : Compares vectors, probability distributions, and sets and exposes each rule’s mathematical guarantees
knotkit/prng : Generates seeded pseudorandom numbers and unbiased integers for reproducible simulations and tests
knotkit/sampling : Draws unbiased subsets, pairs, shuffles, and weighted samples over injected randomness
{"v":1,"box":[63.6024,94.1597,1043,444.3555],"x":{"s":"log","lim":[0.117185384051,1.70268503826],"inv":false,"g":0,"t":"Median p95 query latency of three processes (ms, log scale; Apple M1 Pro, Bun 1.4.4)","tk":[[0.130875000001,"0.13"],[0.214125,"0.21"],[0.28225,"0.28"],[1.524583,"1.5"]],"b":10},"y":{"s":"linear","lim":[93.521,100.279],"inv":false,"g":0,"tk":[[93.8,"93.8"],[94.4,"94.4"],[99.4,"99.4"],[100,"100"]]},"ti":"SIFT10K: HNSW keeps 99.4% recall at 7.1× lower p95","a":[{"k":"line","c":"#1d5fa6","s":"x","d":[0.130875000001,93.8,0.214125,99.4],"p":[104.04,429.9,284.21,139.71]},{"k":"scatter","c":"#c4501b","s":"xy","d":[0.28225,94.4],"p":[385.3,398.81],"r":4.96},{"k":"scatter","c":"#5b6b7c","s":"xy","d":[1.524583,100],"p":[1002.57,108.62],"r":4.96},{"k":"segments","c":"#8c8c84"},{"k":"segments","c":"#8c8c84"},{"k":"annotation","c":"#2b2b28"},{"k":"annotation","c":"#2b2b28"},{"k":"annotation","c":"#2b2b28"},{"k":"annotation","c":"#2b2b28"},{"k":"annotation","c":"#5c5c57"}],"lg":[]}
0.13
0.21
0.28
1.5
Median p95 query latency of three processes (ms, log scale; Apple M1 Pro, Bun 1.4.4)
93.8
94.4
99.4
100
HNSW width 10, 0.13 ms
HNSW width 32, 0.21 ms
IVF-Flat, 4 probes, 0.28 ms: slower and lower than width 32
exhaustive, 1.5 ms
Held-out recall@10 (%)
SIFT10K: HNSW keeps 99.4% recall at 7.1× lower p95
{"v":1,"box":[63.6024,605.1597,1043,955.3555],"x":{"s":"log","lim":[122.081441928,2312.42353908],"inv":false,"g":1,"t":"Vectors scored per query, of 2,048 (log scale)","tk":[[137.84375,"138"],[500,"500"],[1000,"1,000"],[2048,"2,048"]],"b":10},"y":{"s":"linear","lim":[73.875,101.125],"inv":false,"g":1,"tk":[[75,"75"],[80,"80"],[85,"85"],[90,"90"],[95,"95"],[100,"100"]]},"ti":"Synthetic: HNSW is exact at 179 vectors scored, IVF at 1,065","a":[{"k":"line","c":"#fffff8","s":"x","d":[165.75,99.84375,179.109375,100,206.484375,100,251.6875,100,289.171875,100,360.78125,100,425.046875,100],"p":[165.42,621.63,191.23,619.62,238.59,619.62,304.51,619.62,350.74,619.62,424.41,619.62,478.99,619.62]},{"k":"line","c":"#1d5fa6","s":"x","d":[165.75,99.84375,179.109375,100,206.484375,100,251.6875,100,289.171875,100,360.78125,100,425.046875,100],"p":[165.42,621.63,191.23,619.62,238.59,619.62,304.51,619.62,350.74,619.62,424.41,619.62,478.99,619.62]},{"k":"line","c":"#fffff8","s":"x","d":[137.84375,75,269.578125,91.5625,542.75,97.96875,1065.296875,100,2048,100],"p":[104.04,940.9,327.37,728.05,560.39,645.72,784.93,619.62,1002.57,619.62]},{"k":"line","c":"#c4501b","s":"x","d":[137.84375,75,269.578125,91.5625,542.75,97.96875,1065.296875,100,2048,100],"p":[104.04,940.9,327.37,728.05,560.39,645.72,784.93,619.62,1002.57,619.62]},{"k":"segments","c":"#8c8c84"},{"k":"segments","c":"#8c8c84"},{"k":"annotation","c":"#1d5fa6"},{"k":"annotation","c":"#c4501b"},{"k":"annotation","c":"#5c5c57"}],"lg":[]}
138
500
1,000
2,048
Vectors scored per query, of 2,048 (log scale)
75
80
85
90
95
100
HNSW, width 10 to 64
IVF-Flat, 1 to 16 probes
Held-out recall@10 (%), 64 queries
Synthetic: HNSW is exact at 179 vectors scored, IVF at 1,065
{"v":1,"box":[63.6024,122.3921,591.8342,444.3555],"x":{"s":"log","lim":[0.117185384051,1.70268503826],"inv":false,"g":0,"t":"Median p95 query latency of three processes (ms, log scale; Apple M1 Pro, Bun 1.4.4)","tk":[[0.130875000001,"0.13"],[0.214125,"0.21"],[0.28225,"0.28"],[1.524583,"1.5"]],"b":10},"y":{"s":"linear","lim":[93.521,100.279],"inv":false,"g":0,"tk":[[93.8,"93.8"],[94.4,"94.4"],[99.4,"99.4"],[100,"100"]]},"ti":"SIFT10K: HNSW keeps 99.4% recall at 7.1×\nlower p95","a":[{"k":"line","c":"#1d5fa6","s":"x","d":[0.130875000001,93.8,0.214125,99.4],"p":[85.41,431.06,182.58,164.27]},{"k":"scatter","c":"#c4501b","s":"xy","d":[0.28225,94.4],"p":[237.11,402.48],"r":4.96},{"k":"scatter","c":"#5b6b7c","s":"xy","d":[1.524583,100],"p":[570.03,135.68],"r":4.96},{"k":"segments","c":"#8c8c84"},{"k":"segments","c":"#8c8c84"},{"k":"annotation","c":"#2b2b28"},{"k":"annotation","c":"#2b2b28"},{"k":"annotation","c":"#2b2b28"},{"k":"annotation","c":"#2b2b28"},{"k":"annotation","c":"#5c5c57"}],"lg":[]}
0.13
0.21
0.28
1.5
Median p95 query latency of three processes (ms, log scale; Apple M1 Pro, Bun 1.4.4)
93.8
94.4
99.4
100
HNSW width 10, 0.13 ms
HNSW width 32, 0.21 ms
IVF-Flat, 4 probes, 0.28 ms: slower and lower than width 32
exhaustive, 1.5 ms
Held-out recall@10 (%)
SIFT10K: HNSW keeps 99.4% recall at 7.1×
lower p95
{"v":1,"box":[63.6024,633.3921,591.8342,955.3555],"x":{"s":"log","lim":[122.081441928,2312.42353908],"inv":false,"g":1,"t":"Vectors scored per query, of 2,048 (log scale)","tk":[[137.84375,"138"],[500,"500"],[1000,"1,000"],[2048,"2,048"]],"b":10},"y":{"s":"linear","lim":[73.875,101.125],"inv":false,"g":1,"tk":[[75,"75"],[80,"80"],[85,"85"],[90,"90"],[95,"95"],[100,"100"]]},"ti":"Synthetic: HNSW is exact at 179 vectors\nscored, IVF at 1,065","a":[{"k":"line","c":"#fffff8","s":"x","d":[165.75,99.84375,179.109375,100,206.484375,100,251.6875,100,289.171875,100,360.78125,100,425.046875,100],"p":[118.52,648.53,132.44,646.68,157.98,646.68,193.53,646.68,218.47,646.68,258.2,646.68,287.64,646.68]},{"k":"line","c":"#1d5fa6","s":"x","d":[165.75,99.84375,179.109375,100,206.484375,100,251.6875,100,289.171875,100,360.78125,100,425.046875,100],"p":[118.52,648.53,132.44,646.68,157.98,646.68,193.53,646.68,218.47,646.68,258.2,646.68,287.64,646.68]},{"k":"line","c":"#fffff8","s":"x","d":[137.84375,75,269.578125,91.5625,542.75,97.96875,1065.296875,100,2048,100],"p":[85.41,942.06,205.87,746.37,331.54,670.68,452.65,646.68,570.03,646.68]},{"k":"line","c":"#c4501b","s":"x","d":[137.84375,75,269.578125,91.5625,542.75,97.96875,1065.296875,100,2048,100],"p":[85.41,942.06,205.87,746.37,331.54,670.68,452.65,646.68,570.03,646.68]},{"k":"segments","c":"#8c8c84"},{"k":"segments","c":"#8c8c84"},{"k":"annotation","c":"#1d5fa6"},{"k":"annotation","c":"#c4501b"},{"k":"annotation","c":"#5c5c57"}],"lg":[]}
138
500
1,000
2,048
Vectors scored per query, of 2,048 (log scale)
75
80
85
90
95
100
HNSW, width 10 to 64
IVF-Flat, 1 to 16 probes
Held-out recall@10 (%), 64 queries
Synthetic: HNSW is exact at 179 vectors
scored, IVF at 1,065
HNSW finds 99.4% of the true top 10 with 7.1× lower p95 latency. Measured on 50 held-out SIFT10K queries. On the 2,048-vector synthetic fixture, HNSW reaches 100% recall@10 scoring 179 vectors per query; clustered IVF-Flat needs 1,065. In a separate tiny replay, IVF-Flat scores 2 candidates and exhaustive search scores 4. Hover or focus a chart for exact values. Drawn by demo.ts at build time, from the fixtures the benchmark uses; it reproduces the README figure.
git clone https://github.com/jkomyno/knotkit.git && cd knotkit && bun install
bun run demo:problem:nearest-neighbors
problems/nearest-neighbors/README.md states the fixture, the seed, and the result table.