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:
@@ -161,10 +161,16 @@ class RetrievalEngine:
|
||||
return self._empty(request)
|
||||
|
||||
lo, hi = bounds
|
||||
span = hi - lo
|
||||
bm25_max: float | None = None
|
||||
if request.score_threshold > 0:
|
||||
# norm = (hi - bm25) / (hi - lo);norm >= threshold ⟺ bm25 <= hi - threshold*(hi - lo)
|
||||
bm25_max = hi - request.score_threshold * (hi - lo)
|
||||
if span == 0:
|
||||
# 全部命中 bm25 相同,归一化后皆为 1.0;阈值超过 1.0 时无命中
|
||||
if request.score_threshold > 1.0:
|
||||
return self._empty(request)
|
||||
else:
|
||||
# norm = (hi - bm25) / span;norm >= threshold ⟺ bm25 <= hi - threshold * span
|
||||
bm25_max = hi - request.score_threshold * span
|
||||
|
||||
fts_hits, total = repository.fts_search_page(
|
||||
match=match,
|
||||
|
||||
Reference in New Issue
Block a user