Skip to content

fix: correctly flatten update_community results in add_episode#1421

Open
octo-patch wants to merge 1 commit intogetzep:mainfrom
octo-patch:fix/issue-1396-add-episode-tuple-unpack
Open

fix: correctly flatten update_community results in add_episode#1421
octo-patch wants to merge 1 commit intogetzep:mainfrom
octo-patch:fix/issue-1396-add-episode-tuple-unpack

Conversation

@octo-patch
Copy link
Copy Markdown

Fixes #1396

Problem

add_episode crashes with ValueError: too many / not enough values to unpack when the number of extracted entity nodes is anything other than exactly 2.

The root cause: semaphore_gather returns a list of N tuples (one per coroutine), where each tuple is (list[CommunityNode], list[CommunityEdge]). The previous code did:

communities, community_edges = await semaphore_gather(...)

This Python unpacking treats the returned list as if it has exactly 2 items, so it only worked by accident when N == 2. For N == 1 it raises ValueError: not enough values to unpack; for N >= 3 it raises ValueError: too many values to unpack.

Solution

Replace the tuple unpack with an explicit accumulation loop:

per_node_results = await semaphore_gather(...)
for node_communities, node_community_edges in per_node_results:
    communities.extend(node_communities)
    community_edges.extend(node_community_edges)

This correctly aggregates results across all nodes regardless of how many entity nodes were extracted from the episode. Also adds explicit type annotations to communities and community_edges since they were previously inferred as list[Any].

Testing

The fix is a straightforward logic correction with no behaviour change for callers — the returned communities and community_edges lists now have the correct types and values for all N. No external dependencies are required to verify the logic.

…etzep#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 = <list of N tuples>`, 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.
SFEley added a commit to SFEley/graphiti that referenced this pull request Apr 21, 2026
Cherry-picked from getzep#1421 (fixes getzep#1396).

semaphore_gather returns a list of N tuples, not two parallel lists.
Unpacking as `communities, community_edges = ...` only worked by
accident when exactly 2 entity nodes were extracted. Replaces the
unpack with an explicit accumulation loop that works for any N.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add_episode tuple-unpack fails when extracted node count is not exactly 2

1 participant