fix: 修复下载意图匹配过于宽松导致牛头不对马嘴问题

问题:用户问'登录插件下载地址'时,bot错误匹配到beibao.md(背包插件)而不是sdf1_login.md(登录插件)

根因:下载意图检查只要求标题包含'下载'就放行,没有验证其他核心关键词(如'登录'、'插件')是否匹配文档

修复:
- 如果查询只有'下载'一个核心词 → 放宽检查(普通下载类查询)
- 如果查询有多个核心词(如'登录插件下载地址')→ 要求至少一个其他核心词命中文档
- 未命中时记录debug日志便于排查

测试:预期'登录插件下载地址'现在应匹配sdf1_login.md而非beibao.md
This commit is contained in:
youpaishidifu
2026-08-16 22:45:03 +08:00
parent 3bfdbff40c
commit 8b116ff824
+26 -2
View File
@@ -279,12 +279,36 @@ class AutoReply:
_download_match = False
if any(w in query for w in ('下载', '下到', '哪下', '在哪下', '怎么下')) and '下载' in heading_clean:
if '<br>' not in heading and '- [' not in heading and '|-' not in heading:
_download_match = True
# ⭐ 修复:下载意图检查不能只靠"下载"放行,必须有其他核心词支撑
# 否则"登录插件下载地址"会错误匹配到beibao.md的"下载地址"
# 规则:
# 1. 如果查询只有"下载"一个核心词 → 放宽检查(普通下载类查询)
# 2. 如果查询有多个核心词(如"登录插件下载地址")→ 要求至少一个其他核心词命中
other_core_kw = core_kw - {'下载', '下到', '哪下', '在哪下', '怎么下'}
if not other_core_kw:
# 只有"下载"一个核心词,直接放行
_download_match = True
else:
# 有多个核心词,检查其他核心词是否命中文档
other_hits = sum(1 for kw in other_core_kw if kw in doc_text)
if other_hits >= 1:
_download_match = True
else:
logger.debug(
f"下载意图拒绝(核心词未命中): query={query[:40]!r} "
f"doc_title={title!r} other_kw={other_core_kw!r} hits={other_hits}"
)
else:
# 复合标题:检查标题主体部分(<br>或列表之前)是否含"下载"
_title_part = re.split(r'<br>|- |\|-', heading_clean)[0]
if '下载' in _title_part:
_download_match = True
other_core_kw = core_kw - {'下载', '下到', '哪下', '在哪下', '怎么下'}
if not other_core_kw:
_download_match = True
else:
other_hits = sum(1 for kw in other_core_kw if kw in doc_text)
if other_hits >= 1:
_download_match = True
if _download_match:
logger.debug(f"下载意图放行: query={query[:30]!r} heading={heading[:30]!r}")
return True