From 771fce3ef14d3caad614ff12c3faf4e312cbcdc1 Mon Sep 17 00:00:00 2001 From: youpaishidifu Date: Wed, 16 Sep 2026 13:11:29 +0800 Subject: [PATCH] =?UTF-8?q?Task=20#1728:=20=E4=BF=AE=E5=A4=8D'=E8=83=8C?= =?UTF-8?q?=E5=8C=85=E6=8F=92=E4=BB=B6=E6=80=8E=E4=B9=88=E8=A3=85'?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E9=94=99=E8=AF=AFsection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因:protect.md的'操作方式|是否支持'表格通过表格兜底策略被boost到 max_score×2=99.82分,压过beibao.md的'安装方法'(76.32分) 修复: 1. 安装意图查询时,将'安装'加入核心词列表,确保heading含'安装'的 section获得核心词奖励 2. 表格兜底策略:安装/下载意图查询时,表格必须含安装/下载相关词 (安装/下载/前置/插件/依赖)才boost,防止无关表格压过正确答案 --- knowledge_base.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/knowledge_base.py b/knowledge_base.py index 535f166..7f8387c 100644 --- a/knowledge_base.py +++ b/knowledge_base.py @@ -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)