fix(kb): 添加语义意图验证,防止OCR错字导致错误匹配

问题:查询'那录插件的pHp后端那管理员默认密码是多少?'(OCR将'登'识别为'录'),
beibao.md的'使用方法-管理员'(score=79)压过phpadmin.md的'php管理员后端'(score=64)。

修复:增加语义意图验证规则:
1. 查询含'php'+'后端/管理'时,heading必须含'php'或'管理'
2. 查询含'管理员密码'时,heading必须含'密码/管理/php'

效果:php管理密码查询现在正确返回phpadmin.md的'## php管理员后端'
This commit is contained in:
youpaishidifu
2026-08-13 16:03:01 +08:00
parent 8d648f37fb
commit 256935d70c
+13
View File
@@ -168,6 +168,19 @@ class AutoReply:
logger.debug(f"前台关键词缺失: query={query[:40]!r} doc={doc.get('heading', '')[:30]!r}")
return False
# ⭐ 语义意图验证:OCR查询可能含错字(如"录"→"登"、"php"→"pHp"),
# 需要结合heading确认查询意图,防止"云背包管理员密码"压过"php管理员后端"
# 查询含"php"+"后端"时,heading必须含"php"或"管理"
if 'php' in query.lower() and ('后端' in query or '管理' in query):
if 'php' not in heading_clean and '管理' not in heading_clean:
logger.debug(f"php查询意图不匹配: query={query[:40]!r} heading={heading[:30]!r}")
return False
# 查询含"管理员密码"时,heading必须含"密码"或"管理"或"php"
if '管理员' in query and '密码' in query:
if '密码' not in heading_clean and '管理' not in heading_clean and 'php' not in heading_clean:
logger.debug(f"管理员密码查询意图不匹配: query={query[:40]!r} heading={heading[:30]!r}")
return False
if has_ht or has_body:
# ⭐ 正文覆盖不足防御(牛头不对马嘴修复):
# 当 heading 无命中但有 body 命中时,检查 body 覆盖了多少查询词。