From abccb328fc98d4cbab54fdf6496941aee7e8aed7 Mon Sep 17 00:00:00 2001 From: yxx <2412119399@qq.com> Date: Thu, 3 Sep 2026 23:57:00 +0800 Subject: [PATCH] =?UTF-8?q?fix(backend):=20FTS=20=E9=98=88=E5=80=BC?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=E5=A4=84=E7=90=86=20span=3D0=20=E9=80=80?= =?UTF-8?q?=E5=8C=96=E5=9C=BA=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 全部命中 bm25 相同时归一化皆为 1.0,阈值超过 1.0 应无命中, 与旧 normalize_scores 语义对齐。 Co-Authored-By: Claude Code --- backend/app/retrieval/engine.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/app/retrieval/engine.py b/backend/app/retrieval/engine.py index 0688f34..e09ef27 100644 --- a/backend/app/retrieval/engine.py +++ b/backend/app/retrieval/engine.py @@ -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,