From c0d6604981225e2f15fc0fc4170445dc27a5060a Mon Sep 17 00:00:00 2001 From: lixiangcheng1 Date: Thu, 18 Dec 2025 18:51:32 +0800 Subject: [PATCH] [fix]document chunk QA --- api/app/core/rag/graphrag/utils.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/api/app/core/rag/graphrag/utils.py b/api/app/core/rag/graphrag/utils.py index 65beb31f..a2290516 100644 --- a/api/app/core/rag/graphrag/utils.py +++ b/api/app/core/rag/graphrag/utils.py @@ -1,12 +1,23 @@ import xxhash -from app.aioRedis import aio_redis_set, aio_redis_get +import redis +from app.core.config import settings + +redis_client = redis.StrictRedis( + host=settings.REDIS_HOST, + port=settings.REDIS_PORT, + db=settings.REDIS_DB, + password=settings.REDIS_PASSWORD, + decode_responses=True, + max_connections=30 +) + def get_llm_cache(llmnm, txt, history, genconf): hasher = xxhash.xxh64() - hasher.update((str(llmnm)+str(txt)+str(history)+str(genconf)).encode("utf-8")) + hasher.update((str(llmnm) + str(txt) + str(history) + str(genconf)).encode("utf-8")) k = hasher.hexdigest() - bin = aio_redis_get(k) + bin = redis_client.get(k) if not bin: return None return bin @@ -14,6 +25,6 @@ def get_llm_cache(llmnm, txt, history, genconf): def set_llm_cache(llmnm, txt, v, history, genconf): hasher = xxhash.xxh64() - hasher.update((str(llmnm)+str(txt)+str(history)+str(genconf)).encode("utf-8")) + hasher.update((str(llmnm) + str(txt) + str(history) + str(genconf)).encode("utf-8")) k = hasher.hexdigest() - aio_redis_set(k, v.encode("utf-8"), 24 * 3600) + redis_client.set(k, v.encode("utf-8"), 24 * 3600)