fix(cognition): drop stopwords in knowledge-pack relevance scoring (recall quality) - #4269
Open
rysweet wants to merge 1 commit into
Conversation
…ecall quality) Planning-context knowledge-pack selection (`knowledge_context::relevance_score`) scored packs by whole-word, distinct-token overlap between the objective and each pack's `name + description` (post #4241), but it never dropped English function words. Because this seam admits 2-char tokens (`MIN_TOKEN_LEN == 2`), short function words (`of, to, in, on, at, by, is, it`) plus longer ones (`the, and, for, with, …`) that coincidentally appeared in both the objective and an off-topic pack's text each added +1 to that pack's relevance. Those filler hits could crowd a genuinely relevant pack out of the `MAX_PACKS_PER_OBJECTIVE` cut, injecting off-topic knowledge into the planning prompt (`enrich_planning_context`, consumed by `base_type_turn`) and degrading reasoner reliability. `relevance_score` now excludes a curated closed-class function-word stopword set before scoring — aligning this seam with the stopword policy already adopted for episodic/procedural recall by `memory_consolidation::tokenize_objective`. The set is deliberately conservative: only grammatical function words, never open-class task terms (`fix`/`bug`/`test`) and never legitimate short technical topics (`go, os, io, ml, js, db, ci, cd`), so a real match is never dropped. Public surface unchanged (`enrich_planning_context` signature/contract intact); this refines a private helper only. New unit tests pin the stopword contract and guard against over-filtering; a qa-scenario drives them outside-in. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Summary
Standing cognition-improvement goal — recall quality axis.
Planning-context knowledge-pack selection (
knowledge_context::relevance_score, consumed byenrich_planning_context→base_type_turn) scored packs by whole-word, distinct-token overlap between the objective and each pack'sname + description(post #4241), but it never dropped English function words. Because this seam admits 2-char tokens (MIN_TOKEN_LEN == 2), short function words (of, to, in, on, at, by, is, it) plus longer ones (the, and, for, with, …) that coincidentally appeared in both the objective and an off-topic pack's text each added+1to that pack's relevance. Those filler hits could crowd a genuinely relevant pack out of theMAX_PACKS_PER_OBJECTIVEcut, injecting off-topic knowledge into the planning prompt and degrading reasoner reliability.relevance_scorenow excludes a curated closed-class function-word stopword set before scoring, aligning this seam with the stopword policy already adopted for episodic/procedural recall bymemory_consolidation::tokenize_objective(which never needed the 2-char entries because it drops <3-char tokens first). The set is deliberately conservative: only grammatical function words, never open-class task terms (fix/bug/test) and never legitimate short technical topics (go, os, io, ml, js, db, ci, cd), so a real match is never dropped.Public surface unchanged —
enrich_planning_contextsignature/contract intact; this refines a private helper only.Changed surfaces
src/knowledge_context.rs— privaterelevance_score+ new privateRELEVANCE_STOPWORDSconst /is_relevance_stopwordhelper. No public/user-facing surface changed, so no user docs require updates (internal-only justification per criterion 2). The behavior change is documented in-module and pinned by tests.tests/qa-scenarios/knowledge-context-stopword-relevance.yaml— new outside-in scenario.Evidence
1. qa-team scenario
Added
tests/qa-scenarios/knowledge-context-stopword-relevance.yaml, mirroring the known-goodknowledge-context-whole-word-relevance.yaml(#4241) format. It drives the hermetic in-process contract tests and a regression pass over the consuming turn path:cargo test --locked --lib knowledge_context→test result: ok. 12 passed; 0 failedcargo test --locked --lib base_type_turn→test result: ok. 16 passed; 0 failed(Note:
gadugi-testis not installed on this engineering host; the scenario is a thin wrapper whose underlyingcargo testcommands are the real assertions and were run directly — both green. YAML validated as well-formed.)2. Docs
No user-facing surface changed (private helper only). In-module rustdoc updated to document the stopword policy and its alignment with
memory_consolidation::tokenize_objective.3. quality-audit (>=3 SEEK→VALIDATE→FIX cycles, clean final)
go/os/io/ml/js/db/ci/cd) explicitly excluded and pinned byrelevance_score_keeps_short_technical_tokens. No code fix.cargo fmt --checkclean,cargo clippy --lib --no-deps -- -D warningsclean, tests green. Zero critical/high; zero medium correctness/security findings.4. CI green (local mirror)
cargo fmt --all -- --check✓ (pre-commit + pre-push)cargo clippy --release --no-deps -- -D warnings✓ (pre-commit)cargo clippy --all-targets --all-features --locked -- -D warnings✓ (pre-push)cognitive_memory bootstrap memory_ipc memory_consolidation) ✓cargo test --locked --lib→ 8664 passed; 0 failed; 7 ignored6. Focused diff
Two files, +177/−5. No unrelated edits.
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com