From 2f0aa7ed121564e98beab5958707b2f188660024 Mon Sep 17 00:00:00 2001 From: yangdx Date: Sat, 2 Aug 2025 12:54:22 +0800 Subject: [PATCH] Optimize graph query by simplifying MATCH pattern - Simplify MATCH clause to ()-[r]-() - Remove node type constraints - Improve query performance --- lightrag/kg/postgres_impl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lightrag/kg/postgres_impl.py b/lightrag/kg/postgres_impl.py index 7fb1935c..7edfdad1 100644 --- a/lightrag/kg/postgres_impl.py +++ b/lightrag/kg/postgres_impl.py @@ -3289,7 +3289,7 @@ class PGGraphStorage(BaseGraphStorage): query = f""" SELECT * FROM cypher('{self.graph_name}', $$ UNWIND {chunk_ids_str} AS chunk_id - MATCH (a:base)-[r]-(b:base) + MATCH ()-[r]-() WHERE r.source_id IS NOT NULL AND chunk_id IN split(r.source_id, '{GRAPH_FIELD_SEP}') RETURN DISTINCT r, startNode(r) AS source, endNode(r) AS target $$) AS (edge agtype, source agtype, target agtype);