refactor(lightrag): 优化hashing_kv初始化逻辑

- 修改了 llm_model_func 和 query 方法中的hashing_kv初始化逻辑
- 当 self.llm_response_cache 不存在或没有 global_config 属性时,会创建一个新的hashing_kv实例
- 所有基于hashing_kv获取global_config属性的对象可以正常运行
This commit is contained in:
GG
2024-12-17 13:45:39 +08:00
parent a3bf3a58f0
commit 9893e93dd1

View File

@@ -252,7 +252,12 @@ class LightRAG:
self.llm_model_func = limit_async_func_call(self.llm_model_max_async)( self.llm_model_func = limit_async_func_call(self.llm_model_max_async)(
partial( partial(
self.llm_model_func, 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, **self.llm_model_kwargs,
) )
) )
@@ -515,7 +520,12 @@ class LightRAG:
self.text_chunks, self.text_chunks,
param, param,
asdict(self), 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": elif param.mode == "naive":
response = await naive_query( response = await naive_query(
@@ -524,7 +534,12 @@ class LightRAG:
self.text_chunks, self.text_chunks,
param, param,
asdict(self), 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: else:
raise ValueError(f"Unknown mode {param.mode}") raise ValueError(f"Unknown mode {param.mode}")