修复KB搜索3项:疑问词不当降权 + 文档聚合tiebreaker + section弱匹配不计入

This commit is contained in:
youpaishidifu
2026-07-29 00:09:22 +08:00
parent 4da415f9c5
commit 718f67804c
+6 -3
View File
@@ -317,17 +317,20 @@ class KnowledgeBase:
score = combined_scores[i]
if score >= min_score:
doc_best[t] = max(doc_best.get(t, 0), score)
doc_count[t] = doc_count.get(t, 0) + 1
# 只统计强匹配 section(≥2×min_score),弱匹配不计入 bonus
if score >= min_score * 2:
doc_count[t] = doc_count.get(t, 0) + 1
else:
doc_best[t] = max(doc_best.get(t, 0), score)
if not doc_best:
return []
# 文档级排序:主分(最高 section 分) + 0.02 * section 数量(打破单个高分 lucky hit)
# 文档级排序:主分优先,doc_count 仅做 tiebreaker(section 数更多→多角度匹配)
# 弱匹配(score < min_score*2)不计入 doc_count,防低分堆叠
sorted_docs = sorted(
doc_best.items(),
key=lambda x: x[1] + 0.02 * doc_count.get(x[0], 0),
key=lambda x: (x[1], doc_count.get(x[0], 0)),
reverse=True
)