From 7b589d41cfbd3dfccc7cdf3f1183487afd0dc39c Mon Sep 17 00:00:00 2001 From: Ken Wiltshire Date: Fri, 25 Oct 2024 17:45:59 -0400 Subject: [PATCH] adding neo4j --- lightrag/storage.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lightrag/storage.py b/lightrag/storage.py index 704dc4e8..cd313397 100644 --- a/lightrag/storage.py +++ b/lightrag/storage.py @@ -393,9 +393,19 @@ class Neo4JStorage(BaseGraphStorage): else: return None -# edge_degree - # from neo4j import GraphDatabase - + # edge_degree + # from neo4j import GraphDatabase + async def edge_degree(self, src_id: str, tgt_id: str) -> int: + entity_name__label_source = src_id + entity_name_label_target = tgt_id + with graph_db.session() as session: + result = session.run( + """MATCH (n1:{node_label1})-[r]-(n2:{node_label2}) + RETURN count(r) AS degree""" + .format(node_label1=node_label1, node_label2=node_label2) + ) + record = result.single() + return record["degree"] # driver = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "password")) #