diff --git a/lightrag/operate.py b/lightrag/operate.py index 10cb251e..e976a5b4 100644 --- a/lightrag/operate.py +++ b/lightrag/operate.py @@ -681,7 +681,13 @@ async def _rebuild_single_entity( "description": final_description, "entity_type": entity_type, "source_id": GRAPH_FIELD_SEP.join(chunk_ids), - "file_path": GRAPH_FIELD_SEP.join(file_paths) + "file_path": build_file_path( + current_entity.get("file_path", "").split(GRAPH_FIELD_SEP) + if current_entity.get("file_path") + else [], + [{"file_path": fp} for fp in file_paths], + entity_name, + ) if file_paths else current_entity.get("file_path", "unknown_source"), } @@ -894,7 +900,13 @@ async def _rebuild_single_relationship( "keywords": combined_keywords, "weight": weight, "source_id": GRAPH_FIELD_SEP.join(chunk_ids), - "file_path": GRAPH_FIELD_SEP.join([fp for fp in file_paths if fp]) + "file_path": build_file_path( + current_relationship.get("file_path", "").split(GRAPH_FIELD_SEP) + if current_relationship.get("file_path") + else [], + [{"file_path": fp} for fp in file_paths if fp], + f"{src}-{tgt}", + ) if file_paths else current_relationship.get("file_path", "unknown_source"), } @@ -1100,12 +1112,7 @@ async def _merge_edges_then_upsert( + already_source_ids ) ) - file_path = GRAPH_FIELD_SEP.join( - set( - [dp["file_path"] for dp in edges_data if dp.get("file_path")] - + [fp for fp in already_file_paths if fp] - ) - ) + file_path = build_file_path(already_file_paths, edges_data, f"{src_id}-{tgt_id}") for need_insert_id in [src_id, tgt_id]: if not (await knowledge_graph_inst.has_node(need_insert_id)):