fix: skip semantic cache for short follow-up queries to avoid false hits
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.
This commit is contained in:
@@ -309,7 +309,9 @@ class IntentAnalyzer:
|
|||||||
|
|
||||||
# 2. 尝试从语义缓存获取
|
# 2. 尝试从语义缓存获取
|
||||||
cache = self._get_cache()
|
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 + 历史关键信息作为缓存键
|
# 使用 query + 历史关键信息作为缓存键
|
||||||
cache_key = self._build_cache_key(query, history)
|
cache_key = self._build_cache_key(query, history)
|
||||||
cache_emb = self._get_embedding(cache_key)
|
cache_emb = self._get_embedding(cache_key)
|
||||||
@@ -325,7 +327,10 @@ class IntentAnalyzer:
|
|||||||
else:
|
else:
|
||||||
logger.warning("意图分析缓存: _get_embedding 返回 None,跳过缓存")
|
logger.warning("意图分析缓存: _get_embedding 返回 None,跳过缓存")
|
||||||
else:
|
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
|
# 构建 prompt
|
||||||
user_prompt = f"""## 对话历史
|
user_prompt = f"""## 对话历史
|
||||||
|
|||||||
Reference in New Issue
Block a user