diff --git a/ruoyi-fastapi-backend/module_admin/service/kb_es_service.py b/ruoyi-fastapi-backend/module_admin/service/kb_es_service.py index d0ccc30..dd46fcb 100644 --- a/ruoyi-fastapi-backend/module_admin/service/kb_es_service.py +++ b/ruoyi-fastapi-backend/module_admin/service/kb_es_service.py @@ -42,8 +42,11 @@ class KBESService: if not question: return [], KBRetrievalMetrics(0.0, 0.0, 0.0, 0, 0.0, False) + # 仅对 KB_PROVIDER=es_bm25:禁用 KBES 检索缓存(避免 curl/API 不一致与历史命中) + enable_retrieval_cache = KBConfig.KB_PROVIDER != 'es_bm25' + cache_hit = False - if redis and KBConfig.KB_CACHE_TTL > 0: + if enable_retrieval_cache and redis and KBConfig.KB_CACHE_TTL > 0: key = cls._cache_key(question) cached = await redis.get(key) if cached: @@ -91,7 +94,7 @@ class KBESService: cache_hit=cache_hit, ) - if redis and KBConfig.KB_CACHE_TTL > 0: + if enable_retrieval_cache and redis and KBConfig.KB_CACHE_TTL > 0: try: key = cls._cache_key(question) await redis.set(