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. 尝试从语义缓存获取
|
||||
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,6 +327,9 @@ class IntentAnalyzer:
|
||||
else:
|
||||
logger.warning("意图分析缓存: _get_embedding 返回 None,跳过缓存")
|
||||
else:
|
||||
if is_short_followup:
|
||||
logger.debug(f"跳过语义缓存(短追问依赖上下文): query='{query[:30]}'")
|
||||
elif not cache:
|
||||
logger.warning("意图分析缓存: _get_cache 返回 None,缓存不可用")
|
||||
|
||||
# 构建 prompt
|
||||
|
||||
Reference in New Issue
Block a user