Restore 0.1.5 version from stash
This commit is contained in:
@@ -7,7 +7,7 @@ import inspect
|
||||
import os
|
||||
import time
|
||||
import warnings
|
||||
from dataclasses import asdict, dataclass, field
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime, timezone
|
||||
from functools import partial
|
||||
from typing import (
|
||||
@@ -516,7 +516,8 @@ class LightRAG:
|
||||
)
|
||||
|
||||
# Fix global_config now
|
||||
global_config = asdict(self)
|
||||
# 避免 deepcopy 带来的 asyncpg __reduce__ 异常,统一使用浅复制配置
|
||||
global_config = self._global_config()
|
||||
|
||||
_print_config = ",\n ".join([f"{k} = {v}" for k, v in global_config.items()])
|
||||
logger.debug(f"LightRAG init with param:\n {_print_config}\n")
|
||||
@@ -655,6 +656,10 @@ class LightRAG:
|
||||
|
||||
self._storages_status = StoragesStatus.CREATED
|
||||
|
||||
def _global_config(self) -> dict[str, Any]:
|
||||
"""浅拷贝全局配置,避免 dataclasses.asdict 深拷贝底层连接对象。"""
|
||||
return dict(self.__dict__)
|
||||
|
||||
async def initialize_storages(self):
|
||||
"""Storage initialization must be called one by one to prevent deadlock"""
|
||||
if self._storages_status == StoragesStatus.CREATED:
|
||||
@@ -1863,12 +1868,16 @@ class LightRAG:
|
||||
await asyncio.gather(*first_stage_tasks)
|
||||
|
||||
# Stage 2: Process entity relation graph (after text_chunks are saved)
|
||||
entity_relation_task = asyncio.create_task(
|
||||
self._process_extract_entities(
|
||||
chunks, pipeline_status, pipeline_status_lock
|
||||
# 可通过环境变量关闭实体/关系抽取,避免非必要的 KG 处理带来的失败
|
||||
if not os.getenv("LIGHTRAG_DISABLE_ENTITY_RELATION", "false").lower() == "true":
|
||||
entity_relation_task = asyncio.create_task(
|
||||
self._process_extract_entities(
|
||||
chunks, pipeline_status, pipeline_status_lock
|
||||
)
|
||||
)
|
||||
)
|
||||
chunk_results = await entity_relation_task
|
||||
chunk_results = await entity_relation_task
|
||||
else:
|
||||
chunk_results = []
|
||||
file_extraction_stage_ok = True
|
||||
|
||||
except Exception as e:
|
||||
@@ -1951,24 +1960,25 @@ class LightRAG:
|
||||
)
|
||||
|
||||
# Use chunk_results from entity_relation_task
|
||||
await merge_nodes_and_edges(
|
||||
chunk_results=chunk_results, # result collected from entity_relation_task
|
||||
knowledge_graph_inst=self.chunk_entity_relation_graph,
|
||||
entity_vdb=self.entities_vdb,
|
||||
relationships_vdb=self.relationships_vdb,
|
||||
global_config=asdict(self),
|
||||
full_entities_storage=self.full_entities,
|
||||
full_relations_storage=self.full_relations,
|
||||
doc_id=doc_id,
|
||||
pipeline_status=pipeline_status,
|
||||
pipeline_status_lock=pipeline_status_lock,
|
||||
llm_response_cache=self.llm_response_cache,
|
||||
entity_chunks_storage=self.entity_chunks,
|
||||
relation_chunks_storage=self.relation_chunks,
|
||||
current_file_number=current_file_number,
|
||||
total_files=total_files,
|
||||
file_path=file_path,
|
||||
)
|
||||
if not os.getenv("LIGHTRAG_DISABLE_ENTITY_RELATION", "false").lower() == "true":
|
||||
await merge_nodes_and_edges(
|
||||
chunk_results=chunk_results, # result collected from entity_relation_task
|
||||
knowledge_graph_inst=self.chunk_entity_relation_graph,
|
||||
entity_vdb=self.entities_vdb,
|
||||
relationships_vdb=self.relationships_vdb,
|
||||
global_config=self._global_config(),
|
||||
full_entities_storage=self.full_entities,
|
||||
full_relations_storage=self.full_relations,
|
||||
doc_id=doc_id,
|
||||
pipeline_status=pipeline_status,
|
||||
pipeline_status_lock=pipeline_status_lock,
|
||||
llm_response_cache=self.llm_response_cache,
|
||||
entity_chunks_storage=self.entity_chunks,
|
||||
relation_chunks_storage=self.relation_chunks,
|
||||
current_file_number=current_file_number,
|
||||
total_files=total_files,
|
||||
file_path=file_path,
|
||||
)
|
||||
|
||||
# Record processing end time
|
||||
processing_end_time = int(time.time())
|
||||
@@ -2139,7 +2149,7 @@ class LightRAG:
|
||||
try:
|
||||
chunk_results = await extract_entities(
|
||||
chunk,
|
||||
global_config=asdict(self),
|
||||
global_config=self._global_config(),
|
||||
pipeline_status=pipeline_status,
|
||||
pipeline_status_lock=pipeline_status_lock,
|
||||
llm_response_cache=self.llm_response_cache,
|
||||
@@ -2553,7 +2563,7 @@ class LightRAG:
|
||||
actual data is nested under the 'data' field, with 'status' and 'message'
|
||||
fields at the top level.
|
||||
"""
|
||||
global_config = asdict(self)
|
||||
global_config = self._global_config()
|
||||
|
||||
# Create a copy of param to avoid modifying the original
|
||||
data_param = QueryParam(
|
||||
@@ -2671,7 +2681,7 @@ class LightRAG:
|
||||
"""
|
||||
logger.debug(f"[aquery_llm] Query param: {param}")
|
||||
|
||||
global_config = asdict(self)
|
||||
global_config = self._global_config()
|
||||
|
||||
try:
|
||||
query_result = None
|
||||
@@ -3462,7 +3472,7 @@ class LightRAG:
|
||||
relationships_vdb=self.relationships_vdb,
|
||||
text_chunks_storage=self.text_chunks,
|
||||
llm_response_cache=self.llm_response_cache,
|
||||
global_config=asdict(self),
|
||||
global_config=self._global_config(),
|
||||
pipeline_status=pipeline_status,
|
||||
pipeline_status_lock=pipeline_status_lock,
|
||||
entity_chunks_storage=self.entity_chunks,
|
||||
|
||||
Reference in New Issue
Block a user