From be2d938c849541a10b76cb39c914c3b512bb24fe Mon Sep 17 00:00:00 2001 From: yangdx Date: Thu, 17 Jul 2025 18:33:14 +0800 Subject: [PATCH] Fix file path handling in graph operations - Filter out empty file paths - Handle missing file_path fields --- lightrag/operate.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lightrag/operate.py b/lightrag/operate.py index 77eaa70c..1e5f96bc 100644 --- a/lightrag/operate.py +++ b/lightrag/operate.py @@ -871,7 +871,7 @@ async def _rebuild_single_relationship( "keywords": combined_keywords, "weight": weight, "source_id": GRAPH_FIELD_SEP.join(chunk_ids), - "file_path": GRAPH_FIELD_SEP.join(file_paths) + "file_path": GRAPH_FIELD_SEP.join([fp for fp in file_paths if fp]) if file_paths else current_relationship.get("file_path", "unknown_source"), } @@ -947,7 +947,14 @@ async def _merge_nodes_then_upsert( set([dp["source_id"] for dp in nodes_data] + already_source_ids) ) file_path = GRAPH_FIELD_SEP.join( - set([dp["file_path"] for dp in nodes_data] + already_file_paths) + set( + [ + dp.get("file_path", "unknown_source") + for dp in nodes_data + if dp.get("file_path") + ] + + [fp for fp in already_file_paths if fp] + ) ) force_llm_summary_on_merge = global_config["force_llm_summary_on_merge"] @@ -1082,7 +1089,7 @@ async def _merge_edges_then_upsert( file_path = GRAPH_FIELD_SEP.join( set( [dp["file_path"] for dp in edges_data if dp.get("file_path")] - + already_file_paths + + [fp for fp in already_file_paths if fp] ) )