修复三个问题:病句过滤、KB回复内容、截图保存日志
1. 病句过滤改进(monitor.py): - ≤5字短句:必须包含疑问词(什么/怎么/如何/为什么/吗/呢等)才放行 - 无疑问词的短句直接过滤(如'自行修?') - 5-50字病句:增加'过'字匹配(如'修正过后') 2. KB回复内容改进(auto_reply.py + knowledge_base.py): - _get_answer 改为返回 body(纯正文),不含 heading - KB搜索增加heading包含查询关键词的bonus - 文档头部(# 文档名)增加penalty,避免返回错误section 3. 截图保存日志改进(monitor.py): - QQ/微信截图保存失败日志从 debug 升级为 warning - 增加保存路径提示,便于定位问题
This commit is contained in:
@@ -406,6 +406,23 @@ class KnowledgeBase:
|
||||
continue
|
||||
|
||||
# 同文档内,根据查询意图优先选合适的 section
|
||||
# 1. heading 包含查询关键词 → bonus;文档头部(仅含文档名)→ penalty
|
||||
query_tokens = set(t for t in jieba.cut(query_stripped) if len(t) >= 2)
|
||||
reranked = []
|
||||
for idx, doc, score in doc_sections:
|
||||
heading = doc.get("heading", "")
|
||||
body = doc.get("body", doc.get("content", ""))
|
||||
h_tokens = set(t for t in jieba.cut(heading) if len(t) >= 2)
|
||||
# heading 包含查询关键词 → bonus
|
||||
heading_hits = len(query_tokens & h_tokens)
|
||||
bonus = heading_hits * 2.0
|
||||
# 文档头部惩罚:heading 是单层 # + 文档名(如 "# php管理员后端"),且无 body
|
||||
if heading.startswith("# ") and (not body or len(body) < 50):
|
||||
bonus -= 5.0
|
||||
reranked.append((idx, doc, score + bonus))
|
||||
reranked.sort(key=lambda x: x[2], reverse=True)
|
||||
doc_sections = reranked
|
||||
|
||||
if has_action and len(doc_sections) > 1:
|
||||
# 动作查询:提取动词+对象,精准匹配 section
|
||||
# 如"怎么打印流水" → verb="打印", obj="流水",优先选 heading 同时含两者的 section
|
||||
|
||||
Reference in New Issue
Block a user