Skip to content

Commit

Permalink
refactor(lightrag): 优化hashing_kv初始化逻辑
Browse files Browse the repository at this point in the history
- 修改了 llm_model_func 和 query 方法中的hashing_kv初始化逻辑
- 当 self.llm_response_cache 不存在或没有 global_config 属性时,会创建一个新的hashing_kv实例
- 所有基于hashing_kv获取global_config属性的对象可以正常运行
  • Loading branch information
theClassLight committed Dec 17, 2024
1 parent a3bf3a5 commit 9893e93
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions lightrag/lightrag.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,12 @@ 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(
global_config=asdict(self),
),
**self.llm_model_kwargs,
)
)
Expand Down Expand Up @@ -515,7 +520,12 @@ 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(
global_config=asdict(self),
),
)
elif param.mode == "naive":
response = await naive_query(
Expand All @@ -524,7 +534,12 @@ 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(
global_config=asdict(self),
),
)
else:
raise ValueError(f"Unknown mode {param.mode}")
Expand Down

0 comments on commit 9893e93

Please sign in to comment.