[GH-ISSUE #1250] [Issue]: LTM recall scoring: bounded per-lane normalization (BM25 boost, keyword lane, threshold) #639

Closed
opened 2026-10-20 17:29:15 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @Promansis on GitHub (Oct 7, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1250

Originally assigned to: @Promansis on GitHub.

Summary

Recall ranking is not bounded per lane. The raw BM25 score is added to the fused score unbounded, which overrides rank fusion and the lane weights. The keyword lane is normalized against its own top hit, so a false positive gets full relevance. The threshold means different things per style, lane and vault size.

Affected package

long-term-memory (packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/ranking.ts, retrieval.ts, keyword-index.ts)

Expected behavior

  • Lane weights and rank fusion decide the order, so a weight-0.6 semantic lane is not beaten by a weight-0.3 lexical lane.
  • Each lane reports relevance on an absolute, bounded scale, so one threshold value means roughly the same thing across styles and vault sizes.
  • A keyword hit with no exact match does not normalize to relevance 1.0 just because it is the best of a weak set.

Actual behavior

  1. Raw BM25 boost overrides fusion (ranking.ts:46,58): rawScoreBoost = rawScore * 0.001 * lane.weight. Non-bm25 raws are <= 1, so the boost is a tie-breaker. BM25 raw is an unbounded idf sum (10-40 for multi-message queries), while the whole RRF term is <= 1/61 ~ 0.0164, so the boost dominates. Probe of reciprocalRankFuse with balanced weights (semantic 0.6, lexical 0.3): vector rank 1 (cosine 0.85) fused 0.00887 / relevance 0.510; bm25 rank 10 (raw 18) fused 0.00946 / relevance 0.284. All ten bm25 hits outrank the best semantic hit. On real debug-log recalls the boost is 49-63% (median) of the fused score. Source extraction's existing-note lookup uses the whole source text as the query (source-extraction.ts:311-321), so it is hit hardest.
  2. Keyword lane normalizes to the top hit (retrieval.ts:167,173: rawScore = hit.score / keywords[0].score), and fuzzy matching is a bare substring check (keyword-index.ts:96,98,103,110). searchLtmKeywordIndex({byKeyword:{king:[...]}}, "I was looking for the map") returns {"score":1.6136,"reasons":["keyword:fuzzy:king"]}. With no exact hit, that false positive normalizes to 1.0, so relevanceScore = keywordWeight (0.8 under exact) and every chunk of the note passes any threshold up to 0.8. The threshold help text (locales/en.json:310) says it is not "a score relative to the top result", but this lane is exactly that.
  3. Threshold meaning shifts (ranking.ts:43,60, constants.ts:284-314, graph.ts:92, runtime-settings.ts:117-119): a lane's maximum relevance is weight x its own ceiling (graph <= 0.5w; bm25 x/(x+1) < w and grows with corpus size and query length; vector cosine x w, <= 0.15 under exact). A threshold of 0.3 tuned under broad removes all semantic recall under exact and all bm25, keyword and graph recall under balanced. Real BM25 normalizes to 0.94-0.98 for every hit, and balanced's selected relevance sits in a 0.285-0.295 band, so any threshold change acts as a cliff.

Steps to reproduce

  1. Run reciprocalRankFuse (ranking.ts) with balanced weights, one vector hit at rank 1 (cosine 0.85) and ten bm25 hits with raw scores up to 18.
  2. Observe the vector hit ranks last.
  3. Run searchLtmKeywordIndex with a keyword king against the query "I was looking for the map" and observe the fuzzy hit and its normalization to 1.0 in retrieval.ts.

Environment

  • Marinara Engine version: 2.5.0 line (staging)
  • Package version: long-term-memory 1.4.7
  • Install type: source (found by code audit and tsx probes against src/)
  • OS + version: not platform-specific
  • Browser or app shell: not UI-specific

Logs, screenshots, or video

Probe output above. Full write-up: audit findings LTM-SCORE-02, 03 and 07 (local scratch/audits/ltm-recall-scoring.md, not tracked).

Additional context

Proposed fix: one bounded per-lane normalization pass in ranking.ts and retrieval.ts.

  • Base the boost on the bounded normalizedRawScore, or remove the additive term.
  • Normalize keyword scores against a fixed ceiling (e.g. the exact-phrase score of 4) and require token or word-boundary containment for fuzzy matches.
  • Map every lane to an absolute bounded scale before weighting, and document the per-style ceilings.
  • Add a reciprocalRankFuse unit test: a deep high-raw bm25 hit vs. the top vector hit across styles, an invariant that the raw boost cannot invert lane weights, and keyword negative cases (substring-only match must not reach relevance = keywordWeight).
  • Re-tune preset weights and a default threshold (~0.35-0.40) only after this lands.

Related: #1246 (separate settings-validation bug).

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @Promansis on GitHub (Oct 7, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1250 Originally assigned to: @Promansis on GitHub. ## Summary Recall ranking is not bounded per lane. The raw BM25 score is added to the fused score unbounded, which overrides rank fusion and the lane weights. The keyword lane is normalized against its own top hit, so a false positive gets full relevance. The threshold means different things per style, lane and vault size. ## Affected package long-term-memory (`packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory/ranking.ts`, `retrieval.ts`, `keyword-index.ts`) ## Expected behavior - Lane weights and rank fusion decide the order, so a weight-0.6 semantic lane is not beaten by a weight-0.3 lexical lane. - Each lane reports relevance on an absolute, bounded scale, so one threshold value means roughly the same thing across styles and vault sizes. - A keyword hit with no exact match does not normalize to relevance 1.0 just because it is the best of a weak set. ## Actual behavior 1. **Raw BM25 boost overrides fusion** (`ranking.ts:46,58`): `rawScoreBoost = rawScore * 0.001 * lane.weight`. Non-bm25 raws are <= 1, so the boost is a tie-breaker. BM25 raw is an unbounded idf sum (10-40 for multi-message queries), while the whole RRF term is <= 1/61 ~ 0.0164, so the boost dominates. Probe of `reciprocalRankFuse` with balanced weights (semantic 0.6, lexical 0.3): vector rank 1 (cosine 0.85) fused 0.00887 / relevance 0.510; bm25 rank 10 (raw 18) fused 0.00946 / relevance 0.284. All ten bm25 hits outrank the best semantic hit. On real debug-log recalls the boost is 49-63% (median) of the fused score. Source extraction's existing-note lookup uses the whole source text as the query (`source-extraction.ts:311-321`), so it is hit hardest. 2. **Keyword lane normalizes to the top hit** (`retrieval.ts:167,173`: `rawScore = hit.score / keywords[0].score`), and fuzzy matching is a bare substring check (`keyword-index.ts:96,98,103,110`). `searchLtmKeywordIndex({byKeyword:{king:[...]}}, "I was looking for the map")` returns `{"score":1.6136,"reasons":["keyword:fuzzy:king"]}`. With no exact hit, that false positive normalizes to 1.0, so `relevanceScore = keywordWeight` (0.8 under `exact`) and every chunk of the note passes any threshold up to 0.8. The threshold help text (`locales/en.json:310`) says it is not "a score relative to the top result", but this lane is exactly that. 3. **Threshold meaning shifts** (`ranking.ts:43,60`, `constants.ts:284-314`, `graph.ts:92`, `runtime-settings.ts:117-119`): a lane's maximum relevance is weight x its own ceiling (graph <= 0.5w; bm25 `x/(x+1)` < w and grows with corpus size and query length; vector cosine x w, <= 0.15 under `exact`). A threshold of 0.3 tuned under `broad` removes all semantic recall under `exact` and all bm25, keyword and graph recall under `balanced`. Real BM25 normalizes to 0.94-0.98 for every hit, and balanced's selected relevance sits in a 0.285-0.295 band, so any threshold change acts as a cliff. ## Steps to reproduce 1. Run `reciprocalRankFuse` (`ranking.ts`) with balanced weights, one vector hit at rank 1 (cosine 0.85) and ten bm25 hits with raw scores up to 18. 2. Observe the vector hit ranks last. 3. Run `searchLtmKeywordIndex` with a keyword `king` against the query "I was looking for the map" and observe the fuzzy hit and its normalization to 1.0 in `retrieval.ts`. ## Environment - Marinara Engine version: 2.5.0 line (`staging`) - Package version: long-term-memory 1.4.7 - Install type: source (found by code audit and tsx probes against `src/`) - OS + version: not platform-specific - Browser or app shell: not UI-specific ## Logs, screenshots, or video Probe output above. Full write-up: audit findings LTM-SCORE-02, 03 and 07 (local `scratch/audits/ltm-recall-scoring.md`, not tracked). ## Additional context Proposed fix: one bounded per-lane normalization pass in `ranking.ts` and `retrieval.ts`. - Base the boost on the bounded `normalizedRawScore`, or remove the additive term. - Normalize keyword scores against a fixed ceiling (e.g. the exact-phrase score of 4) and require token or word-boundary containment for fuzzy matches. - Map every lane to an absolute bounded scale before weighting, and document the per-style ceilings. - Add a `reciprocalRankFuse` unit test: a deep high-raw bm25 hit vs. the top vector hit across styles, an invariant that the raw boost cannot invert lane weights, and keyword negative cases (substring-only match must not reach relevance = keywordWeight). - Re-tune preset weights and a default threshold (~0.35-0.40) only after this lands. Related: #1246 (separate settings-validation bug). ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-20 17:29:15 +07:00
  • closed this issue
  • added the
    bug
    label
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Agents#639
No description provided.