Skip to content

A labelled document fixture measures knowledge.search retrieval - #193

Merged
zlareb1 merged 25 commits into
mainfrom
bench/knowledge-retrieval-fixture
Nov 3, 2026
Merged

zlareb1 merged 25 commits into
mainfrom
bench/knowledge-retrieval-fixture

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Build/Testing/Packaging Improvement

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

bench/knowledge_retrieval.py measures knowledge.search on a small labelled document corpus: recall@k, MRR and nDCG@10 per query kind.

Why

No bench scores the knowledge plane's document retrieval on its own (NarrativeQA measures answers end to end). Ranking changes to knowledge.search (the lexical leg, fusion, reranking, chunking) need a cheap, repeatable before/after number.

The fixture is synthetic, so it carries no licence or confidentiality question: handbooks of four fictional products that share one heading layout (the product name is in the title, the first heading and its opening paragraph; the other sections never name it), runbooks keyed by error code (the code is in the title and the Symptom section, never in the Resolution), an old and a current version of one policy, other policies, design notes and meeting notes. 21 documents (97 chunks at the default chunk size), 76 answerable queries in five kinds and 5 unanswerable ones:

Kind n What answers it
context 38 a section that never names the subject the query names (the title does)
paraphrase 16 a section mostly in other words than the query's (some share a term or two)
identifier 14 a runbook: "error X" accepts its opening (title and service), Symptom or Resolution (R@k and MRR count any; all-gold and nDCG reward all three), "how do I fix X" only the Resolution
multi 5 a question across the products: every document that answers it (all-gold)
freshness 3 the current policy, not the superseded one (a superseded policy ranked first shows in R@1, MRR and nDCG@10, not R@5)

Two arms compare per query: the docstring says how to pair two --out reports through bench.bootstrap.paired_bootstrap, clustered by the fixture's cluster field, which groups the queries whose results move together: one question asked of each product, and every set of queries that share a gold chunk, merged transitively into 36 clusters over the 76 answerable queries (a unit test rebuilds that partition from the chunker and checks the labels equal it). A label is a (source_uri, answer text) pair, so a hit is relevant when it comes from that document and holds that text; the labels survive a chunker change that keeps each answer inside one chunk (a unit test checks they lie inside one chunk at the default size). The multi and freshness figures rest on five and three queries and are coarse.

First result on main, text-embedding-3-large, default chunking, measured with this head's fixture:

Arm R@1 R@5 R@10 MRR nDCG@10 context MRR identifier R@5 paraphrase R@5
hybrid (default) 0.526 0.776 0.895 0.629 0.610 0.546 0.857 0.688
semantic 0.855 0.987 1.000 0.911 0.916 0.974 0.929 1.000
lexical 0.316 0.566 0.605 0.414 0.398 0.274 0.714 0.500

MRR and nDCG@10 differ per query (a single passage at rank 2 scores 0.5 and 0.63; finding one of two passages leaves nDCG below 1) and only average out close together here.

The default hybrid mode ranks below its own vector leg, most on context queries: the lexical leg scores chunk text only, so a section whose subject is named only in its document's title or heading path is invisible to BM25 (the vector leg embeds the title and breadcrumb with the text), and fusion weights that leg's ranks like the vector leg's. A follow-up changes the lexical leg; this PR only adds the measurement.

Scope and risk

Bench only: a harness, its fixture (the JSONL opens with its provenance header), a README entry and a row in its when-to-run table, a row in the in-house fixtures table of docs/benchmarks/running.md and a unit test. No server code. A default run ingests into a fresh namespace (knowledge-retrieval-run-<random>), registered as a bench namespace and erased when the run ends, so concurrent arms never share one. --phase ingest and --phase search need a --namespace, which is never erased (ingest once, search per arm) and must start with knowledge-retrieval-, the prefix of every namespace the harness writes, so it never registers, fills or prints an erase command for anyone else's namespace (a run's own fresh knowledge-retrieval-run-… namespace cannot be named, so no named run writes into a concurrent one); the ingest prints the loom namespaces-gc command that erases it before anything else. Each report records the server's embedding model, dimension and build, digests of the corpus and the queries, and the namespace's chunk count (instrument), so two reports pair only over one corpus, query set and chunking; an unknown or fake embedder is refused. --param takes only knowledge.search fields and refuses the ones the harness sets (top_k, the metrics are @10; org, namespace, namespaces, namespace_scope, query) and the filters that would score a subset of the corpus as the whole (tags, uri_prefix, since_seconds, session_ids, source_classes), so an identity or transport key the server would drop silently (session_id, explain, traffic_class) is refused too; a field the server still names in ignored_args, a search that finds nothing, a hybrid or lexical arm whose lexical leg never fired (a cold corpus runs the vector leg alone; lexical_fired counts the queries it scored, so a partly degraded arm shows), or a named namespace whose documents are not exactly this fixture's fails the run instead of reporting the default arm, zeros or a stale corpus: each ingested document carries a fixture:<digest> tag of the corpus it came from, and the search phase checks every document's tag and the URI set.

