Fix graph truncation logic for depth-limited traversals

• Only set truncated flag for node limit
• Keep depth limit info logging
• Improve log message clarity
• Fix false truncation detection
This commit is contained in:
yangdx 2025-09-24 18:03:11 +08:00
parent ac26f3a2f2
commit f99c4a3738

View file

@ -402,14 +402,14 @@ class NetworkXStorage(BaseGraphStorage):
# Check if graph is truncated - either due to max_nodes limit or depth limit # Check if graph is truncated - either due to max_nodes limit or depth limit
if (queue and len(bfs_nodes) >= max_nodes) or has_unexplored_neighbors: if (queue and len(bfs_nodes) >= max_nodes) or has_unexplored_neighbors:
result.is_truncated = True
if len(bfs_nodes) >= max_nodes: if len(bfs_nodes) >= max_nodes:
result.is_truncated = True
logger.info( logger.info(
f"[{self.workspace}] Graph truncated: max_nodes limit {max_nodes} reached" f"[{self.workspace}] Graph truncated: max_nodes limit {max_nodes} reached"
) )
else: else:
logger.info( logger.info(
f"[{self.workspace}] Graph truncated: only {len(bfs_nodes)} nodes found within max_depth {max_depth}" f"[{self.workspace}] Graph truncated: found {len(bfs_nodes)} nodes within max_depth {max_depth}"
) )
# Create subgraph with BFS discovered nodes # Create subgraph with BFS discovered nodes