LightRAG icon indicating copy to clipboard operation
LightRAG copied to clipboard

Inserting a multi-part document results in duplicate nodes and edges

Open jin38324 opened this issue 1 year ago • 4 comments

I want to convert a long document into a Lightrage knowledge base. If I convert the entire document directly, one error will lead to a total failure. For the purpose of risk control, the document is divided into multiple parts and insert is performed separately. From the result data, it is found that there are a lot of duplications in nodes and edges.

After investigation, the reason is in the relevant code below. LightRAG will merge nodes and edges with the same name when executing insert; but this is only valid for the same execution of _process_single_content. If you insert multiple documents like I did, the results will not be merged.

https://github.com/HKUDS/LightRAG/blob/874f3b392b959877756bf4828d698fcb53b9c7c9/lightrag/operate.py#L391

jin38324 avatar Dec 18 '24 08:12 jin38324

@jin38324 Hi, have you solved this issue? I want to process multiple documents individually and merge the duplicated nodes or edges into one knowledge graph.

xandery-geek avatar Jan 08 '25 08:01 xandery-geek

@jin38324 Hi, have you solved this issue? I want to process multiple documents individually and merge the duplicated nodes or edges into one knowledge graph.

I dug deeper into the code and found that the problem was not from _merge_nodes_then_upsert. The problem was caused by the data storage part from kg, which set too strict constraints when trying to get existing objects, resulting in the inability to find existing objects, so an insert was performed.

So, if you use the default storage, there should be no problem.

jin38324 avatar Jan 10 '25 03:01 jin38324

The problem was not from _merge_nodes_then_upsert. The problem was caused by the data storage part from kg, which set too strict constraints when trying to get existing objects, resulting in the inability to find existing objects, so an insert was performed.

jin38324 avatar Jan 10 '25 03:01 jin38324

Hi @jin38324 I'm using Neo4j as my graph database and working with large documents that need to be split and processed. I wanted to know: Will similar entities and relationships be merged automatically, or do I need to configure something for that? Also, if for default LightrAG storage, it handle merging of entities across multiple documents automatically right? Could you please explain how this works?

Utkarshagharat58 avatar Apr 29 '25 02:04 Utkarshagharat58