yangdx commited on
Commit
05d00f6
·
1 Parent(s): 2e59a56

Fix mis-using directed edge in PostgreSQL AGE graph storage

Browse files
Files changed (1) hide show
  1. lightrag/kg/postgres_impl.py +4 -4
lightrag/kg/postgres_impl.py CHANGED
@@ -1262,7 +1262,7 @@ class PGGraphStorage(BaseGraphStorage):
1262
  tgt_label = target_node_id.strip('"')
1263
 
1264
  query = """SELECT * FROM cypher('%s', $$
1265
- MATCH (a:base {entity_id: "%s"})-[r]->(b:base {entity_id: "%s"})
1266
  RETURN properties(r) as edge_properties
1267
  LIMIT 1
1268
  $$) AS (edge_properties agtype)""" % (
@@ -1374,7 +1374,7 @@ class PGGraphStorage(BaseGraphStorage):
1374
  MATCH (source:base {entity_id: "%s"})
1375
  WITH source
1376
  MATCH (target:base {entity_id: "%s"})
1377
- MERGE (source)-[r:DIRECTED]->(target)
1378
  SET r += %s
1379
  RETURN r
1380
  $$) AS (r agtype)""" % (
@@ -1447,7 +1447,7 @@ class PGGraphStorage(BaseGraphStorage):
1447
  tgt_label = target.strip('"')
1448
 
1449
  query = """SELECT * FROM cypher('%s', $$
1450
- MATCH (a:base {entity_id: "%s"})-[r]->(b:base {entity_id: "%s"})
1451
  DELETE r
1452
  $$) AS (r agtype)""" % (self.graph_name, src_label, tgt_label)
1453
 
@@ -1723,7 +1723,7 @@ class PGGraphStorage(BaseGraphStorage):
1723
  if node_label == "*":
1724
  query = f"""SELECT * FROM cypher('{self.graph_name}', $$
1725
  MATCH (n:base)
1726
- OPTIONAL MATCH (n)-[r]->(target:base)
1727
  RETURN collect(distinct n) AS n, collect(distinct r) AS r
1728
  LIMIT {max_nodes}
1729
  $$) AS (n agtype, r agtype)"""
 
1262
  tgt_label = target_node_id.strip('"')
1263
 
1264
  query = """SELECT * FROM cypher('%s', $$
1265
+ MATCH (a:base {entity_id: "%s"})-[r]-(b:base {entity_id: "%s"})
1266
  RETURN properties(r) as edge_properties
1267
  LIMIT 1
1268
  $$) AS (edge_properties agtype)""" % (
 
1374
  MATCH (source:base {entity_id: "%s"})
1375
  WITH source
1376
  MATCH (target:base {entity_id: "%s"})
1377
+ MERGE (source)-[r:DIRECTED]-(target)
1378
  SET r += %s
1379
  RETURN r
1380
  $$) AS (r agtype)""" % (
 
1447
  tgt_label = target.strip('"')
1448
 
1449
  query = """SELECT * FROM cypher('%s', $$
1450
+ MATCH (a:base {entity_id: "%s"})-[r]-(b:base {entity_id: "%s"})
1451
  DELETE r
1452
  $$) AS (r agtype)""" % (self.graph_name, src_label, tgt_label)
1453
 
 
1723
  if node_label == "*":
1724
  query = f"""SELECT * FROM cypher('{self.graph_name}', $$
1725
  MATCH (n:base)
1726
+ OPTIONAL MATCH (n)-[r]-(target:base)
1727
  RETURN collect(distinct n) AS n, collect(distinct r) AS r
1728
  LIMIT {max_nodes}
1729
  $$) AS (n agtype, r agtype)"""