fix(cognition): drop stopwords in knowledge-pack relevance scoring (recall quality) - #4303
Open
rysweet wants to merge 1 commit into
Conversation
…ecall quality) Planning-context knowledge-pack selection (`knowledge_context::relevance_score`) scored packs by DISTINCT WHOLE-WORD objective-token overlap (fixed in #4241) but still counted generic English stopwords ("the", "with", "how", "from", "this", ...) as matches. The episodic-recall tokenizer (`memory_consolidation::tokenize_objective`, PR-C #2281) has always dropped these because they carry zero topical signal — the two recall seams disagreed. Consequence: an objective that merely shared a stopword with an off-topic pack's name/description inflated that pack's relevance, creating spurious ties that could crowd a genuinely relevant pack out of the top-`MAX_PACKS_PER_OBJECTIVE` (3) cut and inject off-topic knowledge into the planning prompt — the SAME recall-precision crowd-out failure mode #4241 addressed, reached by a different route. Fix: align both recall seams on ONE stopword source of truth. Expose `memory_consolidation::is_recall_stopword` (the tokenizer now routes through it too) and filter stopwords out of the objective token set in `relevance_score`. Public surface unchanged (`enrich_planning_context` signature/contract intact); this refines a private helper only. New unit tests pin the stopword contract and a crowd-out regression guard; a qa-scenario drives them outside-in. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Owner
Author
|
CI 100% green (run 29622310725): pre-commit |
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.
Standing cognition goal — recall quality
Durable improvement toward the perpetual cognition goal (graph memory, recall
quality, distillation fact-yield, reasoner reliability). Code-only change; no
snapshot docs.
Problem
Planning-context knowledge-pack selection (
knowledge_context::relevance_score,consumed by
enrich_planning_context→base_type_turn) scored packs byDISTINCT WHOLE-WORD objective-token overlap after #4241 — but still counted
generic English stopwords (
the,with,how,from,this, …) asmatches.
The episodic-recall tokenizer (
memory_consolidation::tokenize_objective, PR-C#2281) has always dropped these stopwords because they carry zero topical
signal. The two recall seams disagreed. Consequence: an objective that merely
shared a stopword with an off-topic pack's name/description inflated that pack's
relevance, creating spurious ties that could crowd a genuinely relevant pack out
of the top-
MAX_PACKS_PER_OBJECTIVE(3) cut and inject off-topic knowledge intothe planning prompt — the SAME recall-precision crowd-out failure mode #4241
fixed, reached by a different route.
Fix
Align both recall seams on ONE stopword source of truth:
memory_consolidation::is_recall_stopword(the tokenizer now routesthrough it too — pure refactor, behaviour identical).
relevance_score.Public surface unchanged (
enrich_planning_contextsignature/contract intact);this refines a private helper only.
Changed surfaces
src/knowledge_context.rs—relevance_score(private fn) now dropsstopwords; doc updated; 2 new unit tests.
src/memory_consolidation/mod.rs— newpub(crate) is_recall_stopwordpredicate (single source of truth);
tokenize_objectiveroutes through it.tests/qa-scenarios/knowledge-context-stopword-relevance.yaml— newqa-team scenario (outside-in).
No user-facing surface changed (internal planning-context helper only), so no
end-user docs update is required; the shared-seam behaviour is documented in the
rustdoc of
is_recall_stopword/relevance_score.Evidence
Criterion 1 — qa-team scenario (gadugi-test):
tests/qa-scenarios/knowledge-context-stopword-relevance.yaml.gadugi-test validate→✓ Scenario "knowledge-context-stopword-relevance" is valid(1 valid, 0 invalid).gadugi-test run -s knowledge-context-stopword-relevance→✓ Passed: 1 ✗ Failed: 0. Drivesknowledge_context(11 tests),memory_consolidation(146), andbase_type_turn(16), eachtest result: ok.Criterion 2 — docs: No user-facing surface changed (private planning-context
helper); changed surfaces listed above with internal-only justification. Rustdoc
updated on the touched items.
Criterion 3 — quality-audit (≥3 SEEK→VALIDATE→FIX cycles, clean final):
relevance_scorelowercases before thestopword filter;
tokenize_objectivelowercases up front. VALIDATE: targetedtests pass; clippy clean.
TOKEN_STOPWORDSis referenced only byis_recall_stopword; both seams callthe predicate. VALIDATE:
memory_consolidation146 tests pass (behaviouridentical). FIX applied in an earlier cycle: clippy
doc_lazy_continuationwarning on the new doc list → fixed by adding blank lines / indentation.
--all-targets -- -D warningsparity checked. VALIDATE: clean, zero findings.Criterion 4 — CI green (local equivalents):
cargo fmt --all -- --check→ clean (pre-commit gate passed).cargo clippy --release --no-deps -- -D warnings→ SUCCESS (pre-commit gate).cargo clippy --all-targets --all-features --locked -- -D warnings→ clean(pre-push gate passed).
cargo test --all-features --locked --lib --no-fail-fast→test result: ok. 8665 passed; 0 failed; 7 ignored.memory_ipcsuite →423 passed; 0 failed.Criterion 6 — focused diff: 2 source files + 1 new qa scenario; no unrelated
edits (
git diff --stat:src/knowledge_context.rs,src/memory_consolidation/mod.rs).Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com