增加日志

This commit is contained in:
Tian jianyong 2025-12-24 19:07:10 +08:00
parent 09ca6948f0
commit 1f65967551

View File

@ -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,