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"""## 对话历史