From ffbe2a0c5d0ea05b8d9882b51f0f5ba735552fa3 Mon Sep 17 00:00:00 2001 From: yangdx Date: Thu, 24 Apr 2025 08:40:06 +0800 Subject: [PATCH] Fix get_knowledge_graph query slow problem for PostgreSQL AGE --- lightrag/kg/postgres_impl.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lightrag/kg/postgres_impl.py b/lightrag/kg/postgres_impl.py index 9464ea21..54722eb0 100644 --- a/lightrag/kg/postgres_impl.py +++ b/lightrag/kg/postgres_impl.py @@ -1849,9 +1849,8 @@ class PGGraphStorage(BaseGraphStorage): else: strip_label = self._normalize_node_id(node_label) count_query = f"""SELECT * FROM cypher('{self.graph_name}', $$ - MATCH (n:base {{entity_id: "{strip_label}"}}) - OPTIONAL MATCH p = (n)-[*..{max_depth}]-() - RETURN count(nodes(p)) AS total_nodes + MATCH (n:base {{entity_id: "{strip_label}"}})-[r]-() + RETURN count(r) AS total_nodes $$) AS (total_nodes bigint)""" count_result = await self._query(count_query)