From 5bc86a7c1f4d954dd3fc2825707d31b665bc196f Mon Sep 17 00:00:00 2001 From: lacerate551 <128470311+lacerate551@users.noreply.github.com> Date: Sat, 20 Jun 2026 22:35:29 +0800 Subject: [PATCH] fix: skip semantic cache for short follow-up queries to avoid false hits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Short follow-ups like "B3类呢?" are too context-dependent for embedding similarity matching. Only exact-match cache is used when history exists and query is under 20 chars. --- core/intent_analyzer.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/intent_analyzer.py b/core/intent_analyzer.py index eabba0c..01d83a8 100644 --- a/core/intent_analyzer.py +++ b/core/intent_analyzer.py @@ -309,7 +309,9 @@ class IntentAnalyzer: # 2. 尝试从语义缓存获取 cache = self._get_cache() - if cache: + # 短追问(如"B3类呢?")严重依赖上下文,embedding 区分度不足易误命中 + is_short_followup = history and len(query.strip()) < 20 + if cache and not is_short_followup: # 使用 query + 历史关键信息作为缓存键 cache_key = self._build_cache_key(query, history) cache_emb = self._get_embedding(cache_key) @@ -325,7 +327,10 @@ class IntentAnalyzer: else: logger.warning("意图分析缓存: _get_embedding 返回 None,跳过缓存") else: - logger.warning("意图分析缓存: _get_cache 返回 None,缓存不可用") + if is_short_followup: + logger.debug(f"跳过语义缓存(短追问依赖上下文): query='{query[:30]}'") + elif not cache: + logger.warning("意图分析缓存: _get_cache 返回 None,缓存不可用") # 构建 prompt user_prompt = f"""## 对话历史