Repository navigation
feat(recall): two-concept admission for memory_recall behind a flag - #418
Conversation
|
Composition note. Measured alone, admission only — ranking, scoring and window size untouched. Off by default. Every row this gate promotes into the window from below rank 3 is labelled: 9 queries gain a row, one an answer, one something useful, eight junk. That is the counterweight to the 145 rows removed across all 404 queries. With the flag unset the windows are identical to |
|
Rework pushed ( Two independent problems, both found in adversarial review:
Adjudicated held-out (n=227, k=3): answers at rank 1 56→57, paired discordance 1/0 (p=1.0), rows 571→479, non-answering rows 438→346. Flag off byte-identical to |
memory_recall scores a row by counting how many of the query's words appear in it as substrings, and returns anything that scores above zero. One shared word is enough, so `watermark 283 287 head` answers with every row that mentions a head, and `fixer ready tickets queue blocked` answers with rows about the GitHub CLI and about npm publishing. On 404 real recall queries from 30 days of session transcripts, labelled by two independent readers against a pinned store snapshot (#409 case bank), 42% of the rows the tool returned were judged irrelevant and a further 30% related-but-not-an-answer. The injected relevance block already refuses single-concept matches once a query is long enough to be a deliberate search (LONG_QUERY_TOKENS). This applies that rule to the tool, behind OPENCODE_MEMORY_QUERY_GATE, so the two paths agree on when nothing is a good enough answer. Admission only: ranking, scoring and the window size are untouched. Measured by running the handler itself with the flag flipped once per query: held-out half (227 queries, k=3), answers in the window 148 -> 149, answers at rank 1 125 -> 125 (zero discordant pairs against recall), returned rows 571 -> 480, non-answering rows 363 -> 272, and no-gold queries still shown a window 0.847 -> 0.678, paired 10-to-0 (McNemar p=0.002). Every row the gate promotes from below rank 3 is labelled too: nine queries gain a row, one an answer, one something useful, eight junk. With the flag unset the tool is unchanged: the same 404 queries run through origin/main and through this branch produce identical windows on 404 of 404. Refs #409
The first version counted the scorer's substring hits, which made the gate satisfiable by accidents: 'on' occurs inside 'context' and 'decision', 'pr' inside 'preference', and '283' inside 'build2837' — so the query that motivated this change, 'watermark 283 287 head', still admitted the row it was meant to refuse. Admission now compares whole words (underscore kept inside identifiers, so 'db_id' and 'OPENCODE_MEMORY_DIR' survive), drops the query's stopwords and fragments, and shares the injection scorer's stopword list. gateEnabled() now allowlists '1', 'true', 'yes' and 'on'; the old deny-list treated 'no', 'n', '00' and '0.0' as on. Tests pin the counterexamples, the distinct-concept boundary, and clear OPENCODE_MEMORY_QUERY_GATE in beforeEach so an ambient flag cannot flip the flag-off tests. The substring gate's case-bank numbers are void; they are re-measured against full-text labels before the PR body is updated.
d3cc122 to
79c2d8e
Compare
|
🎉 This PR is included in version 0.27.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
What
Adds two-concept admission to the
memory_recalltool's matcher behindOPENCODE_MEMORY_QUERY_GATE(unset = shipped behaviour): once a query carries three or more content words, a returned row must share two whole words with it. This is the rule the injection path already applies (LONG_QUERY_TOKENSinsrc/recall/score.ts); the tool did not, so one shared word —head,run,on— was enough to fill the window.Reworked after adversarial review
The first version counted the scorer's substring hits. Review showed the gate was then satisfiable by two accidents, reproduced against the shipped code:
onmatched inside thetypefield (context,decision),prinsidepreference;283matched insidebuild2837— the example query in the original body still admitted the row it was meant to refuse;OPENCODE_MEMORY_QUERY_GATE=no(andn,00,0.0) enabled the gate.Admission now:
db_idandOPENCODE_MEMORY_DIRstay single concepts (splitting them is the regression that blocked perf(recall): split identifiers in the matcher tokenizer (#409) #417), dashes separate, so283no longer matchesbuild2837or#2830;how do I set the pr onreduces to the one conceptset;gateEnabled()allowlists1|true|yes|on; everything else is off;Measurements — re-run; the first version's numbers are void
The original numbers were measured with substring admission and relevance labels taken from a judge that saw row prose clipped to 500 chars. Rebuilding the labels with the store's own full text (4,000-char cap) moved 158 of 1,863 labels across the answer boundary, so every decisive pair — any row a gate moved into or out of a window — was re-adjudicated in isolation on two independent seats (27B judge + a second model). The isolated seats overturned 29 of the 36 disputed ANSWER labels: batch context inflates answer labels on long rows. Numbers below use the adjudicated labels, measured through the real handler (
poc-409/casebank/gate-e2e.ts,PLUGIN_SRCat this branch).Held-out half, n=227, window k=3:
All 404 queries: answers at rank 1 106 → 106, paired discordance 3/2 (p = 1.0), rows 1,043 → 893.
Flag off, the handler's windows are byte-identical to
origin/mainon 404/404 queries (diffed as ts lists).What this does not fix
abstainshares no whole word with a row sayingabstention, and the gate cannot bridge that. IDF ranking (Enhancement: recall useful memories across different wording #409) is the fix for this class, not this gate.Tests
17 tests pin the counterexamples above, the env allowlist, the distinct-concept boundary (three tokens with a duplicate stay permissive), and the flag-off path;
beforeEachclears the flag so an ambient CI value cannot flip the off-tests.bun run gate(tsc + biome + unit + e2e) green.Case bank: 404 real
memory_recallqueries from 30 days of session transcripts, relevance labelled by independent readers against a pinned store snapshot (not committed — it carries query text and memory prose). See #409 for the instrument and its known limits.