Repository navigation
Hybrid retrieval: BM25 candidates, graph evidence, evidence-based refusal - #52
Draft
Deep-Sixed wants to merge 3 commits into
Draft
Deep-Sixed wants to merge 3 commits into
Deep-Sixed wants to merge 3 commits into
Conversation
Committed first, so the record shows these questions predate the implementation they will evaluate. - bench/heldout-docs.json: 10 answerable + 4 out-of-scope questions written from README sections the contextmesh-docs suite does not ask about (checkpoints, restart, health, re-execution, persistence, dashboard). - bench/heldout-code.json: 10 + 4 over contextmesh_mcp/, a package no other suite reads, written from its raw docstrings. Rules, stated in each suite: never used to choose or calibrate anything, run once to evaluate. Same author as the code, so not independent; questions from someone who has not seen the implementation are wanted. tests/test_bench.py now checks every shipped suite structurally (labels point at real files of the suite's own types, no duplicate questions) without running the held-out ones, and that held-out questions share none with the development suites. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hin evidence contextmesh/hybrid.py (HybridRetriever): - Candidates: BM25 top-k over the graph's live claims only; the index is rebuilt when the build, node count or invalidated count moves, so a retired claim is never served as current evidence. - Re-ranking: relative BM25 score, idf-weighted coverage of the question, entity overlap with the question's resolved entities, embedding similarity; fixed weights. - Evidence: the answer comes with its path over live edges (question entity -> claim -> the source it was lifted from) and file location. Close calls return up to max_answers runners-up within a margin, each paid for in tokens. - Refusal: below min_coverage of the question's terms (unseen terms count at the highest idf), refused with the coverage stated. A path is never taken as proof. - Read-only: names resolve with Resolver.match, so asking neither logs nor learns; answers do not depend on question order. contextmesh/lexical.py: BM25 shared by the benchmark and the hybrid, plus coverage(). contextmesh/bench.py: the hybrid as a method; every method now reports wrong answers (answered, incorrect), out-of-scope refusals and mean latency; the hybrid's index memory and parameters are recorded. ops/calibrate-hybrid.py chose the defaults on the development suites only (grid of 21,289 points meeting the constraint that mean tokens stay under BM25 top-3's on each suite); its output is ops/calibrate-hybrid.log. Entity overlap and embedding similarity earned no weight there. The held-out suites were not read; this commit precedes running them. tests/test_hybrid.py: evidence path over live edges, entity-first paths, token accounting, both refusals and the configurable threshold, runner-up limits, rejected and refreshed-away claims never retrieved, and asking leaving graph and resolver byte-identical in any order. Live-only, refusal and read-only were mutation-checked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…criteria Development suites (calibrated on) and the held-out suites (run once, on committed code cb49b46, never calibrated on), each method scored on the same corpus in the same run, plus the acceptance criteria one by one: - Not met: docs accuracy (22/32 ties BM25 top-3; held out 3/10 vs BM25 top-1 4/10) and code accuracy (13/18 vs BM25 top-3 15/18; held out 7/10 vs 8/10). - Met: out-of-scope refusals (8/8, 5/6, 4/4, 4/4 vs BM25's 3/8, 2/6, 2/4, 2/4), tokens below BM25 top-3 on every suite, complete evidence paths, no retired claim retrieved, reproducible read-only asking. The hybrid is a precision gain, not an accuracy gain: on held-out docs it traded one correct answer for three fewer wrong ones. The lexical coverage threshold overfits (4/10 in-scope refusals on held-out docs, 0 on held-out code). Calibration gave the graph's re-ranking signals no weight; the graph's contribution here is the evidence path, live-only retrieval and invalidation. Latency ~1 ms vs the walk's 12-16 ms; index ~1.2-1.4 MB. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
HybridRetriever(contextmesh/hybrid.py) works in four steps:It's benchmarked against graph-only and BM25-only on both development suites and on held-out suites frozen before any hybrid code existed. Separate from #50 and #51, as asked. Full write-up:
docs/BENCHMARKS.md→ Hybrid retrieval.Order of work (visible in the commits)
eea2b08: held-out suites frozen first.bench/heldout-docs.jsoncovers README sections the docs suite doesn't ask about;bench/heldout-code.jsoncoverscontextmesh_mcp/, which no other suite reads.cb49b46: implementation and calibration on the development suites only. The calibration searched 21,289 grid settings, constrained to stay under BM25 top-3's tokens on each suite. Its output is committed asops/calibrate-hybrid.log.eb441c7: results. The held-out suites were run once, oncb49b46.Results against the acceptance criteria
Resolver.match, doesn't depend on order, and leaves the graph and resolver byte-identical (tested).Held-out docs, per method: the hybrid got 3 correct, 3 wrong and 4 refused. BM25 top-1 got 4 correct and 6 wrong.
It's a precision gain, not an accuracy gain. Of the 4 refused, BM25 top-1 got 1 right, so the hybrid traded one correct answer for three fewer wrong ones.
The lexical coverage threshold overfits. It refused 4 of 10 in-scope questions on held-out docs, which are paraphrased, and none on held-out code.
Calibration gave the graph's re-ranking signals (entity overlap, embedding similarity) a weight of 0. On these suites, the graph contributes the evidence path, live-only retrieval and invalidation, not the choice of answer.
Cost: about 1 ms per question against the walk's 12–16 ms. The index peaks at about 1.2–1.4 MB for 800–1,000 claims.
Changes
contextmesh/lexical.py: BM25 shared by the baseline and the hybrid, pluscoverage(), an absolute IDF-weighted measure in which unseen terms count at the highest IDF.contextmesh/hybrid.py: the retriever, with defaults from calibration.contextmesh/bench.py:build_corpus/evaluatelet one built corpus be scored many times.ops/calibrate-hybrid.pyandops/calibrate-hybrid.log. The log isn't a.txtfile, so it isn't ingested into the docs corpus.tests/test_hybrid.py, 10 tests: evidence path over live edges, entity-first paths, token accounting, both kinds of refusal and the configurable threshold, runner-up limits, rejected and refreshed-away claims never retrieved, and read-only asking in any order;tests/test_bench.py: every shipped suite validated structurally without running the held-out ones, held-out questions disjoint from the development suites, and machine-dependent figures excluded from the determinism check.Live-only retrieval, refusal and read-only asking were mutation-checked. The full suite,
ruff, the demo export (byte-identical) and the leak check pass.Not in this PR
Wiring the hybrid into
askor MCPmesh_ask. Whether it should replace or sit beside the walk is a product decision these results don't settle.Generated by Claude Code