fix(memory): bm25RankToScore returns constant 1.0 for all negative BM25 ranks#14005
fix(memory): bm25RankToScore returns constant 1.0 for all negative BM25 ranks#14005niceysam wants to merge 1 commit intoopenclaw:mainfrom
Conversation
…25 ranks FTS5's bm25() returns negative values where more negative means more relevant. The previous implementation used Math.max(0, rank) which clamped all negative values to 0, causing every keyword match to receive an identical normalized score of 1.0. This effectively discarded BM25 relevance information in hybrid search. Fix: use Math.abs(rank) so negative BM25 scores are correctly converted to positive magnitudes before normalization. Fixes openclaw#5767
This comment was marked as spam.
This comment was marked as spam.
…pstream fixes - Remove Discord, Telegram, Slack, Signal, iMessage, BlueBubbles extensions - Remove @buape/carbon, grammy, and other gateway-specific dependencies - Add session-based login system (cookie auth, rate limiting) - Add type stubs for optional deps (baileys, ciao, qrcode-terminal) - Apply upstream PRs: XSS fix (openclaw#13952), orphan tool_results (openclaw#13974), Anthropic tool ID sanitization (openclaw#13976), BM25 score fix (openclaw#14005), redaction fix (openclaw#14006), subagent timeout (openclaw#13996), context window guard (openclaw#13986), model default reset (openclaw#13993), cache token accounting (openclaw#13853) - Fix all TypeScript compilation errors from channel removal Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Thanks for the feedback! To be honest, I found this through code inspection, not empirical testing. I don't have before/after metrics — just noticed the bug in static analysis. Would be great if someone with production data could validate the improvement. |
bfc1ccb to
f92900f
Compare
Test by
Haven't check long context retrieval. |
|
This pull request has been automatically marked as stale due to inactivity. |
|
+1 from a CJK-heavy deployment. We independently discovered the same bug and applied an identical fix locally. Can confirm:
Our local fix uses a slightly different normalization formula ( This is especially impactful for CJK users where BM25 is already weakened by FTS5 tokenization issues (#20730). Having the BM25 scores that do work actually carry meaningful weight in hybrid ranking is critical. Would love to see this merged. 🙏 |
|
Friendly ping — this PR has been open for 2+ weeks and the stale bot is circling. 🙂 The fix is straightforward (one-line Would love to see this land — happy to help with any requested changes. @m1heng could this get a review when you have a moment? |
Well, I was the one who originally posted PR #5214 a month ago, but apparently it is still not yet merged and closed. 🙂 |
|
Friendly ping for maintainer review — this PR has been open 16 days and the stale bot has already flagged it. Summary: One-line fix (
This is the scoring half of the CJK search problem. I just opened #29396 for the MMR tokenization half. Together with #20730 (FTS5 tokenization), these form a cluster of fixes that would significantly improve memory search for CJK users (see also the real-world report from @KJT125, an ER doctor in Taiwan using Traditional Chinese). The fix is minimal risk — 2 files, +6/−2, pure math correction. Would love to see this land. 🙏 |
|
This PR was closed automatically by AI triage due to current maintainer bandwidth limits. Sorry if this is incorrect — please reopen and comment if we got this wrong, and we will re-review. Reason category: duplicate / superseded by #33757. Why closing:
Sorry for the churn here. If you want to rework this PR around the monotonic negative-rank mapping used in |
FTS5
bm25()returns negative values (more negative = more relevant), butbm25RankToScorewas doingMath.max(0, rank)which clamps all negative scores to 0. That means1 / (1 + 0)= 1.0 for every result, so BM25 relevance was completely thrown away in hybrid search.Fixed by using
Math.abs(rank)instead, which preserves the magnitude while keeping the normalization formula working.Added test assertions for monotonic behavior with negative inputs.
Fixes #5767