Compatibility, rollout and rollback

  • Wire: none.
  • Operator steps: none.
  • Rollback: revert. A namespace named with --namespace stays until erased with loom namespaces-gc.

Tests

  • pytest tests/unit/test_bench_knowledge_retrieval.py: a fresh ingest erased when the run ends; the embedder and namespace refusals; scoring (a hit counts only from its document and with its text, each gold passage once, one chunk holding two passages, nDCG, misses), parameter parsing and the refused fields, which namespace a run erases, the prefix a named one needs, a kept ingest registering as kept and tagging every upsert, the failed-run checks (nothing found, an ignored field, a namespace holding other documents), the top-hit similarity on answerable and unanswerable queries (over queries with a hit, the rest counted per answerability) and the per-kind means, passage-level nDCG (a hit holding two passages credits both at its rank, capped at 1, so finding them apart and lower never outscores finding them together), and that every gold passage occurs exactly once in its document and inside one chunk at the default size (97 chunks), each passage of a query in a chunk of its own.
  • PYTHONPATH=$PWD .venv/bin/python bench/knowledge_retrieval.py --base-url http://localhost:<port> --namespace knowledge-retrieval-main13 --phase ingest, then --namespace knowledge-retrieval-main13 --phase search --param search_mode=<mode> per arm, against a server from source with text-embedding-3-large: the table above. Two ingests of one fixture version gave identical numbers; a default run's fresh namespace had 0 live chunks after it ended.
  • make format lint, tests/unit/test_public_copy.py, tests/unit/test_doc_links.py.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code; the fixture labels are checked by the unit test and the numbers come from runs against a local server.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

zlareb1 and others added 25 commits November 3, 2026 15:55
bench/knowledge_retrieval.py ingests a small synthetic corpus and scores
knowledge.search per query kind: recall@1/5/10, MRR, nDCG@10, all-gold
recall, and the top-hit score on unanswerable queries. Labels are
(source_uri, answer text) pairs, so they survive a chunker change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…skew its numbers

A default run ingests into its own salted namespace, so two arms never erase
each other's. A search over an empty namespace, a top_k override and a
cross-mode score average are refused or replaced (top-hit similarity). One
chunk holding two gold passages credits both. Fixture: grammatical sentences,
labels that name the fix, more freshness and multi-document queries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Only the fresh namespace a run makes up is erased; --param refuses every field
that defines the measurement; nDCG and all-gold read the one depth constant.
Fixture: the handbook sections no longer name the product outside the opening
section, two queries gain the second document that answers them, and three
template sentences read correctly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…' namespaces alone

A search whose response names ignored_args fails the run; the harness ingests
into a named namespace only when it is unregistered or a bench namespace, and
--phase ingest/search need one. Runbook codes accept the Symptom section, and
the handbook queries that need the title are labelled context.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ery answer

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…that is not the fixture

--param accepts knowledge.search fields alone (identity and transport keys are
dropped by the server without a word); a named namespace whose documents differ
from the fixture's fails the run. Two paraphrase queries no longer repeat their
answer's words; the JSONL carries its provenance header; the fixture is listed in
the in-house fixtures table.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…es another version

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…her documents

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…and guards named namespaces

nDCG's ideal ranking uses the same gains (a hit holding two passages gains 2),
so nothing is capped; a hybrid or lexical arm whose lexical leg never fired
fails; the similarity means count only queries with a hit; a named bench
namespace is written only when all its documents are fixture ingests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ecords its instrument

A named namespace must start with knowledge-retrieval-, which replaces the
owner and listing checks: the harness never registers, fills or prints an
erase command for another namespace. Each report carries the server's
embedding model and build, and a fake embedder is refused.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…of the corpus

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…unt the queries the lexical leg scored

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…says how to pair two arms

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…s the fixture it scored

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…and clusters queries by question

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…uses a valueless param

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…e chunks

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…d as a partition

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…tests chunk as ingest does

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ommitted fixture

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the bench/knowledge-retrieval-fixture branch from bb3e29c to c2462d0 Compare November 3, 2026 15:55
@zlareb1
zlareb1 merged commit 1863610 into main Nov 3, 2026
@zlareb1
zlareb1 deleted the bench/knowledge-retrieval-fixture branch November 3, 2026 15:56
@pufit pufit mentioned this pull request Nov 4, 2026
9 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant