fix(backend): FTS 阈值过滤处理 span=0 退化场景

全部命中 bm25 相同时归一化皆为 1.0,阈值超过 1.0 应无命中,
与旧 normalize_scores 语义对齐。

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
yxx
2026-09-03 23:57:00 +08:00
co-authored by Claude Code
parent ae65c64c8f
commit abccb328fc
+8 -2
View File
@@ -161,10 +161,16 @@ class RetrievalEngine:
return self._empty(request) return self._empty(request)
lo, hi = bounds lo, hi = bounds
span = hi - lo
bm25_max: float | None = None bm25_max: float | None = None
if request.score_threshold > 0: if request.score_threshold > 0:
# norm = (hi - bm25) / (hi - lo)norm >= threshold ⟺ bm25 <= hi - threshold*(hi - lo) if span == 0:
bm25_max = hi - request.score_threshold * (hi - lo) # 全部命中 bm25 相同,归一化后皆为 1.0;阈值超过 1.0 时无命中
if request.score_threshold > 1.0:
return self._empty(request)
else:
# norm = (hi - bm25) / spannorm >= threshold ⟺ bm25 <= hi - threshold * span
bm25_max = hi - request.score_threshold * span
fts_hits, total = repository.fts_search_page( fts_hits, total = repository.fts_search_page(
match=match, match=match,