FTS Algorithm Benchmark
Auto-generated by
test/search-benchmark.shon 2026-03-05 01:13:39
Environment #
| Parameter | Value |
|---|---|
| OS | Darwin 25.3.0 arm64 |
| Go | go1.26.0 |
| Documents | 10000 |
| Queries | 10 diverse queries |
| Iterations | 10 per query per algorithm |
| Runs | 10 (benchmark repeated 10x, results aggregated) |
| Total searches | 1000 per algorithm config |
| Warmup | 5 queries per run (discarded) |
Algorithms #
| Algorithm | Description |
|---|---|
| tfidf | Classic TF-IDF term frequency scoring |
| bm25 | Okapi BM25 probabilistic ranking with length normalization |
| bm25f | BM25F field-weighted scoring (title, meta, content) |
| pmisparse | BM25 + PMI query expansion (invented by Tradik Limited) |
| +fuzzy | Levenshtein distance 1 fuzzy matching variant |
Latency Results #
| Algorithm | Avg (ms) | P50 (ms) | P95 (ms) | P99 (ms) | Min (ms) | Max (ms) | QPS |
|---|---|---|---|---|---|---|---|
| tfidf | 11.44 | 11.09 | 12.98 | 17.60 | 9.84 | 29.02 | 87 |
| tfidf+fuzzy | 24.44 | 23.71 | 27.34 | 35.54 | 22.39 | 102.60 | 40 |
| bm25 | 13.40 | 12.07 | 16.13 | 35.68 | 10.04 | 224.20 | 74 |
| bm25+fuzzy | 26.31 | 24.87 | 30.44 | 40.56 | 23.03 | 254.57 | 38 |
| bm25f | 13.08 | 12.59 | 16.24 | 18.88 | 10.71 | 26.76 | 76 |
| bm25f+fuzzy | 27.09 | 25.94 | 29.72 | 37.40 | 24.31 | 230.38 | 36 |
| pmisparse | 18.43 | 16.74 | 29.92 | 34.30 | 13.19 | 76.31 | 54 |
| pmisparse+fuzzy | 30.57 | 28.87 | 41.22 | 43.98 | 25.84 | 59.31 | 32 |
Average Latency Comparison #
xychart-beta
title "Average Search Latency (ms) — lower is better"
x-axis ["tfidf", "tfidf+f", "bm25", "bm25+f", "bm25f", "bm25f+f", "pmisparse", "pmisparse+f"]
y-axis "Latency (ms)"
bar [11.44, 24.44, 13.40, 26.31, 13.08, 27.09, 18.43, 30.57]
Throughput Comparison #
xychart-beta
title "Search Throughput (queries/sec) — higher is better"
x-axis ["tfidf", "tfidf+f", "bm25", "bm25+f", "bm25f", "bm25f+f", "pmisparse", "pmisparse+f"]
y-axis "QPS"
bar [87, 40, 74, 38, 76, 36, 54, 32]
Bulk Ingest Throughput #
Indexing a document touches three full-text indexes, and each entry point used to open its own BoltDB write transaction — so a batch paid three commits per document. Batching a whole chunk into one transaction (GO-027) leaves the work unchanged and removes the commits.
| Before | After | |
|---|---|---|
| 1000 documents, indexed | 4.20 s (238 docs/s) | 0.14 s (6 996 docs/s) |
| Allocated | 452 MB | 68 MB |
Measured with go test -bench BenchmarkBulkIngest -benchmem -run '^$' . in
services/mddbd. The same benchmark with SkipFTS reports ~57 000 docs/s,
which is the cost of the document writes alone — indexing was 99.5% of the
time before this change.
The batched index is byte-for-byte identical to the per-document one; a test compares every FTS bucket entry between the two paths rather than checking that search still returns something.
Result Counts per Query #
Shows how many documents each algorithm returns (limit=10) to verify they all find relevant results.
| Query | tfidf | bm25 | bm25f | pmisparse |
|---|---|---|---|---|
| kubernetes deployment cluster | 10 | 10 | 10 | 10 |
| neural network training | 10 | 10 | 10 | 10 |
| database query optimization | 10 | 10 | 10 | 10 |
| machine learning model | 10 | 10 | 10 | 10 |
| security authentication token | 10 | 10 | 10 | 10 |
| cloud infrastructure scaling | 10 | 10 | 10 | 10 |
| data pipeline processing | 10 | 10 | 10 | 10 |
| api gateway middleware | 10 | 10 | 10 | 10 |
| distributed consensus protocol | 10 | 10 | 10 | 10 |
| search algorithm ranking | 10 | 10 | 10 | 10 |
Notes #
- tfidf: Fastest for simple keyword matching. No length normalization.
- bm25: Slightly more compute than tfidf due to document length normalization. Best general-purpose algorithm.
- bm25f: Adds field-level weighting. Slower due to separate field index lookups.
- pmisparse: First search triggers lazy PMI matrix training (not included in benchmark). Subsequent searches include PMI expansion overhead.
- fuzzy: Adds Levenshtein distance computation. Expected ~2-3x slower than exact matching.
- All benchmarks run on a warm server with FTS indices already built during document insertion.
Reproducible profile: latency, recall, ingest and recovery (TEST-005) #
One harness, tools/bench/profile, measures
search, ingest, start-up and recovery on a corpus drawn from a seed, and
writes everything it measured — with the machine, the Go version and the
commit — to one JSON file in docs/benchmarks/. The tables
below are rendered from those files; a test
(TestBenchmarkDocInSyncWithResultFiles in tools/bench/profile) fails when a
table and its file disagree, so every number here has a file behind it.
make bench-profile PROFILE=small # 20,000 vectors × 128 dims → docs/benchmarks/<version>-small.json
make bench-profile PROFILE=full # 200,000 vectors; BENCH_ARGS="-vectors 2000000" for 2M
make bench-profile BENCH_BASELINE=docs/benchmarks/2.19.7-small.json # also gate against a baseline
make bench-profile-docs # rewrite the tables below from the JSON files
The pull-request gate in CI compares against docs/benchmarks/ci/, results
recorded by the bench-profile workflow on a hosted runner, not against the
desktop results the tables below show: the two machines differ in how fast
memory-bound scans run next to graph searches, so a desktop baseline would
fail sound changes. Hosted runners also vary in processor; when the runner's
processor differs from the baseline's, a p95 difference is reported as a
warning and only recall, lost writes and replication can fail the job. To
refresh it, run the workflow by hand and commit its
bench-run/result.json artifact as docs/benchmarks/ci/<version>-small.json.
The harness builds mddbd from the tree and starts its own servers on free
loopback ports, with no network: search embeddings come from a local endpoint
that returns the seeded corpus vectors (so recall is scored against the exact
answer), ingest embeds with the built-in lexical provider. What it measures:
- Search — full text (BM25), every vector algorithm by name and
auto(the planner), hybrid (RRF), and vector search behind a metadata filter admitting 1, 2, 10, 25 and 50% of the corpus. Latency is client-side over sequential requests (the median of 5 rounds of 1,000 queries), QPS over a pass with several clients, recall@10 against brute-force cosine. - Ingest — single documents and batches of 1,000, without embedding and with the lexical provider (a document counts once its vector is indexed).
- Mixed — four clients searching HNSW while one writes.
- Start-up — a clean restart of the loaded node: process start to healthy, and to each vector algorithm's first answer. The trainable indexes (IVF, PQ, OPQ, SQ, SQ4, BQ) train before they answer, which is most of that time.
- Recovery —
kill -9under four writers, restart, time to ready and every acknowledged write read back; a clean restart of the same node; a leader and a follower: lag from the leader's acknowledgement to the document being readable on the follower under write load, then the follower stopped, documents written, and the time from its restart to an equal checksum.
The pull-request gate (.github/workflows/bench-profile.yml, only for
changes to the vector indexes, the search paths, the binlog, replication or
the harness) runs the small profile and fails on a recall@10 drop of more
than 0.02, a p95 growth of more than 15% (compared as each scenario's share
of the run's geometric-mean p95, so a slower runner does not fail it), a lost
acknowledged write, or a follower that caught up in the baseline and no
longer does. p95 is noisy on a shared machine — two runs of the same build
here differed by up to 30% on single scenarios, recall by 0.003 — so a gate
that fails on p95 alone measures the search scenarios again and fails only
if they fail twice.
2.19.8, small profile #
Same machine and corpus as the 2.19.7 run below. Restart to every index answering went from 316 s to 0.23 s (index checkpoints), filtered HNSW p95 dropped by 1.3–4.0× (filter-aware walk), and the follower now stays in sync (batched applies).
MDDB 2.19.8 (e54e6de0), profile small, seed 1, recorded 2026-11-16 on AMD Ryzen 9 7950X 16-Core Processor — 32 cores, 30.9 GB, linux/amd64, kernel 6.18.58.1-microsoft-standard-WSL2, go1.27.4. Calibration 5.005 ms.
Search — 20000 vectors × 128 dims in 100 topics; 1000 timed queries × 5 sequential rounds for latency, 4 clients for QPS.
| Scenario | Answered by | p50 ms | p95 ms | p99 ms | QPS | recall@10 |
|---|---|---|---|---|---|---|
fts-bm25 |
bm25 | 0.379 | 0.473 | 0.685 | 9921 | — |
vector-flat |
flat | 0.854 | 1.095 | 3.323 | 3399 | 1.000 |
vector-hnsw |
hnsw | 0.403 | 0.471 | 0.582 | 10062 | 1.000 |
vector-ivf |
ivf | 0.491 | 0.582 | 0.770 | 8669 | 1.000 |
vector-pq |
pq | 2.901 | 3.253 | 5.303 | 1301 | 0.827 |
vector-opq |
opq | 2.923 | 3.270 | 5.360 | 1301 | 0.798 |
vector-sq |
sq | 4.495 | 5.113 | 6.614 | 854 | 1.000 |
vector-sq4 |
sq4 | 5.512 | 7.049 | 7.839 | 748 | 1.000 |
vector-bq |
bq | 1.658 | 2.026 | 4.153 | 2247 | 1.000 |
vector-auto |
hnsw | 0.407 | 0.471 | 0.597 | 10393 | 1.000 |
hybrid-rrf-hnsw |
— | 0.534 | 0.624 | 1.005 | 7140 | — |
hybrid-rrf-flat |
— | 1.020 | 1.279 | 3.970 | 2959 | — |
filtered-hnsw-1pct |
hnsw+prefilter | 0.357 | 0.422 | 0.566 | 11451 | 1.000 |
filtered-hnsw-2pct |
hnsw+prefilter | 0.432 | 0.512 | 0.718 | 9471 | 1.000 |
filtered-hnsw-10pct |
hnsw+prefilter | 0.701 | 0.870 | 1.337 | 4976 | 1.000 |
filtered-hnsw-25pct |
hnsw | 0.859 | 1.089 | 1.744 | 4111 | 1.000 |
filtered-hnsw-50pct |
hnsw | 1.225 | 1.642 | 2.529 | 2755 | 1.000 |
filtered-auto-1pct |
flat+prefilter | 0.369 | 0.445 | 0.596 | 11024 | 1.000 |
filtered-auto-2pct |
flat+prefilter | 0.438 | 0.512 | 0.740 | 9456 | 1.000 |
filtered-auto-10pct |
flat+prefilter | 0.715 | 0.903 | 1.402 | 5082 | 1.000 |
filtered-auto-25pct |
ivf | 0.860 | 1.166 | 1.865 | 4007 | 1.000 |
filtered-auto-50pct |
hnsw | 1.252 | 1.671 | 2.544 | 2548 | 1.000 |
| Ingest | Documents | Batch | Embedding | docs/s | request p50 ms | p95 ms | p99 ms |
|---|---|---|---|---|---|---|---|
single-none |
1000 | 1 | none | 222 | 4.534 | 5.820 | 6.405 |
batch-none |
10000 | 1000 | none | 6027 | 644.441 | 666.423 | 666.423 |
single-lexical |
1000 | 1 | lexical | 194 | 5.115 | 6.333 | 7.008 |
batch-lexical |
10000 | 1000 | lexical | 723 | 5524.253 | 6367.046 | 6367.046 |
| Mixed load, start-up and recovery | Value |
|---|---|
| Mixed (4 readers, 1 writer, 10 s): search p50 / p95 / p99 | 0.427 / 0.733 / 1.003 ms |
| Mixed: searches per second | 8682 |
| Mixed: write p50 / p95 / p99 | 7.728 / 9.676 / 10.753 ms |
| Mixed: writes per second | 127 |
| Clean restart of the search node: process start to healthy | 0.100 s |
| Clean restart of the search node: process start to every vector index answering | 0.231 s |
| Clean restart: process start to each index's first answer | flat 0.2 s, hnsw 0.2 s, ivf 0.2 s, pq 0.2 s, opq 0.2 s, sq 0.2 s, sq4 0.2 s, bq 0.2 s |
| Peak resident memory of the search node | 448.8 MiB |
| kill -9 under write: acknowledged writes / lost after restart | 768 / 0 |
| kill -9 under write: process start to ready | 0.071 s |
| Same node, clean restart: process start to ready | 0.071 s |
| Replication lag, 50 probes under 20 writes/s: p50 / p95 / p99 | 0.342 / 0.610 / 293.897 ms |
| Replication: probes not on the follower within 30 s | 0 of 50 |
| Follower catch-up after missing 5000 documents: process start to in sync | 1.782 s |
| Follower checksum and document count equal the leader's | true |
2.19.7, small profile #
MDDB 2.19.7 (96a2b023), profile small, seed 1, recorded 2026-11-16 on AMD Ryzen 9 7950X 16-Core Processor — 32 cores, 30.9 GB, linux/amd64, kernel 6.18.58.1-microsoft-standard-WSL2, go1.27.4. Calibration 9.768 ms.
Search — 20000 vectors × 128 dims in 100 topics; 1000 timed queries × 5 sequential rounds for latency, 4 clients for QPS.
| Scenario | Answered by | p50 ms | p95 ms | p99 ms | QPS | recall@10 |
|---|---|---|---|---|---|---|
fts-bm25 |
bm25 | 0.408 | 0.532 | 0.712 | 8103 | — |
vector-flat |
flat | 0.973 | 1.245 | 3.527 | 3014 | 1.000 |
vector-hnsw |
hnsw | 0.438 | 0.560 | 0.665 | 8591 | 1.000 |
vector-ivf |
ivf | 0.786 | 1.112 | 1.401 | 4933 | 1.000 |
vector-pq |
pq | 3.078 | 3.540 | 5.513 | 1168 | 0.829 |
vector-opq |
opq | 3.033 | 3.500 | 5.430 | 1204 | 0.803 |
vector-sq |
sq | 4.818 | 6.218 | 7.454 | 817 | 1.000 |
vector-sq4 |
sq4 | 5.574 | 6.860 | 7.857 | 730 | 1.000 |
vector-bq |
bq | 1.711 | 2.398 | 4.153 | 2191 | 1.000 |
vector-auto |
hnsw | 0.447 | 0.564 | 0.704 | 9203 | 1.000 |
hybrid-rrf-hnsw |
— | 0.581 | 0.747 | 1.104 | 6044 | — |
hybrid-rrf-flat |
— | 1.211 | 1.773 | 4.112 | 2499 | — |
filtered-hnsw-1pct |
hnsw | 1.232 | 1.674 | 2.326 | 3264 | 1.000 |
filtered-hnsw-2pct |
hnsw | 1.321 | 2.003 | 2.718 | 3253 | 1.000 |
filtered-hnsw-10pct |
hnsw | 1.746 | 2.968 | 4.241 | 2423 | 1.000 |
filtered-hnsw-25pct |
hnsw | 2.869 | 4.067 | 5.327 | 1449 | 1.000 |
filtered-hnsw-50pct |
hnsw | 1.352 | 2.071 | 2.942 | 2455 | 1.000 |
filtered-auto-1pct |
flat+prefilter | 0.395 | 0.512 | 0.715 | 9846 | 1.000 |
filtered-auto-2pct |
flat+prefilter | 0.482 | 0.636 | 0.839 | 8420 | 1.000 |
filtered-auto-10pct |
ivf | 0.645 | 0.889 | 1.291 | 6146 | 1.000 |
filtered-auto-25pct |
ivf | 0.942 | 1.270 | 2.012 | 3863 | 1.000 |
filtered-auto-50pct |
hnsw | 1.298 | 1.785 | 2.723 | 2541 | 1.000 |
| Ingest | Documents | Batch | Embedding | docs/s | request p50 ms | p95 ms | p99 ms |
|---|---|---|---|---|---|---|---|
single-none |
1000 | 1 | none | 229 | 4.322 | 5.601 | 6.343 |
batch-none |
10000 | 1000 | none | 6183 | 630.716 | 646.566 | 646.566 |
single-lexical |
1000 | 1 | lexical | 185 | 5.307 | 6.814 | 7.667 |
batch-lexical |
10000 | 1000 | lexical | 692 | 5917.554 | 6106.052 | 6106.052 |
| Mixed load, start-up and recovery | Value |
|---|---|
| Mixed (4 readers, 1 writer, 10 s): search p50 / p95 / p99 | 0.436 / 0.718 / 0.988 ms |
| Mixed: searches per second | 8557 |
| Mixed: write p50 / p95 / p99 | 7.619 / 9.540 / 11.156 ms |
| Mixed: writes per second | 128 |
| Clean restart of the search node: process start to healthy | 0.089 s |
| Clean restart of the search node: process start to every vector index answering | 316.156 s |
| Clean restart: process start to each index's first answer | flat 3.2 s, hnsw 3.2 s, ivf 316.1 s, pq 316.1 s, opq 316.1 s, sq 316.1 s, sq4 316.2 s, bq 316.2 s |
| Peak resident memory of the search node | 419.1 MiB |
| kill -9 under write: acknowledged writes / lost after restart | 773 / 0 |
| kill -9 under write: process start to ready | 0.076 s |
| Same node, clean restart: process start to ready | 0.070 s |
| Replication lag, 50 probes under 20 writes/s: p50 / p95 / p99 | — (no probe arrived) |
| Replication: probes not on the follower within 30 s | 50 of 50 |
| Follower catch-up after missing 5000 documents: process start to in sync | not in sync after 180 s |
| Follower checksum and document count equal the leader's | false |
| Follower out of sync | catching up after its downtime: follower has 5601 documents (checksum 21b4cfbf), leader 6601 (checksum 21b4cfbf) after 3m0s |
What this baseline shows, before the 2.19.8 index and replication work:
- Start-up is training. A restart is healthy in under 0.1 s and flat and HNSW answer about 3 s later, but the trainable indexes train again from scratch before their first answer — over five minutes here, almost all of it OPQ, which trains on one core.
- PQ and OPQ lose neighbours at 20k vectors (recall@10 0.83 and 0.80, OPQ below PQ); every other algorithm finds the exact top 10.
- The follower does not keep up on disk. Under 20 single-document writes
a second none of the 50 lag probes reached the follower within 30 s, and
three minutes after a restart it still lacked 1,000 of the 5,000 documents
written while it was down — while
/v1/checksumreturned the same checksum on both sides. - kill -9 lost nothing: every acknowledged write was there after the restart.
Retrieval quality on the MDDB docs #
The latency tables above say how fast each algorithm is. This section says how
often it finds the right page. The set is
tools/bench/evalsets/docs.json: 20
questions about MDDB, each with the documentation page that answers it, graded
0–3. The questions are phrased the way a user asks, not copied from headings.
The collection is the 60 pages of docs/, keyed by file name.
Measured 2026-10-29 on a default-configured server built from this release.
Embeddings came from nomic-embed-text through Ollama, autodetected.
mddb-cli eval docs --queries tools/bench/evalsets/docs.json \
--config fts/bm25 --config fts/bm25f --config fts/tfidf --config fts/pmisparse \
--config vector --config hybrid
| Configuration | recall@10 | nDCG@10 | MRR | p50 ms | p99 ms |
|---|---|---|---|---|---|
| fts/bm25 | 0.825 | 0.739 | 0.723 | 0.9 | 1.9 |
| fts/bm25f | 0.825 | 0.739 | 0.723 | 0.8 | 1.2 |
| fts/tfidf | 0.800 | 0.496 | 0.405 | 1.0 | 1.1 |
| fts/pmisparse | 0.800 | 0.574 | 0.535 | 0.9 | 33.6 |
| vector | 0.875 | 0.763 | 0.750 | 20.1 | 44.2 |
| hybrid (alpha 0.5) | 0.875 | 0.783 | 0.765 | 10.7 | 17.3 |
- Hybrid ranks best. It finds as many pages as vector search and puts the answer higher: its MRR is 0.765, against 0.723 for BM25.
- TF-IDF finds the pages but ranks them badly. Its recall is close to BM25, but its MRR is about half.
- BM25F equals BM25 here. These documents have no separate title field to weight.
- Some questions share no words with their answer. "import a million documents in the background" should find the bulk-import page. Keyword search misses it and vector search finds it. Those questions are where vector search earns its latency.
- Two questions defeat every configuration. These are "call my endpoint when a document changes" (automations) and "which documents are read most often" (temporal tracking). The pages never use the asker's words. That points at the pages, not at the search.
- Returned tokens are large because every result is a whole page. With
format: passagesan agent receives a fraction of that.
The same set runs in CI with keyword search only. The test is
TestEval_DocsSetHoldsTheLine in services/mddbd/eval_docs_test.go. It fails
when recall@10 drops under 0.7 or nDCG@10 under 0.65. The test server there
scores 0.750 and 0.683, because it does not use a default server's
configuration.
BM25 parameters on the MDDB docs #
Same corpus and the same 20 questions as above, keyword search only. Only the BM25 parameters change. Measured 2026-10-29 with:
mddb-cli eval docs --queries tools/bench/evalsets/docs.json \
--config fts/bm25 --config fts/bm25:k1=1.2:b=0.3 --config fts/bm25:k1=0.6:b=0.75 \
--config fts/bm25:k1=2:b=0.75 --config fts/bm25:b=0
| k1 | b | recall@10 | nDCG@10 | MRR |
|---|---|---|---|---|
| 1.2 | 0.75 (default) | 0.825 | 0.739 | 0.723 |
| 1.2 | 0.3 | 0.825 | 0.685 | 0.660 |
| 0.6 | 0.75 | 0.825 | 0.676 | 0.644 |
| 2.0 | 0.75 | 0.825 | 0.749 | 0.731 |
| 1.2 | 0 | 0.800 | 0.523 | 0.438 |
- Recall barely moves. The parameters change the order, not what is found.
- Length normalisation matters here. These pages run from 39 to almost 20,000
words, and with
b = 0the long pages win on repetition alone. - The textbook advice points the wrong way. It suggests a lower
bfor short questions, but here it made ranking worse. The one gain came from a higherk1, a small one. - Why the advisor works only from measurement. It tries
b = 0.3,k1 = 0.6andk1 = 2on a collection's own evaluation set. It recommends a variant only when that variant scores better. There are no thresholds on document length behind it.
Finding code: grep and read vs MDDB passages #
An agent asked to change something first has to find it. This compares the two ways it can, on the MDDB repository itself. The comparison counts tokens and tool calls. It does not measure answer quality.
The 15 tasks are in
tools/bench/evalsets/agent-tasks.json.
Each has a question, the term an agent would grep for first, and the file
that holds the code.
- grep + read (best) greps the tracked files, which is what ripgrep searches. Output is capped at 250 lines, as agent grep tools cap it. Then it reads only the answer file. This is a lower bound, because it assumes the agent picks the right file first.
- grep + read (typical) greps the same way, then reads the matching files with the most matches first until it reaches the answer.
- mddb makes one search that returns passages (
format: passages, 5 results). The answer counts as found when a passage comes from the answer file.
Measured 2026-10-29 on this release. The collection was made with
mddb-cli autoindex . from the repository root: 1491 files, 14.5 MB.
Embeddings came from nomic-embed-text through Ollama. Tokens are bytes
divided by 4.
cd ../../../../tools/bench
go run ./agent -url http://localhost:11023 -collection mddb -root ../.. \
-tasks evalsets/agent-tasks.json -search vector
| Route | Tokens, 15 tasks | Tool calls | Answer reached |
|---|---|---|---|
| grep + read (best) | 139,959 | 28 | 13/15 |
| grep + read (typical) | 2,769,973 | 133 | 13/15 |
| mddb vector, passages | 84,977 | 15 | 13/15 |
| mddb hybrid, passages | 41,666 | 15 | 10/15 |
| mddb fts, passages | 56,284 | 15 | 6/15 |
- Vector passages match grep on answers found. They use 0.6× the tokens of grep's best case and about 3% of its typical case. They take one call per task. Grep takes two in its best case and up to 33 in its typical case.
- Grep's typical case is expensive because common terms match widely. "revision" matches about 160 tracked files, so reading the most-matched files first takes 21 reads before the answer.
- Full-text passages miss most of these questions. The questions are
phrased as a person asks them, and the code does not use the same words.
One question starts with
--fail-below, which the full-text parser reads as an exclusion, so it returns nothing. - Hybrid sits between the two here. On this set it is pulled down by the
full-text half. Run
mddb-cli evalon your own questions before picking one, as shown in Measuring Instead of Guessing. - Two tasks defeat grep. For "include paths" and "cross-collection text search", the first term an agent would try is not in the answer file.
The tool prints per-task rows as well, and -json writes them for further
processing.
Symbol lookup: heuristics vs language-server facts (v2.19.3) #
Before a refactor an agent asks code_symbol where a symbol is used. This
measures how often that answer is right, with and without the facts
mddb-cli autoindex --semantic sends, and what the facts cost.
Method. Two collections are made from the same tree, one with
autoindex and one with autoindex --semantic. The ground truth comes from
the language server directly, not through MDDB: the lspindex driver's local
test writes every definition, reference and implementation it is told, for
exactly the files autoindex --dry-run lists. For WAL.Close the truth agrees
line for line with gopls references run by hand (55 of 55). From the truth,
50 definitions are drawn with seed 13, outside test files: 40% functions, 40%
methods whose bare name another definition shares (Close), 20% interfaces
(Python and PHP have none here; their places go to functions and methods).
Each is asked of both collections as an agent changing it would:
GET /v1/symbol?name=<bare name>&path=<its file>&include=references,implementations&limit=200.
A reference counts when its document and line are in the truth; the
definition's own line is left out of both. References labelled with another
definition (target) are not this symbol's answer and are not counted.
Tokens are the response's bytes divided by 4. Latency is 5 runs of each
lookup on a 32-core machine that was running other work (load 4–10).
Corpora: services/mddbd at 184006a9 (Go, 1,349 files, gopls 0.24.0);
clients/python and integrations/langchain-mddb (Python, 14 files,
basedpyright 1.40.2); services/php-extension and
integrations/wordpress-plugin (PHP, 39 files, phpactor 2026.10.07). The
Python and PHP trees are small, so their numbers say less than Go's.
# 1. the server and the two collections
mddb-cli autoindex services/mddbd -c go-heur
mddb-cli autoindex services/mddbd -c go-sem --semantic=go
mddb-cli --json autoindex services/mddbd -c go-heur --dry-run > plan.json
python3 -c 'import json; [print(p["path"]) for p in json.load(open("plan.json"))["plan"] if p.get("language") == "go"]' > files.txt
# 2. the truth, straight from the language server (local test, needs gopls)
cd services/mddb-cli/internal/lspindex
LSPREAL_DIR=$PWD/../../../mddbd LSPREAL_LANG=go LSPREAL_FILES=$OLDPWD/files.txt \
LSPREAL_OUT=$OLDPWD/go-truth.json go test -tags lspreal -run 'TestRealDir$' .
# 3. the comparison, the facts' size and the search regression
cd ../../../../tools/bench
go run ./codesymbol -url http://localhost:11023 -heuristic go-heur -semantic go-sem \
-truth ../../go-truth.json -queries evalsets/docs.json,evalsets/agent-tasks.json
Python and PHP the same way, from the repository root with
--include 'clients/python/<strong>' --include 'integrations/langchain-mddb/</strong>'
(--include 'services/php-extension/<strong>' --include 'integrations/wordpress-plugin/</strong>')
and LSPREAL_LANG=python (php).
| Language | Symbols | Mode | Reference precision | Reference recall | Exactly right | Implementations right | Tokens (median) | p50 / p95 ms |
|---|---|---|---|---|---|---|---|---|
| Go | functions (20) | heuristic | 92.3% (108/117) | 99.1% (108/109) | 18 | 20 | 218 | 212 / 261 |
| Go | functions (20) | semantic | 92.4% (109/118) | 100% (109/109) | 19 | 20 | 273 | 178 / 214 |
| Go | ambiguous methods (20) | heuristic | 4.4% (30/681) | 58.8% (30/51) | 2 | 20 | 1144 | 267 / 371 |
| Go | ambiguous methods (20) | semantic | 100% (51/51) | 100% (51/51) | 20 | 20 | 385 | 228 / 318 |
| Go | interfaces (10) | heuristic | 99.6% (275/276) | 90.2% (275/305) | 8 | 0 | 236 | 203 / 287 |
| Go | interfaces (10) | semantic | 100% (275/275) | 90.2% (275/305) | 9 | 10 | 1351 | 173 / 246 |
| Go | all 50 | heuristic | 38.5% (413/1074) | 88.8% (413/465) | 28 | 40 | 374 | 221 / 357 |
| Go | all 50 | semantic | 98.0% (435/444) | 93.5% (435/465) | 48 | 50 | 385 | 186 / 309 |
| Python | all 50 | heuristic | 57.8% (93/161) | 70.5% (93/132) | 24 | 50 | 179 | 4.7 / 7.9 |
| Python | all 50 | semantic | 100% (132/132) | 100% (132/132) | 50 | 50 | 223 | 4.4 / 8.1 |
| PHP | all 50 | heuristic | 84.2% (144/171) | 91.7% (144/157) | 40 | 50 | 253 | 8.0 / 12.3 |
| PHP | all 50 | semantic | 100% (157/157) | 100% (157/157) | 50 | 50 | 254 | 7.0 / 10.2 |
- Methods are where the heuristics fail. A bare name such as
CloseorStringmatches every type's method of that name: 681 lines returned for 51 true ones. The facts answer per definition. - Every answer the facts gave was right. 49 of the 50 Go answers carry
precision: semantic, and all 435 of their references are in the truth. The one wrong answer isinitinproto/mddb.pb.go: that generated file has 3,581 fact values, overMDDB_CODE_MAX_FACTS(2048), so the server kept the first 2048 definitions and dropped the rest,initamong them. The lookup then fell back to the heuristics (precision: heuristic) and returned 9 lines of otherinitfunctions. Only that file is over the limit in this tree. Indexed again withMDDB_CODE_MAX_FACTS=4096, nothing is cut, all 50 answers are semantic and precision is 100% (435/435); the largest document's facts then take 246 KB. 2.19.3 ships with 4096 as the default for that reason: the limit protects reads of very large files, and at 4096 it still does, while cutting none of this tree. - The first run found three bugs. Before they were fixed (in this
release), the semantic collection scored 39.3% (435/1107): with a path,
interface methods and methods past the scanner's 512-name
definescap were not looked up in the facts, and the heuristic fallback in a document with facts counted the definition's own lines as uses. A namespaced PHP class was not found by its short name. The table is after the fixes. - Recall below 100% is the limit, not the facts.
MDDBServerhas 230 references and a lookup returns at most 200 per relation. Without it, semantic recall is 235/235 and heuristic 213/235. - "References" means what the language server means. gopls counts a call
through an interface the method satisfies: 46 of WAL.Close's 55
references are
resp.Body.Close()and the like, throughio.Closer. - Implementations come only from facts. The heuristics return none; the
facts returned the truth's count for every symbol, and
backupTarget3,chunkIndexer4.
What the facts cost. Go, services/mddbd unless noted, with no
embedding provider running. The machine was busy with other work (load
5–50), so timings vary by ±20% between identical runs; both runs are given
where there were two.
| Measure | Without --semantic |
With --semantic=go |
|---|---|---|
autoindex wall time |
26 s | 171–194 s |
| of which gopls (load, documentSymbol, references, implementations) | — | 143–167 s |
| gopls peak RSS (VmHWM) | — | 3.3–5.3 GB |
| Collection file (per-collection layout) | 205–209 MB | 263–273 MB |
sym* meta per code document: median / p99 / max |
— | 1,216 B / 9,232 B / 155,740 B |
Documents over 64 KiB of facts / cut at MDDB_CODE_MAX_FACTS |
— | 3 / 1 (all generated: mddb.pb.go, generated.go, mddb_grpc.pb.go) |
code_symbol p50 / p95 over the 50 lookups |
221 / 357 ms | 186 / 309 ms |
| Whole repository (2,593 files, 1,537 Go) | 144 s | 255 s, gopls 160 s, 4.7 GB |
--semantic-concurrency |
gopls time | gopls peak RSS |
|---|---|---|
| 1 | 157 s | 3.9 GB |
| 4 (default) | 149 s, 167 s | 3.7 GB, 3.3 GB |
| 8 | 161 s, 145 s | 3.8 GB, 3.3 GB |
Concurrency changes neither time nor memory beyond the noise: gopls spends
the time checking packages, which it parallelises itself, not waiting on
requests. The default stays at 4. --semantic-memory-mb passes gopls a
memory limit; its effect was not measured. Python and PHP took 2.5 s and 5.7 s; the RSS the
driver reports for basedpyright (12 MB) is the Python launcher's, not the
Node.js server it starts, so it is left out.
Search does not change. The 50 queries of the two evaluation sets
(evalsets/docs.json, SRCH-019; evalsets/agent-tasks.json) were run with
/v1/fts and /v1/hybrid-search (top 10) against each pair of collections,
after normalizing what differs between two identical requests: the
collection name, scores past the ninth decimal, the order of equal scores,
and the results tied at the cut. The first row adds -baseline <URL of a 2.19.2 server holding the same collection>.
| Compared | FTS | Hybrid |
|---|---|---|
| 2.19.2 vs 2.19.3, collection without facts (Go, Python, PHP) | 50/50 byte-identical | 50/50 byte-identical |
| without facts vs with facts, 2.19.3 (Go, Python, PHP) | 50/50 same results | 50/50 same results |
With facts the documents, lines, scores and order are the same; what
differs is the passage's symbol label, which names the definition by its
qualified name (FakeClient.SearchAdvisor for SearchAdvisor) in 27–41 of
the 50 answers.
Relevance feedback #
How much one round of positive and negative examples recovers on a vector
search (SRCH-015). The corpus is synthetic and built for the case feedback is
for. It has 2,000 documents in 20 topics, at 64 dimensions. Each query means
one topic but is typed half way towards another, so a plain search returns a
mix. The answers are the 10 documents nearest what the query meant. Each
query is searched once and its top 10 is judged against those answers. The
right results go back as positive and the wrong ones as negative, and the
search runs again in each mode.
Measured 2026-10-29 on an AMD Ryzen 9 7950X (WSL2), against a server built
from this release, flat index, topK 10, default oversample:
MDDB_EMBEDDING_PROVIDER=openai MDDB_EMBEDDING_API_KEY=bench \
MDDB_EMBEDDING_API_URL=http://127.0.0.1:11099/v1 MDDB_EMBEDDING_DIMENSIONS=64 mddbd &
cd tools/bench && go run ./feedback -url http://localhost:11023 -queries 200 -seed 1
| Feedback | recall@10 seed 1 | seed 2 | seed 3 | p50 ms | p99 ms |
|---|---|---|---|---|---|
| none | 0.305 | 0.298 | 0.325 | 0.4 | 1.0 |
query (Rocchio 1 / 0.75 / 0.25) |
0.491 | 0.490 | 0.503 | 0.5 | 1.4 |
rescore (weight 0.5) |
0.478 | 0.469 | 0.480 | 0.5 | 1.0 |
- One round lifts recall@10 from about 0.31 to about 0.49. That is 60% more of the right documents, and the agent rewrote nothing.
queryis slightly better thanrescorehere, and costs the same.rescorecan only reorder the 30 candidates the index returned, whilequerysearches again from a better starting point.rescoreis for when the query vector must stay as it is.- Latency barely moves. Resolving the example keys and one vector operation add about 0.1 ms at the median.
- This corpus favours feedback. The bench serves its own OpenAI-compatible embeddings, so the numbers are reproducible but not representative of a real embedding model. Read them as what the mechanism can recover, not as what every collection will gain.
Late interaction over chunks: the SRCH-004 spike #
MDDB stores a document as one vector per chunk (keys docID#N) and scores
it by its best chunk against one vector of the whole query. Late interaction
(ColBERT's MaxSim) scores many query vectors against many document vectors.
The cheap variant tested here needs no new storage. It splits the query into
parts and embeds each part. A document's score is the mean, over the parts,
of each part's best chunk. Mean and sum give the same order, because every
document is scored against the same number of parts.
Two ways of splitting were tried:
- clauses: split at punctuation and at "and". A part of one word joins the part before it, and a query with nothing to split stays whole.
- 4-word windows: overlapping windows of 4 words, one every 2 words.
Each split was also tried with the whole query added as one more part. best part is a control, not MaxSim. It scores a document by its best part instead of the mean, which makes it multi-query fusion. It shows whether a change comes from splitting the query or from summing over the parts.
The server was not changed. The tool, tools/bench/maxsim,
reads each chunk's similarity to a query part through the existing API. It
calls vector search with retrievalMode: "chunk", the flat index and a
topK above the chunk count, and does the aggregation itself. The vector
and hybrid rows come from POST /v1/eval with per-query details. Every row
is scored by the same function, which uses the formulas from
services/mddbd/eval.go.
There are two query sets:
- plain: the 20 questions of
docs.json. - multi-topic: every pair of those questions joined with "and", 190 queries. Both answer pages count as relevant. One query vector has to sit between two topics here, which is the case MaxSim is supposed to help.
Δ is the difference from max, whole query, which is today's scoring computed on the same client path, so the difference is the aggregation alone. The interval is a paired bootstrap, 2,000 resamples of the queries. A second seed moved no bound by more than 0.006. "better / worse" counts the queries whose nDCG@10 rose or fell.
Measured 2026-10-29 on an AMD Ryzen 9 7950X (WSL2, Go 1.27.3, Ollama 0.33.3).
The server was built from this release, using nomic-embed-text through
Ollama, the default chunk size of 1,500 characters (891 chunks over the 60
pages), and the embedding cache off so that every part costs one embedding
call:
MDDB_EMBEDDING_PROVIDER=ollama MDDB_EMBEDDING_CACHE_SIZE=0 mddbd &
cd tools/bench && go run ./maxsim -url http://localhost:11023 -load -docs ../../docs
Plain set, 20 queries
| Scoring | recall@10 | nDCG@10 | MRR | Δ nDCG [95% CI] | better / worse | embed calls | p50 ms | p99 ms |
|---|---|---|---|---|---|---|---|---|
| vector (server) | 0.875 | 0.741 | 0.722 | +0.000 [+0.000, +0.000] | 0 / 0 | 1.0 | 11.8 | 52.8 |
| hybrid (server) | 0.875 | 0.814 | 0.806 | +0.073 [−0.026, +0.177] | 6 / 2 | 1.0 | 12.2 | 20.0 |
| max, whole query | 0.875 | 0.741 | 0.722 | — | — | 1.0 | 146.2 | 157.6 |
| maxsim, clauses | 0.875 | 0.750 | 0.722 | +0.008 [−0.003, +0.028] | 1 / 1 | 1.3 | 147.5 | 430.3 |
| maxsim, 4-word windows | 0.925 | 0.723 | 0.690 | −0.018 [−0.121, +0.079] | 4 / 5 | 3.0 | 483.1 | 813.4 |
| maxsim, whole + clauses | 0.875 | 0.744 | 0.722 | +0.002 [−0.003, +0.010] | 1 / 1 | 1.5 | 147.5 | 587.5 |
| maxsim, whole + windows | 0.925 | 0.739 | 0.704 | −0.003 [−0.076, +0.069] | 3 / 5 | 4.1 | 627.4 | 959.5 |
| best part, clauses (control) | 0.850 | 0.711 | 0.689 | −0.030 [−0.079, +0.000] | 0 / 2 | 1.3 | 147.5 | 430.3 |
Multi-topic set, 190 queries
| Scoring | recall@10 | nDCG@10 | MRR | Δ nDCG [95% CI] | Δ recall [95% CI] | better / worse | embed calls | p50 ms | p99 ms |
|---|---|---|---|---|---|---|---|---|---|
| vector (server) | 0.736 | 0.602 | 0.760 | −0.002 [−0.005, +0.000] | −0.005 [−0.013, +0.000] | 0 / 2 | 1.0 | 12.9 | 28.3 |
| hybrid (server) | 0.754 | 0.609 | 0.732 | +0.006 [−0.025, +0.037] | +0.014 [−0.015, +0.043] | 80 / 73 | 1.0 | 12.7 | 22.0 |
| max, whole query | 0.741 | 0.603 | 0.760 | — | — | — | 1.0 | 153.3 | 260.2 |
| maxsim, clauses | 0.663 | 0.481 | 0.575 | −0.123 [−0.147, −0.098] | −0.078 [−0.112, −0.044] | 32 / 128 | 2.5 | 299.6 | 724.4 |
| maxsim, 4-word windows | 0.685 | 0.440 | 0.464 | −0.164 [−0.191, −0.135] | −0.056 [−0.090, −0.019] | 30 / 141 | 7.5 | 1173.6 | 1629.0 |
| maxsim, whole + clauses | 0.708 | 0.528 | 0.635 | −0.076 [−0.098, −0.055] | −0.032 [−0.065, −0.000] | 37 / 108 | 3.5 | 461.0 | 878.5 |
| maxsim, whole + windows | 0.696 | 0.475 | 0.534 | −0.128 [−0.154, −0.102] | −0.045 [−0.078, −0.013] | 31 / 130 | 8.5 | 1330.3 | 1781.8 |
| best part, clauses (control) | 0.783 | 0.655 | 0.765 | +0.051 [+0.023, +0.080] | +0.042 [+0.005, +0.079] | 101 / 58 | 2.5 | 299.6 | 724.4 |
The server rows give the server's own latency from /v1/eval. The other rows
give client round trips, one after another, one per part. Each round trip
returns all 891 chunks as JSON, about 150 ms, so those rows show only how
latency grows with the number of parts. They are not what a server-side
implementation would cost. That cost would be one embedding call per part,
about 10 ms each with this model, plus one flat pass over the chunks per
part. On the plain set the client path returns the same top 10 as the
server's vector search on 19 of 20 queries, and on 175 of 190 multi-topic
queries. The difference comes from the server's parent mode: it collapses an
oversampled chunk list into documents and can then return fewer than 10.
- MaxSim makes multi-topic queries worse, well beyond the noise. Every split loses 0.08 to 0.16 nDCG@10, and every interval lies entirely below zero. The mean over the parts rewards a page that is moderately close to both topics over the two pages that each answer one of them. ColBERT's MaxSim assumes that one document answers the whole query. In a query that joins two needs, that assumption is false.
- On plain questions it changes nothing measurable. Clause splitting rarely finds anything to split (1.3 parts per query). Windows find one more page in recall but rank worse, and every interval spans zero.
- The gain on multi-topic queries comes from splitting, not from summing. The best-part control gains +0.051 nDCG@10 [+0.023, +0.080] and +0.042 recall. It loses 0.030 on plain questions, with an interval that touches zero. That is multi-query fusion, which is query decomposition and not late interaction. If it is pursued, it needs its own ticket and its own measurements.
- Hybrid stays the strongest single-call option on plain questions (+0.073 nDCG@10, though 20 queries cannot separate it from noise).
Verdict: no-go for MaxSim over the existing chunks. The full variant, with token-level vectors, is deferred. None of the supported embedding providers returns token vectors today:
- OpenAI
/v1/embeddingsreturns one vector per input (API reference). - Ollama
/api/embedreturns one vector per input and has no per-token option (API). - Voyage returns one vector per input. Its contextualized chunk embeddings
(
voyage-context-4) are also one vector per chunk (embeddings, contextualized). - Cohere
embedreturns one vector per input (API reference).
Storing token vectors for this corpus would take about 279,000 tokens. That assumes 4 bytes per token and a 128-dimension ColBERT-style model. Today the corpus takes 891 × 768 × 4 B = 2.7 MB. The token vectors would take:
| Format | Bytes per token | Corpus | vs today |
|---|---|---|---|
| float32 | 512 | 143 MB | 52× |
| SQ (int8) | ~141 | 39 MB | 14× |
| SQ4 (int4) | ~77 | 21 MB | 7.8× |
| BQ (1 bit) | 16 | 4.5 MB | 1.6× |
The SQ and SQ4 overheads come from the per-vector calibration listed in QUANTIZATION. The BQ figure assumes no per-vector overhead, which has not been measured.
Query decomposition #
SRCH-020 turns the spike's best-part control into a server option:
queryDecomposition: "auto" on vector and hybrid search
(SEARCH).
The same tool, tools/bench/maxsim,
now also measures four server rows through POST /v1/eval: vector and hybrid
search, each without and with queryDecomposition: "auto". A row with
decomposition is compared with the same search without it. Two client rows
compare the fusions on the same parts: best part, whole + clauses ≤4 is
what the server ships, and rrf, whole + clauses ≤4 sums 1/(60 + rank)
instead. The query sets, the bootstrap and the seed are those of the spike.
Measured 2026-10-30 on the same machine (AMD Ryzen 9 7950X, WSL2, Go 1.27.3,
Ollama 0.33.3, nomic-embed-text). The 60 pages of docs/ gave 937 chunks.
The embedding cache was off, so every part costs one embedding call.
| Set | Search | nDCG@10 | Δ nDCG [95% CI] | Δ recall@10 [95% CI] | better / worse | embed calls | p50 / p99 ms |
|---|---|---|---|---|---|---|---|
| plain, 20 | vector | 0.756 | — | — | — | 1.0 | 9.6 / 54.8 |
| plain, 20 | vector, auto | 0.756 | −0.001 [−0.002, +0.000] | +0.000 [+0.000, +0.000] | 0 / 1 | 1.5 | 9.1 / 43.3 |
| plain, 20 | hybrid | 0.813 | — | — | — | 1.0 | 8.8 / 13.3 |
| plain, 20 | hybrid, auto | 0.810 | −0.003 [−0.010, +0.000] | +0.000 [+0.000, +0.000] | 0 / 1 | 1.5 | 9.9 / 34.0 |
| multi-topic, 190 | vector | 0.597 | — | — | — | 1.0 | 16.7 / 46.0 |
| multi-topic, 190 | vector, auto | 0.662 | +0.065 [+0.046, +0.085] | +0.071 [+0.043, +0.100] | 83 / 37 | 3.5 | 36.2 / 106.9 |
| multi-topic, 190 | hybrid | 0.600 | — | — | — | 1.0 | 11.0 / 23.1 |
| multi-topic, 190 | hybrid, auto | 0.647 | +0.047 [+0.030, +0.066] | +0.046 [+0.024, +0.069] | 53 / 15 | 3.5 | 38.7 / 62.3 |
Latency is the server's own, from /v1/eval.
Fusion, on the client path (Δ against max, whole query):
| Set | Fusion over whole + clauses ≤4 | Δ nDCG [95% CI] |
|---|---|---|
| plain | max (ships) | −0.001 [−0.002, +0.000] |
| plain | RRF | +0.024 [+0.000, +0.062] |
| multi-topic | max (ships) | +0.065 [+0.046, +0.085] |
| multi-topic | RRF | −0.250 [−0.280, −0.218] |
A similarity gate between the parts was measured outside the tool. The
parts were embedded with Ollama (search_query: prefix, as the server
does), and the whole query and the parts were scored on the client path.
auto would split only when the lowest cosine between two parts fell below
the threshold. This sweep did not bound the parts at 4, so its "none" row
differs from the table above by 0.002:
| Gate | plain Δ nDCG | multi-topic Δ nDCG [95% CI] |
|---|---|---|
| none (ships) | −0.001 [−0.002, +0.000] | +0.063 [+0.044, +0.084] |
| cosine < 0.55 | −0.001 [−0.002, +0.000] | +0.059 [+0.040, +0.079] |
| cosine < 0.50 | −0.001 [−0.002, +0.000] | +0.044 [+0.027, +0.063] |
| cosine < 0.45 | +0.000 [+0.000, +0.000] | +0.023 [+0.011, +0.036] |
The lowest cosine between two parts is 0.40–0.66 for the four plain questions that split. On the two-topic queries it is 0.34–0.74, median 0.46. The two ranges overlap, so a gate cannot tell the cases apart.
- The gain is real and survives hybrid. Vector search gains 0.065 nDCG@10 on two-topic questions, and every bound lies above zero. Hybrid gains 0.047, because its full-text half already matched the words of both parts.
- Ordinary questions stay where they were. The interval includes zero. One question of 20 ("log in and get a JWT token, create API keys") loses 0.010; the other 19 are unchanged. The spike's best part without the whole query lost 0.030 [−0.079, 0.000]. Keeping the whole query as one of the searches is what removes that loss.
- Max, not RRF. RRF gains 0.024 on plain questions (2 better, none worse), but loses 0.25 on the two-topic set. Summing ranks rewards a page that is mediocre for both parts, the same flaw as MaxSim's mean.
- No gate. Every threshold lowers the gain on two-topic questions. Only 0.45 removes the 0.001 loss on plain questions, and it gives up two thirds of the gain to do so.
- Cost. 3.5 embedding calls per two-topic query instead of 1. The p50 rises from 17 to 36 ms with Ollama on this machine. A query with nothing to split costs nothing more.
Vector query planner #
Before and after algorithm: "auto" (SRCH-013). Before, a search used flat
unless the caller named an index. After, the planner picks one per query.
The bench loads a synthetic clustered corpus at three sizes. It builds the
indexes before timing anything: HNSW is built as vectors arrive, and IVF is
trained by one search that names it, because the planner never builds on the
query path. Then each size is searched with flat, hnsw, ivf and auto. Each
search runs once without a filter and once with slice=rare, a filter that
admits 2% of the collection. Recall@10 is scored against the exact top 10,
computed by the bench itself. "Ran" is the plan's algorithm from
explain: true.
The first run found three problems, fixed in the same release: HNSW recall was low and unstable, the exact prefilter scanned the whole collection, and the planner's thresholds were not backed by numbers. The tables marked "before the fixes" are that first run. The ones after them are the same bench against the fixed server.
Before the fixes #
Measured 2026-10-29 on an AMD Ryzen 9 7950X (WSL2, 32 GB), against a server
built from this release, with its database on disk. Latency is measured by
the client over HTTP. The corpus has 32 dimensions and 100 topics, and each
search runs 100 timed queries after 5 warmup queries, at topK 10 and
seed 1:
MDDB_EMBEDDING_PROVIDER=openai MDDB_EMBEDDING_API_KEY=bench \
MDDB_EMBEDDING_API_URL=http://127.0.0.1:11098/v1 MDDB_EMBEDDING_DIMENSIONS=32 \
MDDB_EMBEDDING_CHUNK_ENABLED=false MDDB_HTTP_WRITE_TIMEOUT=0 mddbd &
cd tools/bench && go run ./planner -url http://localhost:11023 -sizes 2000,200000,2000000
| Vectors | Filter admits | Load s | IVF train s |
|---|---|---|---|
| 2,000 | 40 (2.0%) | 3 | 0.0 |
| 200,000 | 4,000 (2.0%) | 437 | 57.7 |
| 2,000,000 | 40,000 (2.0%) | 7,020 | 621.2 |
| Vectors | Filter | algorithm | Ran (explain) | recall@10 | p50 ms | p99 ms |
|---|---|---|---|---|---|---|
| 2,000 | none | flat |
flat | 1.000 | 0.42 | 1.10 |
| 2,000 | none | hnsw |
hnsw | 0.862 | 0.82 | 1.70 |
| 2,000 | none | ivf |
ivf | 0.997 | 0.34 | 0.79 |
| 2,000 | none | auto |
flat | 1.000 | 0.42 | 1.24 |
| 2,000 | 2% | flat |
flat | 1.000 | 0.31 | 0.62 |
| 2,000 | 2% | hnsw |
hnsw | 1.000 | 0.89 | 2.31 |
| 2,000 | 2% | ivf |
ivf | 0.543 | 0.29 | 0.76 |
| 2,000 | 2% | auto |
flat + prefilter | 1.000 | 0.32 | 0.66 |
| 200,000 | none | flat |
flat | 1.000 | 22.17 | 56.21 |
| 200,000 | none | hnsw |
hnsw | 0.827 | 2.64 | 3.49 |
| 200,000 | none | ivf |
ivf | 1.000 | 1.65 | 10.37 |
| 200,000 | none | auto |
hnsw | 0.827 | 2.68 | 3.49 |
| 200,000 | 2% | flat |
flat | 1.000 | 6.09 | 44.96 |
| 200,000 | 2% | hnsw |
hnsw | 1.000 | 36.56 | 41.30 |
| 200,000 | 2% | ivf |
ivf | 1.000 | 1.06 | 1.46 |
| 200,000 | 2% | auto |
flat + prefilter | 1.000 | 6.13 | 34.76 |
| 2,000,000 | none | flat |
flat | 1.000 | 245.06 | 978.92 |
| 2,000,000 | none | hnsw |
hnsw | 0.664 | 5.99 | 9.38 |
| 2,000,000 | none | ivf |
ivf | 1.000 | 14.09 | 23.55 |
| 2,000,000 | none | auto |
ivf | 1.000 | 14.22 | 24.20 |
| 2,000,000 | 2% | flat |
flat | 1.000 | 68.24 | 707.40 |
| 2,000,000 | 2% | hnsw |
hnsw | 1.000 | 615.74 | 906.38 |
| 2,000,000 | 2% | ivf |
ivf | 1.000 | 10.24 | 57.48 |
| 2,000,000 | 2% | auto |
flat + prefilter | 1.000 | 79.34 | 834.01 |
What that run showed: HNSW recall of 0.86, 0.83 and 0.66, varying between
loads (0.70 to 0.83 at 200k over three loads); a prefilter that cost what the
collection cost (79 ms at p50 and 834 ms at p99 at 2M for a 2% filter); and
auto choosing HNSW at 200k, giving up 17% of recall against a faster IVF.
The same bench against the same release before the fixes, repeated at 20k and 200k in the session that measured the fixes below. HNSW recall was 0.884 and 0.740 this time:
| Vectors | Filter | algorithm | Ran (explain) | recall@10 | p50 ms | p99 ms |
|---|---|---|---|---|---|---|
| 20,000 | none | flat |
flat | 1.000 | 2.08 | 7.59 |
| 20,000 | none | hnsw |
hnsw | 0.884 | 1.33 | 3.40 |
| 20,000 | none | ivf |
ivf | 1.000 | 0.49 | 0.75 |
| 20,000 | none | auto |
hnsw | 0.884 | 1.38 | 3.90 |
| 20,000 | 2% | flat |
flat | 1.000 | 0.92 | 5.33 |
| 20,000 | 2% | hnsw |
hnsw | 1.000 | 2.20 | 6.49 |
| 20,000 | 2% | ivf |
ivf | 0.792 | 0.39 | 0.79 |
| 20,000 | 2% | auto |
flat + prefilter | 1.000 | 0.92 | 5.57 |
| 200,000 | none | flat |
flat | 1.000 | 19.92 | 50.44 |
| 200,000 | none | hnsw |
hnsw | 0.740 | 2.18 | 2.65 |
| 200,000 | none | ivf |
ivf | 1.000 | 1.42 | 2.08 |
| 200,000 | none | auto |
hnsw | 0.740 | 2.20 | 9.11 |
| 200,000 | 2% | flat |
flat | 1.000 | 5.89 | 45.48 |
| 200,000 | 2% | hnsw |
hnsw | 1.000 | 28.42 | 35.00 |
| 200,000 | 2% | ivf |
ivf | 1.000 | 0.99 | 1.32 |
| 200,000 | 2% | auto |
flat + prefilter | 1.000 | 5.48 | 31.31 |
Loading took 18 s at 20k and 322 s at 200k; HNSW is built as vectors arrive.
After the fixes #
Same machine, settings and command, against the fixed server. 2M was not
re-run: it takes about two hours. -rare-every 10 and -rare-every 4 make
the filter admit 10% and 25%, and -indexes adds sq and sq4 to the
indexes searched by name:
cd tools/bench && go run ./planner -url http://localhost:11023 -sizes 20000,200000
cd tools/bench && go run ./planner -url http://localhost:11023 -sizes 20000,200000 -rare-every 10
cd tools/bench && go run ./planner -url http://localhost:11023 -sizes 200000 -dims 128 -indexes flat,hnsw,ivf,sq,sq4
Loading took 5 s at 20k and 53–59 s at 200k (322 s before), at 32 dimensions; 64–66 s at 200k and 128 dimensions. Training IVF took 1.6 s and 54 s, and 97–105 s at 128 dimensions.
| Vectors | Filter | algorithm | Ran (explain) | recall@10 | p50 ms | p99 ms |
|---|---|---|---|---|---|---|
| 20,000 | none | flat |
flat | 1.000 | 0.75 | 3.97 |
| 20,000 | none | hnsw |
hnsw | 1.000 | 0.35 | 0.68 |
| 20,000 | none | ivf |
ivf | 1.000 | 0.55 | 0.83 |
| 20,000 | none | auto |
hnsw | 1.000 | 0.40 | 0.55 |
| 20,000 | 2% | flat |
flat | 1.000 | 0.41 | 0.99 |
| 20,000 | 2% | hnsw |
hnsw | 1.000 | 1.15 | 1.35 |
| 20,000 | 2% | ivf |
ivf | 0.773 | 0.37 | 0.74 |
| 20,000 | 2% | auto |
flat + prefilter | 1.000 | 0.43 | 1.20 |
| 20,000 | 10% | flat |
flat | 1.000 | 0.72 | 1.79 |
| 20,000 | 10% | hnsw |
hnsw | 1.000 | 1.39 | 3.37 |
| 20,000 | 10% | ivf |
ivf | 1.000 | 0.53 | 1.15 |
| 20,000 | 10% | auto |
ivf | 1.000 | 0.51 | 1.03 |
| 20,000 | 25% | flat |
flat | 1.000 | 1.03 | 2.65 |
| 20,000 | 25% | hnsw |
hnsw | 1.000 | 2.15 | 4.52 |
| 20,000 | 25% | ivf |
ivf | 1.000 | 0.81 | 1.81 |
| 20,000 | 25% | auto |
ivf | 1.000 | 0.79 | 1.93 |
| 200,000 | none | flat |
flat | 1.000 | 5.15 | 23.00 |
| 200,000 | none | hnsw |
hnsw | 1.000 | 0.46 | 0.72 |
| 200,000 | none | ivf |
ivf | 1.000 | 1.59 | 2.82 |
| 200,000 | none | auto |
hnsw | 1.000 | 0.52 | 0.70 |
| 200,000 | 2% | flat |
flat | 1.000 | 1.33 | 2.35 |
| 200,000 | 2% | hnsw |
hnsw | 1.000 | 27.19 | 34.20 |
| 200,000 | 2% | ivf |
ivf | 1.000 | 0.93 | 1.18 |
| 200,000 | 2% | auto |
flat + prefilter | 1.000 | 1.14 | 1.78 |
| 200,000 | 10% | flat |
flat | 1.000 | 4.87 | 9.40 |
| 200,000 | 10% | hnsw |
hnsw | 1.000 | 36.17 | 42.70 |
| 200,000 | 10% | ivf |
ivf | 1.000 | 2.42 | 7.39 |
| 200,000 | 10% | auto |
ivf | 1.000 | 2.52 | 6.40 |
| 200,000 | 25% | flat |
flat | 1.000 | 9.62 | 19.83 |
| 200,000 | 25% | hnsw |
hnsw | 1.000 | 46.36 | 58.93 |
| 200,000 | 25% | ivf |
ivf | 1.000 | 5.16 | 12.71 |
| 200,000 | 25% | auto |
ivf | 1.000 | 5.31 | 12.68 |
At 128 dimensions, 200k vectors (102 MB of float32, under the 256 MB at which
the planner asks for sq). sq and sq4 are named to measure them; they
were trained by their first search, in the warmup:
| Vectors | Filter | algorithm | Ran (explain) | recall@10 | p50 ms | p99 ms |
|---|---|---|---|---|---|---|
| 200,000 | none | flat |
flat | 1.000 | 7.80 | 24.44 |
| 200,000 | none | hnsw |
hnsw | 0.981 | 0.60 | 0.78 |
| 200,000 | none | ivf |
ivf | 1.000 | 1.98 | 2.99 |
| 200,000 | none | sq |
sq | 1.000 | 71.13 | 80.27 |
| 200,000 | none | sq4 |
sq4 | 1.000 | 73.35 | 86.45 |
| 200,000 | none | auto |
hnsw | 0.981 | 0.55 | 0.77 |
| 200,000 | 2% | flat |
flat | 1.000 | 1.16 | 1.78 |
| 200,000 | 2% | hnsw |
hnsw | 1.000 | 28.96 | 41.75 |
| 200,000 | 2% | ivf |
ivf | 1.000 | 1.24 | 4.44 |
| 200,000 | 2% | sq |
sq | 1.000 | 20.04 | 28.85 |
| 200,000 | 2% | sq4 |
sq4 | 1.000 | 19.82 | 38.50 |
| 200,000 | 2% | auto |
flat + prefilter | 1.000 | 1.14 | 1.56 |
A second load at 128 dimensions measured HNSW at 0.990. At 32 dimensions
sq and sq4 also held 1.000 (40 and 42 ms at 200k, unfiltered).
The HNSW graph alone #
In-process, without the server: the 20k corpus inserted topic by topic, as
the bench stores it, and shuffled. 100 queries, built with -tags noasm:
| Graph | M | ef (construction / search) | Order | recall@10 | build | per query |
|---|---|---|---|---|---|---|
coder/hnsw |
16 | 100 / 100 | by topic | 0.939 | 10.9 s | 702 µs |
coder/hnsw |
16 | 100 / 100 | shuffled | 1.000 | 12.9 s | 734 µs |
coder/hnsw |
16 | 200 / 200 | by topic | 0.972 | 22.2 s | 1,410 µs |
coder/hnsw |
32 | 100 / 100 | by topic | 0.998 | 19.4 s | 1,197 µs |
| MDDB | 16 | 200 / 100 | by topic | 1.000 | 2.0 s | 98 µs |
| MDDB | 16 | 200 / 50 | by topic | 1.000 | 2.1 s | 44 µs |
| MDDB | 16 | 200 / 100 | shuffled | 1.000 | 2.4 s | 79 µs |
At 200k the MDDB graph measured 1.000 at efSearch 100, 0.997–0.998 at 50 and 1.000 at efConstruction 100 / efSearch 64, in either order. The library gave the construction search the search beam, so its two ef columns are one number.
Findings #
- HNSW recall was the library's, and the graph is replaced.
coder/hnswkept each node's M nearest candidates as neighbours, without the paper's diversity heuristic. The bench stores documents topic by topic, so each topic's edges to the others were the first evicted, and a search that entered the wrong topic could not leave it. Shuffling the same documents gave the library 1.000 (table above). Its layer 0 also kept M links rather than 2M, its construction ignoredefConstruction(the reasonNewHNSWIndexdropped its second argument), and both its entry point and its levels were random per load, hence 0.70–0.88 between loads. Metric,ef < k, tombstones and chunk keys were checked and were not the cause: the graph orders by cosine as the default metric does, a search's beam is never below k, and both the 20k and 200k corpora are unchunked with nothing deleted. MDDB now has its own graph (internal/vector/vector_hnsw_graph.go): heuristic neighbour selection, 2M links on layer 0, a realefConstruction(200),efSearch64, and levels from a fixed seed. Recall@10 is 1.000 at 20k and 200k and 0.981–0.990 at 128 dimensions. It is 3–5× faster per query than before (0.46 against 2.18 ms at 200k), and loading 200k takes 53 s instead of 322 s. autokeeps HNSW for 10k–1M vectors. The fixed graph beats a trained IVF on both recall and latency: 0.35 against 0.55 ms at 20k and 0.46 against 1.59 ms at 200k, at 1.000 each. Before the fix,autoat 200k gave 0.740–0.827. If HNSW holds nothing for a collection, the planner now falls back to a trained IVF before flat.- The prefilter costs what the filter admits. It looks up the admitted documents' vectors, in parallel, rather than scanning the collection. At 200k and 2% it fell from 5.5–6.1 ms to 1.1 ms at p50, and from 31–35 ms to 1.8 ms at p99. It is still exact. Flat search also keeps its top k in a bounded heap rather than sorting every score: 20 ms → 5 ms at 200k.
- Under 5%, the prefilter; from 5% to a third, a trained IVF. At 2% a
trained IVF was 0.2 ms faster at 200k (0.93 against 1.14 ms), but at 20k it
found 0.773 of the exact top 10. The prefilter is exact, so
autokeeps it. From 10% up, IVF wins at 1.000: 2.4 against 4.9 ms at 10%, 5.2 against 9.6 ms at 25%. HNSW filters after its search and takes 3× the candidates it is asked for. A filter under a third leaves it short, and it then scores the whole collection: 27, 36 and 46 ms at 2, 10 and 25%. Soautosends such a filter to a trained IVF, or to the prefilter when there is none. Above a third, HNSW post-filters as before. - Quantized indexes are a memory choice, not a speed one. At float32
sizes over 256 MB (
sq) and 1 GB (sq4), which 2M vectors reach from 64 dimensions up, the planner asks for a quantized index, by design. On this corpussqandsq4keep recall@10 at 1.000 at 32 and 128 dimensions. They are the slowest indexes measured: 71–73 ms at 200k and 128 dimensions, against 7.8 ms for flat and 0.6 ms for HNSW. They score every vector and sort all the scores before reranking. 2M vectors at 32 dimensions are 244 MiB, just under the threshold, so they stay onivf, as the 2M table shows. - Training is the cost
autowill not pay. IVF takes 54 s to train at 200k (97–105 s at 128 dimensions) and 10 minutes at 2M. Without a trained IVF,autoat 2M falls back to HNSW and says so inreasons. - 2M after the fixes is not measured. The planner still sends more than 1M vectors to IVF. The fixed graph may now beat IVF there, as it does at 200k, but that run takes about two hours.
- The corpus is synthetic. It has 100 Gaussian clusters. Read the recall columns as a comparison between the indexes, not as what a real embedding model will get.
Benchmark tool for measuring MDDB document insertion throughput. Inserts documents in configurable batches, records timing per batch, and generates an HTML report with an SVG chart.
Prerequisites #
- MDDB server running (default
http://localhost:7890) - Go 1.27+
Build #
cd ../../../../tools/bench
go build -o mddb-bench .
Usage #
# Start MDDB
cd services/mddbd
go run . -db /tmp/bench.db
# Run benchmark (default: 10K docs, batches of 100)
cd ../../../../tools/bench
./mddb-bench
# Custom parameters
./mddb-bench -total 5000 -batch 50 -collection mybench -output results.html
# Cleanup collection after benchmark
./mddb-bench -total 1000 -cleanup
Flags #
| Flag | Default | Description |
|---|---|---|
-url |
http://localhost:7890 |
MDDB server URL |
-collection |
bench |
Collection to insert into |
-total |
10000 |
Total documents to insert |
-batch |
100 |
Batch size for timing measurements |
-output |
bench_report.html |
HTML report output path |
-cleanup |
false |
Delete collection after benchmark |
What It Measures #
Each document is a simulated blog post with:
- Random title (3-6 words)
- Random tags (1-3 from a pool of 20)
- Random author
- 2-5 paragraphs of lorem ipsum (~500-2000 characters)
Documents are inserted one-by-one via POST /v1/add. Every batch of N documents is timed and throughput is calculated.
Results (2026-03-06) #
Environment: Darwin 25.3.0 arm64, Go 1.26.0, sequential
POST /v1/add(one doc at a time)
Summary #
| Metric | Value |
|---|---|
| Total documents | 10,000 |
| Total time | 5m 34s |
| Avg throughput | 30 docs/sec |
| Min batch | 11 docs/sec |
| Max batch | 49 docs/sec |
| Batch size | 100 |
Throughput per Batch #
| Docs | docs/sec | Cum. avg | Notes |
|---|---|---|---|
| 100 | 49 | 49 | Cold start, fastest batch |
| 500 | 38 | 41 | |
| 1,000 | 37 | 39 | Stable ~37-39 range |
| 2,000 | 36 | 38 | |
| 2,500 | 22 | 35 | Degradation begins (FTS index growth) |
| 3,000 | 25 | 33 | |
| 4,000 | 11 | 29 | Worst batch — likely BoltDB compaction |
| 5,000 | 24 | 27 | |
| 6,000 | 37 | 27 | Recovery after compaction |
| 7,000 | 37 | 28 | Stabilized ~35-38 |
| 8,000 | 33 | 29 | |
| 9,000 | 35 | 29 | |
| 10,000 | 37 | 30 | Final average: 30 docs/sec |
Throughput Chart #
xychart-beta
title "Insert Throughput (docs/sec per 100-doc batch)"
x-axis ["1K", "2K", "3K", "4K", "5K", "6K", "7K", "8K", "9K", "10K"]
y-axis "docs/sec" 0 --> 55
bar [37, 36, 25, 11, 24, 37, 37, 33, 35, 37]
line [39, 38, 33, 29, 27, 27, 28, 29, 29, 30]
Observations #
- 0-2K docs: Stable ~37-49 docs/sec. BoltDB is small, FTS index fits comfortably.
- 2K-5K docs: Throughput drops to 11-25 docs/sec. FTS token index grows, BoltDB page splits and fsync become expensive.
- 5K-10K docs: Recovery to ~33-38 docs/sec. BoltDB has compacted and stabilized at a larger page count.
- Batch 40 dip (4000 docs): 9.3s for 100 docs (11 docs/sec) — classic BoltDB B+ tree rebalancing spike.
- Each insert includes: JSON decode, BoltDB write, FTS tokenization + index update, revision tracking, checksum computation.
How to Run #
cd ../../../../tools/bench
go build -o mddb-bench .
./mddb-bench -url http://localhost:7890 -total 10000 -batch 100 -output bench_report.html -cleanup
Flags #
| Flag | Default | Description |
|---|---|---|
-url |
http://localhost:7890 |
MDDB server URL |
-collection |
bench |
Collection to insert into |
-total |
10000 |
Total documents to insert |
-batch |
100 |
Batch size for timing measurements |
-output |
bench_report.html |
HTML report output path |
-cleanup |
false |
Delete collection after benchmark |
HTML Report #
The tool also generates a self-contained HTML report with an interactive SVG bar chart, cumulative average trend line, and detailed per-batch table. Open in any browser — no external dependencies.