From 5ede210f12fece0f9b7c02e0a8c3366054ccac70 Mon Sep 17 00:00:00 2001 From: matea16 Date: Tue, 17 Jun 2025 15:29:33 +0200 Subject: [PATCH] update memgraph integration --- .../databases/graph/memgraph/memgraph_adapter.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cognee/infrastructure/databases/graph/memgraph/memgraph_adapter.py b/cognee/infrastructure/databases/graph/memgraph/memgraph_adapter.py index 75c0722a8..9a0389e91 100644 --- a/cognee/infrastructure/databases/graph/memgraph/memgraph_adapter.py +++ b/cognee/infrastructure/databases/graph/memgraph/memgraph_adapter.py @@ -376,12 +376,22 @@ class MemgraphAdapter(GraphDBInterface): The result of the edge addition operation, including relationship details. """ + + exists = await asyncio.gather( + self.has_node(str(from_node)), + self.has_node(str(to_node)) + ) + + if not all(exists): + return None + serialized_properties = self.serialize_properties(edge_properties or {}) query = dedent( f"""\ MATCH (from_node {{id: $from_node}}), (to_node {{id: $to_node}}) + WHERE from_node IS NOT NULL AND to_node IS NOT NULL MERGE (from_node)-[r:{relationship_name}]->(to_node) ON CREATE SET r += $properties, r.updated_at = timestamp() ON MATCH SET r += $properties, r.updated_at = timestamp()