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
+7
View File
@@ -1234,6 +1234,13 @@ class MsgBotApp(ctk.CTk):
if rel:
# 计算质量分:body越长、有表格/链接列表,质量越高
body = doc.get('body', '') or doc.get('content', '')
body_full_len = len(body.strip())
# ⭐ 代码块长度惩罚:body含```代码块时,代码块内容(如配置格式示例、问答数据)
# 不应贡献body_len加分。截断到代码块起始位置,只计算"说明文字"的长度。
# 修复"用户组是怎么配置的"被sdf1_game"题目配置格式"(body含完整代码块)压过的问题
_code_block_idx = body.find('```')
if _code_block_idx >= 0:
body = body[:_code_block_idx]
body_len = len(body.strip())
# 下载类查询优先选择详细表格,而非简略提示
is_download_query = any(w in cleaned_msg for w in ('下载', '下到', '哪下', '怎么下'))