fix: 缓存系统全面加固 — 版本失效 + 死代码清理 + 防御性改进

基于缓存审查报告 + Claude Code 交叉审查的反馈:

P0+ 语义缓存版本失效:
- sync.py: 文档变更后清空语义缓存,防止返回过时的 images/sources
- document_routes.py: 删除文档时同步清理缓存
- kb_routes.py: 删除向量库时同步清理缓存

P1.5 cache_type 包含式校验:
- intent_analyzer.py: != "rag_answer" 改为 == "intent_analysis"

P2+ Rerank Cache 版本失效:
- cache.py: increment_kb_version 时同时清空 rerank_cache

P1+P6 死代码清理:
- agentic.py: 移除未使用的 SemanticCache 实例和相关导入
- agentic_base.py: 移除未使用的语义缓存配置导入
- cache.py: 移除 _compute_doc_hash 和未使用的 doc_ids 参数
- engine.py: 移除 set_query_result 调用中的 doc_ids 参数

P7 缓存质量门槛:
- config.py: CACHE_MIN_SCORE 从 0.0 改为 0.3
This commit is contained in:
lacerate551
2026-06-21 16:08:58 +08:00
parent 21470ed28c
commit 0f339a0998
8 changed files with 58 additions and 107 deletions

View File

@@ -316,8 +316,8 @@ class IntentAnalyzer:
if query_emb is not None:
cached = cache.get(query_emb)
# 确保缓存条目是意图分析结果(非 RAG 回答缓存
if cached and cached.get("cache_type") != "rag_answer":
# 确保缓存条目是意图分析结果(包含式校验,避免新增缓存类型时误命中
if cached and cached.get("cache_type") == "intent_analysis":
# 二次验证:检查原始 query 文本相似度
cached_query = cached.get("_raw_query", "")
if cached_query and self._query_text_similar(query, cached_query):