Skip to content

[Feature Request]: PostgreSQL-native graph storage using recursive CTEs (no AGE dependency) #3095

Description

@ysys143

Do you need to file a feature request?

  • I have searched the existing feature request and this feature request is not already filed.
  • I believe this is a legitimate feature request, not just a question or bug.

Feature Request Description

Hi — I've been running LightRAG in production on PostgreSQL and kept hitting the same wall: AGE isn't available on RDS, Cloud SQL, Supabase, or Neon. Every deployment needs a custom Docker image, and even then the Cypher wrapper adds latency that compounds under load.

I wrote an alternative graph storage backend that uses plain PostgreSQL with recursive CTEs. No extensions, no custom images.

Implementation

Two tables: lightrag_graph_nodes and lightrag_graph_edges, both with JSONB properties. All 18 BaseGraphStorage abstract methods are implemented. The five batch methods override the defaults to avoid N+1 patterns. get_knowledge_graph runs as a single recursive CTE.

Correctness

I ran equivalence tests against NetworkX (reference), AGE, and Neo4j on two datasets: a 200-node synthetic graph and 8,050-node data extracted from real production documents via LightRAG. All five operations (has_node, node_degree, get_node, get_node_edges, has_edge) return identical results across all four backends on both datasets.

Performance

Each backend ran in an isolated container (2 vCPU, 2 GB RAM). Workload matches LightRAG's actual call pattern during retrieval and indexing: get_node 35%, get_node_edges 25%, node_degree 15%, has_node 10%, upsert_node 15%. 10 concurrent workers, 30 seconds.

Synthetic dataset (8,000 nodes / 39,975 edges):

Backend RPS p50 p95
RCTE (this) 12,776 0.7ms 1.3ms
Neo4j 1,684 4.3ms 13.2ms
AGE 175 4.8ms 213ms

Real production data (8,050 nodes / 25,844 edges):

Backend RPS p50 p95
RCTE (this) 9,169 0.7ms 1.4ms
Neo4j 1,693 4.2ms 13.2ms
AGE 159 4.6ms 239ms

AGE's p95 breaks 200ms at 10 workers. The RCTE backend is 7.6x faster than Neo4j and 58x faster than AGE on this workload.

Deployment

Works on any PostgreSQL 14+, including all major managed services. No Cypher, no graph extensions, no custom image.

Additional Context

Would you be open to a PR adding PgRcteGraphStorage to lightrag/kg/? I'm happy to match existing code conventions and add tests in whatever format fits the project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions