Skip to content

Commit

Permalink
fix: correctly add nodes to chunks [COG-1370] (#568)
Browse files Browse the repository at this point in the history
<!-- .github/pull_request_template.md -->

## Description
- Fix expand_with_nodes_and_edges to correctly add nodes to chunks
## DCO Affirmation
I affirm that all code in every commit of this pull request conforms to
the terms of the Topoteretes Developer Certificate of Origin


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Refactor**
- Enhanced the internal processing for data associations to ensure more
reliable and consistent handling of connections.
- Streamlined the logic to better manage edge cases, improving overall
stability and error handling.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
lxobr authored Feb 20, 2025
1 parent f2e0f47 commit e25c7c9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cognee/modules/graph/utils/expand_with_nodes_and_edges.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def expand_with_nodes_and_edges(
existing_edges_map = {}

added_nodes_map = {}

relationships = []

for index, data_chunk in enumerate(data_chunks):
Expand Down Expand Up @@ -53,12 +54,14 @@ def expand_with_nodes_and_edges(
description=node.description,
)

if data_chunk.contains is None:
data_chunk.contains = []
added_nodes_map[f"{str(node_id)}_entity"] = entity_node
else:
entity_node = added_nodes_map[f"{str(node_id)}_entity"]

data_chunk.contains.append(entity_node)
if data_chunk.contains is None:
data_chunk.contains = []

added_nodes_map[f"{str(node_id)}_entity"] = entity_node
data_chunk.contains.append(entity_node)

# Add relationship that came from graphs.
for edge in graph.edges:
Expand Down

0 comments on commit e25c7c9

Please sign in to comment.