From 9893e93dd15b943112cb0c370b9689bbd4afe2fe Mon Sep 17 00:00:00 2001 From: GG <1592860538@qq.com> Date: Tue, 17 Dec 2024 13:45:39 +0800 Subject: [PATCH 1/2] =?UTF-8?q?refactor(lightrag):=20=E4=BC=98=E5=8C=96has?= =?UTF-8?q?hing=5Fkv=E5=88=9D=E5=A7=8B=E5=8C=96=E9=80=BB=E8=BE=91=20-=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=20llm=5Fmodel=5Ffunc=20=E5=92=8C=20?= =?UTF-8?q?query=20=E6=96=B9=E6=B3=95=E4=B8=AD=E7=9A=84hashing=5Fkv?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=80=BB=E8=BE=91=20-=20=E5=BD=93?= =?UTF-8?q?=20self.llm=5Fresponse=5Fcache=20=E4=B8=8D=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E6=88=96=E6=B2=A1=E6=9C=89=20global=5Fconfig=20=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E6=97=B6=EF=BC=8C=E4=BC=9A=E5=88=9B=E5=BB=BA=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E6=96=B0=E7=9A=84hashing=5Fkv=E5=AE=9E=E4=BE=8B=20-?= =?UTF-8?q?=20=E6=89=80=E6=9C=89=E5=9F=BA=E4=BA=8Ehashing=5Fkv=E8=8E=B7?= =?UTF-8?q?=E5=8F=96global=5Fconfig=E5=B1=9E=E6=80=A7=E7=9A=84=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E5=8F=AF=E4=BB=A5=E6=AD=A3=E5=B8=B8=E8=BF=90=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lightrag/lightrag.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lightrag/lightrag.py b/lightrag/lightrag.py index a32cf621..bff2f3b5 100644 --- a/lightrag/lightrag.py +++ b/lightrag/lightrag.py @@ -252,7 +252,12 @@ class LightRAG: 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( + global_config=asdict(self), + ), **self.llm_model_kwargs, ) ) @@ -515,7 +520,12 @@ class LightRAG: 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( + global_config=asdict(self), + ), ) elif param.mode == "naive": response = await naive_query( @@ -524,7 +534,12 @@ class LightRAG: 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( + global_config=asdict(self), + ), ) else: raise ValueError(f"Unknown mode {param.mode}") 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 2/2] =?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 @@ class LightRAG: 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 @@ class LightRAG: 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 @@ class LightRAG: 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}")