Skip to content

Commit

Permalink
fix: Duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-paliychuk committed Aug 22, 2024
1 parent b47e68e commit 6a97e9f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions core/graphiti.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,14 @@ async def add_episode(
edge_touched_node_uuids.append(edge.source_node_uuid)
edge_touched_node_uuids.append(edge.target_node_uuid)

entity_edges.extend(invalidated_edges)
edges_to_save = invalidated_edges

# There may be an overlap between deduped and invalidated edges, so we want to make sure to save the invalidated one
for deduped_edge in deduped_edges:
if deduped_edge.uuid not in [edge.uuid for edge in invalidated_edges]:
edges_to_save.append(deduped_edge)

entity_edges.extend(edges_to_save)

edge_touched_node_uuids = list(set(edge_touched_node_uuids))
involved_nodes = [node for node in nodes if node.uuid in edge_touched_node_uuids]
Expand All @@ -190,7 +197,6 @@ async def add_episode(
logger.info(f'Invalidated edges: {[(e.name, e.uuid) for e in invalidated_edges]}')

logger.info(f'Deduped edges: {[(e.name, e.uuid) for e in deduped_edges]}')
entity_edges.extend(deduped_edges)

episodic_edges.extend(
build_episodic_edges(
Expand All @@ -203,12 +209,6 @@ async def add_episode(
# Important to append the episode to the nodes at the end so that self referencing episodic edges are not built
logger.info(f'Built episodic edges: {episodic_edges}')

# invalidated_edges = await self.invalidate_edges(
# episode, new_nodes, new_edges, relevant_schema, previous_episodes
# )

# edges.extend(invalidated_edges)

# Future optimization would be using batch operations to save nodes and edges
await episode.save(self.driver)
await asyncio.gather(*[node.save(self.driver) for node in nodes])
Expand Down

0 comments on commit 6a97e9f

Please sign in to comment.