Repository navigation
perf(memory): let a query word in the path lift a code recall candidate - #471
Merged
Merged
Conversation
The code index's FTS holds chunk text only, so BM25 cannot see that "compact the conversation" names compact.rs. Candidates are now ranked by their BM25 relevance (best = 1.0) plus 0.2 per query word of three or more characters that is also a word of the path. Putting path matches strictly first was worse: generic path words (turn, command, load) then push out the only relevant chunk. eval_code_recall.py, top 4: tuning set 47% -> 57% on topic (19/22 answered either way); a held-out set written after tuning 35% -> 58%, 9/12 -> 11/12 answered. FtsPage now carries each row's BM25 relevance. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The relevance column was read by a closure inside the generic fts_rows, which line coverage counts per instantiation (storage floor: 1 missed line). A separate non-generic query now returns the scores in the same BM25 order; tied rows share one score, so tie order cannot misalign them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merged
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.
Follow-up to #470 (code recall keeps the BM25 order).
Problem
The code index's FTS holds chunk text only. BM25 cannot see that "compact the conversation" names
crates/agent/src/compact.rs, so for that question it injectedagent/mod.rs,llm/capabilities.rs,tui/app.rsandcli/cmd/helpers.rs.Fix
On a BM25-ranked page, each candidate's rank is its BM25 relevance, scaled so the best candidate is 1.0, plus 0.2 per query word of ≥3 characters that is also a word of its path (
PATH_WORD_WEIGHT). Unranked pages (browse / scan) still sort by cosine; the cosine still sets the floor and the shown score.FtsPagenow carries each row's relevance (-bm25()).Putting path matches strictly first was measured and rejected: generic path words (
turn,command,load) then push out the only relevant chunk (19 → 17 questions answered).Measured (
scripts/eval_code_recall.py, release build, top 4)Weights 0.15–0.3 sit on the same plateau (57–60%); 0.2 is in the middle of it. The held-out questions are now in the script too, reported separately.
Checks
cargo test -p whycodes-memory --lib(91;a_query_word_in_the_path_lifts_a_close_candidatecovers scaling, the ≥3-char rule, unranked and out-of-range)cargo test -p whycodes-storage --lib(45); clippy (memory, storage); fmt; ratchets🤖 Generated with Claude Code