From 1f65967551f396bb7649479419ca69469554b103 Mon Sep 17 00:00:00 2001 From: Tian jianyong <11429339@qq.com> Date: Wed, 24 Dec 2025 19:07:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-fastapi-backend/utils/semantic_cache_service.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ruoyi-fastapi-backend/utils/semantic_cache_service.py b/ruoyi-fastapi-backend/utils/semantic_cache_service.py index 915d367..3dd9ea3 100644 --- a/ruoyi-fastapi-backend/utils/semantic_cache_service.py +++ b/ruoyi-fastapi-backend/utils/semantic_cache_service.py @@ -91,7 +91,9 @@ class SemanticCacheService: """对问题进行哈希,生成唯一标识""" # 标准化问题文本(去除多余空格、统一标点) normalized = self._normalize_question(question) - return hashlib.md5(normalized.encode('utf-8')).hexdigest()[:16] + hash_value = hashlib.md5(normalized.encode('utf-8')).hexdigest()[:16] + logger.debug(f"[SemanticCache] Hash计算 | 原始={question} | 标准化={normalized} | hash={hash_value}") + return hash_value def _normalize_question(self, question: str) -> str: """标准化问题文本""" @@ -135,6 +137,8 @@ class SemanticCacheService: question_hash = self._hash_question(question) exact_key = self._build_cache_key(chat_id, question_hash) + logger.info(f"[SemanticCache] 精确查找 | chat_id={chat_id} | question={question} | hash={question_hash} | key={exact_key}") + cached_data = await redis.get(exact_key) if cached_data: entry = CacheEntry.from_dict(json.loads(cached_data)) @@ -226,6 +230,8 @@ class SemanticCacheService: question_hash = self._hash_question(question) cache_key = self._build_cache_key(chat_id, question_hash) + logger.info(f"[SemanticCache] 存储缓存 | chat_id={chat_id} | question={question} | hash={question_hash} | key={cache_key}") + entry = CacheEntry( question=question, answer=answer,