Task #1728: 修复'背包插件怎么装'匹配错误section
根因:protect.md的'操作方式|是否支持'表格通过表格兜底策略被boost到 max_score×2=99.82分,压过beibao.md的'安装方法'(76.32分) 修复: 1. 安装意图查询时,将'安装'加入核心词列表,确保heading含'安装'的 section获得核心词奖励 2. 表格兜底策略:安装/下载意图查询时,表格必须含安装/下载相关词 (安装/下载/前置/插件/依赖)才boost,防止无关表格压过正确答案
This commit is contained in:
@@ -532,6 +532,9 @@ class KnowledgeBase:
|
||||
if len(query_stripped) < 2 or len(tokens) == 0:
|
||||
return []
|
||||
|
||||
# ⭐ 检测安装意图:查询包含"安装/怎么装/如何安装"等词
|
||||
has_install_keyword = any(w in query_stripped for w in ('安装', '怎么装', '如何安装', '安装方法', '安装步骤', '安装教程'))
|
||||
|
||||
# ⭐ 过滤查询停用词:通用名词(服务器、玩家、游戏等)会导致TF-IDF虚高
|
||||
# 修复"服务器的公告"被player.md"运营方权利"压过index.md"近期公告"的问题
|
||||
from auto_reply import AutoReply
|
||||
@@ -583,6 +586,10 @@ class KnowledgeBase:
|
||||
# 核心词:查询tokens中长度>=2且不在停用词表中的词
|
||||
from auto_reply import AutoReply
|
||||
query_core_tokens = set(t for t in jieba.cut(query_stripped) if len(t) >= 2 and t not in AutoReply._STOPWORDS)
|
||||
# ⭐ 修复:安装意图查询时,将"安装"也加入核心词列表
|
||||
# 防止"背包插件怎么装"被protect.md的"登录插件"链接文本压过
|
||||
if has_install_keyword:
|
||||
query_core_tokens.add('安装')
|
||||
for i, doc in enumerate(self.docs):
|
||||
heading = doc.get("heading", "")
|
||||
# 清理链接语法
|
||||
@@ -884,6 +891,15 @@ class KnowledgeBase:
|
||||
body = doc.get("body", "").strip()
|
||||
heading = doc.get("heading", "")
|
||||
if body.startswith('|') and '|' in body[1:] and ('操作' in body or '支持' in body):
|
||||
# ⭐ 修复:安装/下载意图查询时,不强制加入无关表格
|
||||
# 防止"背包插件怎么装"被protect.md"操作方式|是否支持"表格压过
|
||||
_query_is_install_or_download = has_install_keyword or download_intent
|
||||
if _query_is_install_or_download:
|
||||
# 安装/下载意图:表格必须含安装/下载相关词才boost
|
||||
_install_or_dl_terms = {'安装', '下载', '前置', '插件', '依赖'}
|
||||
_tbl_has_relevance = any(t in body for t in _install_or_dl_terms)
|
||||
if not _tbl_has_relevance:
|
||||
continue # 跳过无关表格
|
||||
# 检查heading是否与查询语义相关
|
||||
h_tokens = set(t for t in jieba.cut(heading) if len(t) >= 2)
|
||||
heading_relevant = bool(query_tokens_set & h_tokens)
|
||||
|
||||
Reference in New Issue
Block a user