Skip to content

perf(memory): let a query word in the path lift a code recall candidate - #471

Merged
mrnasil merged 2 commits into
mainfrom
perf/code-recall-path-boost
Nov 25, 2026
Merged

mrnasil merged 2 commits into
mainfrom
perf/code-recall-path-boost

Conversation

@mrnasil

@mrnasil mrnasil commented Nov 25, 2026

Copy link
Copy Markdown
Member

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 injected agent/mod.rs, llm/capabilities.rs, tui/app.rs and cli/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. FtsPage now 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)

tuning set (22) held-out set (12, written after tuning)
main before #470 (cosine) 28%, 13/22 answered –
#470 (BM25 order) 47%, 19/22 35%, 9/12
this PR 57%, 19/22 58%, 11/12

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_candidate covers 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

mrnasil and others added 2 commits November 25, 2026 05:48
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]>
@mrnasil
mrnasil merged commit f6dc8aa into main Nov 25, 2026
7 checks passed
@mrnasil
mrnasil deleted the perf/code-recall-path-boost branch November 25, 2026 03:08
@mrnasil mrnasil mentioned this pull request Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant