Repository navigation
perf(memory): keep the BM25 order of code recall candidates - #470
Merged
Merged
Conversation
Code search took FTS5's BM25-ranked candidates and re-sorted them by the
hash-embedding cosine. Common words ("where", "how", "file") dominate
that cosine, so turn recall injected off-topic chunks: on 22 questions
about this repo only 28% of injected chunks were on topic and 9
questions got no relevant chunk at all. Keeping the BM25 order raises
that to 47% and 19/22 answered. The cosine still sets the floor and the
shown score, and still orders a page FTS did not rank (a browse or a
scan without the index), which FtsPage now reports as `ranked`.
scripts/eval_code_recall.py reproduces the measurement.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 25, 2026
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.
Problem
Turn recall injects up to 4 code chunks into each user message. Code search took FTS5's candidates (already BM25-ranked) and re-sorted them by the hash-embedding cosine. That cosine is a bag of hashed words, so common words ("where", "does", "how", "file") dominate it. For "where does edit matching live" it injected
tui/app.rs,config/merge.rs,debug_tests.rsandglob.rs, all scoring 0.39–0.41. Off-topic and on-topic chunks share the same score band, so nocode_min_scoreseparates them.Fix
code_min_score) and the shown score.FtsPagereports which case it is in the newrankedfield.Measured
scripts/eval_code_recall.py(new): 22 questions about this repo, each with the paths that answer it; top 4, floor 0.22, release build.Token use is unchanged (same number of chunks;
bench_tokens.py --workload dev248k → 251k, within recall noise). This is a recall-quality change.The cases were written knowing the repo, so read the table as a comparison of two rankings on one fixed set. Next step, measured offline on the same set: index the path too (FTS column), 47% → ~52–57% depending on weight. That needs a migration, so it gets its own PR.
Checks
cargo test -p whycodes-memory --lib(90). The newranked_hits_keep_bm25_order_and_a_browse_sorts_by_scorestores vectors that disagree with the text, and it fails on the old re-rank (checked).cargo test -p whycodes-storage --lib(45,rankedasserted for match / browse / scan)cargo check --workspace --tests, ratchets🤖 Generated with Claude Code