Fix #1701: 修复知识库搜索权重计算导致牛头不对马嘴问题

问题:用户问用户组是怎么配置的,系统回复了sdf1_game.md的问答题表格配置块,
而不是protect.md中关于用户组的正确描述。

根因:sdf1_game.md的题目配置格式section body包含完整代码块(数百字符),
gui.py质量分body_len/100给该section大量加分,压过真正答案。

修复(三处):
1. knowledge_base.py: TF-IDF corpus构建时移除代码块内容
2. auto_reply.py: 相关性检查中移除代码块内容
3. gui.py: 质量分计算时截断代码块只计算说明文字长度
This commit is contained in:
youpaishidifu
2026-09-11 22:20:09 +08:00
parent d1ed67358e
commit be91fbad35
3 changed files with 16 additions and 1 deletions
+3
View File
@@ -193,6 +193,9 @@ class AutoReply:
heading_clean = _link.sub(r'\1', heading).lower()
body = doc.get("content", "") or doc.get("body", "")
body_clean = _link.sub(r'\1', body).lower()
# ⭐ 移除代码块内容:避免配置示例/问答数据等代码块污染相关性检查
# 修复"用户组是怎么配置的"被sdf1_game"题目配置格式"(body含代码块)误匹配的问题
body_clean = re.sub(r'```.*?```', '', body_clean, flags=re.DOTALL)
ht_tokens = AutoReply._meaningful_tokens(heading_clean + " " + title)
body_tokens = AutoReply._meaningful_tokens(body_clean[:800])