fix(cognition): dedup keywords + deterministic tie-break in knowledge-pack ranking (recall quality) - #4293
Merged
rysweet merged 1 commit intoJul 17, 2026
Conversation
…-pack ranking (recall quality) Builds on the keyword-coverage ranking landed in #4281, which added `ORDER BY (title_hit*2 + content_hit*1) DESC` to native_knowledge::query_articles but left two recall-quality gaps: 1. Query keywords were not de-duplicated, so a word repeated in the question ("rust ... rust") double-counted in the coverage score and over-rewarded an article that merely mentions it once. query_pack_db now keeps only DISTINCT keywords, folded case-insensitively to match SQLite's ASCII-case-insensitive LIKE — making the 'sum across distinct keywords' the ranking already claimed actually hold. 2. Equal-score matches had no tie-break, so their order fell back to SQLite's arbitrary rowid order (non-reproducible recall). The ORDER BY now ends `, title ASC` for deterministic, run-to-run-stable ordering. Also adds a durable reference doc documenting the full article-ranking behavior. knowledge.query wire shape ({answer, sources, confidence}) is unchanged; only result ORDER improves. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
rysweet
force-pushed
the
engineer/continuously-research-and-improve-your-own-cogn-70ab8541-1784319955-a066ec
branch
from
July 17, 2026 22:06
c8f661d to
0915a5a
Compare
📊 Coverage Summary
Coverage data from CI run. Test files matching |
rysweet
deleted the
engineer/continuously-research-and-improve-your-own-cogn-70ab8541-1784319955-a066ec
branch
July 17, 2026 22:39
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 goal — recall quality. Additive hardening of the knowledge-pack article ranking behind
knowledge.query(native, Python-free reader insrc/native_knowledge.rs), which feeds the reasoner's planning-context enrichment.The keyword-coverage ranking (
ORDER BY (title_hit*2 + content_hit*1) DESC) landed in #4281. This PR rebases onto that and closes two remaining recall-quality gaps it left:"rust ... rust") double-counted in the coverage score and over-rewarded an article that merely mentions it once.query_pack_dbnow keeps only DISTINCT keywords, folded case-insensitively (to_ascii_lowercase) to match SQLite's ASCII-case-insensitiveLIKE— making the "sum across distinct keywords" the ranking already documented actually hold.ORDER BYnow ends, title ASCfor run-to-run-stable ordering.knowledge.querywire shape ({answer, sources, confidence}) is unchanged; only result ORDER improves.Changed surfaces
src/native_knowledge.rs—query_pack_db(case-insensitive keyword dedup),query_articles(deterministictitle ASCtie-break + doc). Internal functions; RPC output shape unchanged.docs/reference/knowledge-pack-article-relevance-ranking.md(new) +mkdocs.ymlnav entry — durable documentation of the full article-ranking behavior (coverage + title weighting + dedup + determinism).Merge-ready evidence
1. Scenarios (tests) written, validated, run
gadugi-test is not provisioned in this engineer environment; the executable scenarios for this surface are the module's Rust unit tests. Added 2 additive tests alongside #4281's:
query_articles_breaks_score_ties_by_title_ascending— three equal-score articles inserted reverse-alphabetically come backtitle ASC(proves determinism).query_pack_db_dedups_repeated_keywords—"rust rust ownership borrowing"ranks the higher-coverage article first; without dedup the repeated"rust"would have vaulted the single-keyword article to the top.2. Docs
New durable reference doc
docs/reference/knowledge-pack-article-relevance-ranking.md(doc_type: reference — not a point-in-time report, G4-compliant), wired intomkdocs.ymlnav.tests/docs_integrity.rs:4 passed; 0 failed.3. Quality audit (SEEK → VALIDATE → FIX, ≥3 cycles, clean final)
query_pack_db_dedups_repeated_keywords(fails without the fix). FIX: case-insensitive keyword dedup.query_articles_breaks_score_ties_by_title_ascending. FIX:title ASCsecondary sort.query_pack_db_*and url-column tests still green (20/20). No regression.nodes/entitiestables gain no new failure mode (ORDER BY references onlytitle/content, already required by the WHERE clause).cargo fmt --checkclean;cargo clippy --release -- -D warningsandclippy --all-targets --all-features --locked -- -D warningsclean. Zero critical/high; zero medium correctness/security findings.4. CI
Local gates green:
cargo fmt --all -- --check; pre-commitclippy --release --no-deps -- -D warnings; pre-push race subset (cognitive_memory bootstrap memory_ipc memory_consolidation) 443 passed, 0 failed;clippy --all-targets --all-features --lockedclean. Full CI runs on this PR.6. Focused diff
3 files, +158/−4:
src/native_knowledge.rs,docs/reference/knowledge-pack-article-relevance-ranking.md,mkdocs.yml. No unrelated edits. Rebased onto latestmain(no conflict with #4281; layered strictly on top of it).