Repository navigation
fix(recall): admit unique exact keywords in explicit memory lookup - #441
Conversation
|
Author follow-up on dd0bb30. I found a precision tradeoff the positive-query table misses. Using the same ten transport golds and 180 keyword-bearing distractors, I checked the rendered block at limit 3 and a 300-character budget. Upstream abstains on both of these unrelated queries. This head injects a memory for each:
The intended rate-limiter query still recovers its gold. A keyword being unique in this store does not tell us which sense the user meant. These are targeted counterexamples; their frequency in live prompts is unmeasured. I recommend keeping them as negative controls and revisiting the default automatic-injection rule before merging. Explicit recall could reasonably use a different precision threshold. |
abogartz
left a comment
There was a problem hiding this comment.
Verdict: REQUEST_CHANGES
The mechanism is sound and the guard tests are good, but the change lands on one of the two admission paths, and it moves published numbers and documented rules that nothing in CI checks.
Verified on dd0bb30 against main at ebc083a: typecheck clean, 1483 unit pass / 21 skip / 0 fail, lint clean, CI 4/4 green. The body's "51 focused keyword, tokenizer and negative-evaluation tests" claim reproduces exactly (51 pass across keywords.test.ts, negative-eval.test.ts, tokenizer.test.ts).
P1 — the fix applies to injection only; memory_recall still returns nothing for the same query
There are two admission paths, not one:
scoreMemories(src/recall/score.ts) serves injection —src/inject/pull.ts:44andsrc/recall/relevant.ts:165. This PR changes that one.memory_recallruns the same results through a second gate:src/tools/recall.ts:61filters onadmitsRow(src/recall/gate.ts:114), which still requires two whole-word concepts once the query reachesLONG_QUERY_TOKENS.
Measured on this branch with the row and query from the new test:
scoreMemories (injection path) returned: 1
tool gate concepts: ["throttling","rules","never","take","effect","locally"]
admitsRow (memory_recall path): false
So the row now rides the prompt while the tool that searches for it reports no match. src/recall/gate.ts:5 states the invariant this breaks, in its own header: "This is the rule the injection path already applies (LONG_QUERY_TOKENS in score.ts); the two paths must agree on when nothing is a good enough answer."
This matters for closure: #405 is titled as a recall failure ("7 of 21 curated query/gold pairs retrieve nothing"). The body measures the rendered injection block, which is the path this PR fixes. Please either extend the same uniqueness rule into admitsRow, or state in the PR and in #405 that the tool path is deliberately unchanged and why the invariant in gate.ts no longer holds.
P1 — the published recall numbers move, and no doc or record is updated
bun run bench:recall on main versus this head, vocabulary-bridge table:
Class (with kw) |
main R@1 / R@3 | head R@1 / R@3 |
|---|---|---|
| strict | 24% / 24% | 26% / 26% |
| all rows | 64% / 66% | 65% / 67% |
bench/runners/recall-quality.ts measures the shipped matcher, and the README plus docs/recall-quality.md publish those figures. test/claims.test.ts pins only the "What memory is worth, measured" section, so CI cannot catch the drift — the guard is this review.
One related observation, not caused by this PR: main prints 24% for strict-with-kw while the README publishes 26%. The table was already stale before this change, and the change happens to move it back into agreement. Whichever way this PR lands, the table needs a re-run and a dated record rather than a coincidence.
P1 — three documents state the two-concept rule as absolute
The diff is two files, both code and test. These now read as false:
- README, "Token cost and caching": "A free-text prompt must share at least two distinct concepts with a memory to be injected."
docs/injection-cost.md, "Two-concept threshold": same rule, plus "Silence on single-word coincidences is deliberate."docs/flags.md,OPENCODE_MEMORY_QUERY_GATE: "the rule the injected relevance block already applies, so both paths agree on when nothing is a good enough answer."
The exception is worth writing down — it is a real rule with a real justification (a complete authored alias that no other live row indexes). Please state it in all three places, and say explicitly that it applies to injection and not to the recall tool if that is the decision.
P2 — nothing pins the user-visible behavior on either path
The new test calls scoreMemories directly, which is the right unit-level check and it covers the refusals well: prose-only rows, identifier fragments, and a competing row sharing the keyword are all still refused. What is missing is one test at the level a user sees — what memory_recall returns for the same query, whichever way the path question above is resolved. Right now a regression that removes the tool-side admission, or adds it, stays green.
P2 — the transport-bank numbers are not reproducible from the PR
"With a 300-character budget the expected memory rode for 13 queries (previously 12)" is the only evidence that the change recovers a real case. Name the command that produces it so the next reader can re-run it, and record the before/after in the bench results file rather than only in the body.
The body is also right to say these fixture results establish nothing about precision on live prompts. That sentence should stay in #405 when it closes.
Nits
uniqueTermsre-runs the identifier regex[A-Za-z0-9_.\-/]+thatqueryConceptsalready runs over the sameterm. One pass would keep the two lists from drifting apart if the tokenizer changes.- A multi-word authored alias such as
bun testcan never equal a single query identifier, so part of the alias classmemory_rememberasks for is unreachable by this rule. The comment says fragments need corroboration; it would help to say that phrases do too. df.get(id) === 1is computed overliverows only, which is correct, andnormalizeKeywordslowercases aliases, so the case handling on both sides checks out. Worth a comment noting that the alias side is normalized at write time, because a legacy row holdingThrottlingwill not admit.
|
Ready for another look at 64c494a. I narrowed the exception to explicit memory_recall and restored automatic injection's original admission rule. The user-facing test covers the intended lookup and the two wrong-sense automatic injection cases. The revised body links the reproducible fixture and distinguishes the 50-row and 200-row published metrics. I also recorded the scope on #405, which stays open. |
abogartz
left a comment
There was a problem hiding this comment.
Verdict: APPROVE
Re-reviewed at b012c23. All three P1s from my earlier review are resolved, and the resolution is better than the one I proposed. I suggested extending the new admission into admitsRow so both paths agree again. You took the other branch of the dilemma and made it explicit: the exception now belongs only to deliberate lookup, and the injector keeps the two-concept rule. That is the correct reading of the precision evidence, and the wrong-sense counterexamples you posted are what prove it.
What each P1 became
The two-path invariant. src/recall/score.ts is no longer in the diff at all. The exception lives in exactAliasMatches (src/recall/gate.ts:94) and is applied at exactly one call site, src/tools/recall.ts:57. The header in gate.ts that previously demanded the paths agree was rewritten to state the asymmetry as the design: "Explicit lookup also accepts a complete authored alias that identifies a single candidate. Automatic injection stays stricter." The file no longer contradicts the code, which was the finding.
The published numbers. bun run bench:recall on this head produces output byte-identical to main. Injection is untouched, confirmed rather than argued. I also owe you a correction: the 24%-versus-26% drift I reported was my own error. The bench prints three store sizes and I compared the 50-row table against the README's 200-row figures. Verified on this head — size 50 strict-with-kw 24%/24%, size 200 26%/26%, size 500 26%/26%. The README matches the 200-row store, as you said. There was no stale table.
The docs. docs/flags.md names the exception on OPENCODE_MEMORY_QUERY_GATE and states that automatic injection keeps its two-concept requirement. docs/injection-cost.md replaced the sentence that claimed the pull path was identical. docs/recall-quality.md gained an "Explicit exact-keyword lookup" section. The README needed no change and correctly does not get one, because its bullet describes injection and injection did not move.
The new tests are real guards, not assertions
I copied test/recall-gate.test.ts onto main and ran it. It fails there with Received: "No matching memories" on the throttling query and passes on this branch. So the 13-to-14 gain at the public tool is demonstrated by a test that would notice a regression, which is the P2 I asked for. The second test pins the hard cases properly: a competing thermal throttling row blocks admission, a scope filter that removes the competitor lets it through, throttling_rules as a fragment is refused, and the phrase alias frame pacing is not matched by the word pacing alone.
Verification on this head: typecheck clean, lint clean, comment-lint clean, 1505 unit pass / 21 skip / 0 fail, e2e 35 pass / 0 fail.
Nits, none blocking
Math.max(scoreMemory(m, args.query!), aliases.has(m) ? 1 : 0)— the floor never fires.scoreMemoryalready adds 1 for any query word present in the haystack, and an alias term is by construction both a query word and in the haystack. It reads as a ranking intervention without being one. Delete it, or say what future scorer change it guards.exactAliasMatchescallsrowConcepts(row)for every candidate inside the loop. Theif (!owners.size) returnguard keeps the common path cheap, so this only matters if a later change moves that guard upward. Worth noting where the cost is bounded.docs/recall-quality.mdlinks the bench file by absolute URL pinned to64c494a. That is the right call —bench/is not inpackage.jsonfiles, so a relative link would fail the published-surface check intest/doc-links.test.ts— but the reason is invisible, anddoc-links.test.tsskipshttpslinks, so CI will not catch a force-push that orphans it. One sentence for the pin, then re-point it atmainafter merge.- Keep the body's wording that this addresses the explicit-lookup portion of #405 and that the paraphrase and automatic-retrieval questions stay open. No
Closeskeyword on this one.
|
🎉 This PR is included in version 0.31.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Addresses the explicit lookup portion of #405. For a long memory_recall query, a whole authored keyword can admit one visible candidate when no other eligible row indexes that term. Scope and type filters apply first. The automatic injector retains its two-concept gate. A single polysemous term had caused the previous revision to inject a Redis fact for CPU frequency throttling and a database seed command for stadium lighting fixtures.
Reproduction at 64c494a. Run
bun test test/recall-gate.test.ts -t "transport keyword lookup"for the public tool, the positive injection control, and both wrong-sense prompts. On 21 transport queries with ten gold rows and 180 keyword-bearing distractors, explicit recall at limit three recovered 14 golds, up from 13 on upstream ebc083a. The throttling query gains the Redis row. At a 300-character injection budget all three ambiguous prompts abstain; a corroborated Redis query still delivers the row.bun run bench:recallreproduces upstream injection numbers: strict keyword R@1/R@3 is 24%/24% at size 50 and 26%/26% at size 200 (the README table). Results and methodology are in bench/transport-lookup-results.md and bench/recall-results.md. Windows, Bun 1.4.4, synthetic store, no model. Live precision is unmeasured. Deliberate search can still return wrong-sense matches.Typecheck, comment lint and 80 focused tests passed. The broader paraphrase and automatic-retrieval questions in #405 remain open.