From f0b99bf6b72cb9cfc18d338f4e50de9f92625e09 Mon Sep 17 00:00:00 2001 From: octo-patch Date: Sat, 18 Apr 2026 11:20:14 +0800 Subject: [PATCH] fix: correctly flatten update_community results in add_episode (fixes #1396) semaphore_gather returns a list of N tuples (one per coroutine), where each tuple is (list[CommunityNode], list[CommunityEdge]). The previous code unpacked this as `communities, community_edges = `, which only worked accidentally when exactly 2 nodes were extracted. Replace the tuple unpack with an explicit loop that extends the accumulated lists, making it work correctly for any number of extracted entity nodes. --- graphiti_core/graphiti.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/graphiti_core/graphiti.py b/graphiti_core/graphiti.py index 8c4943e89..45e4bcc05 100644 --- a/graphiti_core/graphiti.py +++ b/graphiti_core/graphiti.py @@ -1114,16 +1114,19 @@ async def add_episode_endpoint(episode_data: EpisodeData): ) # Update communities if requested - communities = [] - community_edges = [] + communities: list[CommunityNode] = [] + community_edges: list[CommunityEdge] = [] if update_communities: - communities, community_edges = await semaphore_gather( + per_node_results = await semaphore_gather( *[ update_community(self.driver, self.llm_client, self.embedder, node) for node in nodes ], max_coroutines=self.max_coroutines, ) + for node_communities, node_community_edges in per_node_results: + communities.extend(node_communities) + community_edges.extend(node_community_edges) end = time()