Update Memgraph integration (#850)

<!-- .github/pull_request_template.md -->

## Description
Update Memgraph integration with the missing abstract methods
`get_neighbors`, `get_node`, `get_nodes`

## 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.

---------

Co-authored-by: github-actions[bot] <github-actions@users.noreply.github.com>
This commit is contained in:
Matea Pesic 2025-05-23 08:55:55 +02:00 committed by GitHub
parent b1b4ae3d5f
commit 822cc55b02
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 34 additions and 3 deletions

View file

@ -27,9 +27,9 @@ EMBEDDING_API_VERSION=""
EMBEDDING_DIMENSIONS=3072
EMBEDDING_MAX_TOKENS=8191
# "neo4j", "networkx" or "kuzu"
# "neo4j", "networkx", "kuzu" or "memgraph"
GRAPH_DATABASE_PROVIDER="networkx"
# Only needed if using neo4j
# Only needed if using neo4j or memgraph
GRAPH_DATABASE_URL=
GRAPH_DATABASE_USERNAME=
GRAPH_DATABASE_PASSWORD=

12
CONTRIBUTORS.md Normal file
View file

@ -0,0 +1,12 @@
## 💫 Contributors
Thanks to our amazing contributors! 💖
<a href="https://github.com/topoteretes/cognee/graphs/contributors">
<img src="https://contrib.rocks/image?repo=topoteretes/cognee" />
</a>
## 🏆 Top Contributors
| Rank | Contributor | Contributions |
|------|------------|---------------|

View file

@ -358,13 +358,32 @@ class MemgraphAdapter(GraphDBInterface):
return [result["successor"] for result in results]
async def get_neighbours(self, node_id: str) -> List[Dict[str, Any]]:
async def get_neighbors(self, node_id: str) -> List[Dict[str, Any]]:
predecessors, successors = await asyncio.gather(
self.get_predecessors(node_id), self.get_successors(node_id)
)
return predecessors + successors
async def get_node(self, node_id: str) -> Optional[Dict[str, Any]]:
"""Get a single node by ID."""
query = """
MATCH (node {id: $node_id})
RETURN node
"""
results = await self.query(query, {"node_id": node_id})
return results[0]["node"] if results else None
async def get_nodes(self, node_ids: List[str]) -> List[Dict[str, Any]]:
"""Get multiple nodes by their IDs."""
query = """
UNWIND $node_ids AS id
MATCH (node {id: id})
RETURN node
"""
results = await self.query(query, {"node_ids": node_ids})
return [result["node"] for result in results]
async def get_connections(self, node_id: UUID) -> list:
predecessors_query = """
MATCH (node)<-[relation]-(neighbour)