From 2d048b5eb09bc80553ad3c34c6e5abac9e25f4e1 Mon Sep 17 00:00:00 2001 From: GG <1592860538@qq.com> Date: Tue, 17 Dec 2024 16:44:42 +0800 Subject: [PATCH] =?UTF-8?q?fix(llm):=20hashing=5Fkv=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -hybrid模式对hashing_kv的依赖不止global_config,干脆复用llm_response_cache的初始化结构 --- lightrag/lightrag.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/lightrag/lightrag.py b/lightrag/lightrag.py index a32cf621..69820d9a 100644 --- a/lightrag/lightrag.py +++ b/lightrag/lightrag.py @@ -252,7 +252,14 @@ def __post_init__(self): self.llm_model_func = limit_async_func_call(self.llm_model_max_async)( partial( self.llm_model_func, - hashing_kv=self.llm_response_cache, + hashing_kv=self.llm_response_cache + if self.llm_response_cache + and hasattr(self.llm_response_cache, "global_config") + else self.key_string_value_json_storage_cls( + namespace="llm_response_cache", + global_config=asdict(self), + embedding_func=None, + ), **self.llm_model_kwargs, ) ) @@ -515,7 +522,14 @@ async def aquery(self, query: str, param: QueryParam = QueryParam()): self.text_chunks, param, asdict(self), - hashing_kv=self.llm_response_cache, + hashing_kv=self.llm_response_cache + if self.llm_response_cache + and hasattr(self.llm_response_cache, "global_config") + else self.key_string_value_json_storage_cls( + namespace="llm_response_cache", + global_config=asdict(self), + embedding_func=None, + ), ) elif param.mode == "naive": response = await naive_query( @@ -524,7 +538,14 @@ async def aquery(self, query: str, param: QueryParam = QueryParam()): self.text_chunks, param, asdict(self), - hashing_kv=self.llm_response_cache, + hashing_kv=self.llm_response_cache + if self.llm_response_cache + and hasattr(self.llm_response_cache, "global_config") + else self.key_string_value_json_storage_cls( + namespace="llm_response_cache", + global_config=asdict(self), + embedding_func=None, + ), ) else: raise ValueError(f"Unknown mode {param.mode}")