laya-jev-GraphRAG is a graph-database-agnostic Agentic GraphRAG framework β€” a production-ready intelligence layer you drop on top of your existing graph database to make it fully agentic. It doesn't replace your graph DB; it gives it a brain.

Instead of hard-wiring GraphRAG logic to a single database, this framework completely decouples the AI decision layer from the storage layer. The same complete 4-phase pipeline (Ingestion β†’ Pre-Retrieval β†’ Traversal β†’ Post-Retrieval) and evaluation runs identically across Neo4j, Memgraph, Apache AGE, and KΓΉzu β€” switched with one environment variable.

At its core, this framework continuously evaluates every single edge and relationship across the entire lifecycle of the data. From the moment data enters the graph (Ingestion/Pre-Retrieval), through real-time multi-hop navigation (Traversal), to final synthesis (Post-Retrieval), the engine actively scores, builds, and prunes connections.

Every decision inside that pipeline β€” from semantic chunking and intent routing to custom A* traversal and hallucination gating β€” is handled by swappable System One models (local Laya / cloud Jev) using three deterministic mathematical primitives instead of slow generative LLM calls:

Primitive What It Does Where It's Used
Score Evaluates edges & relationships [0, 1] Edge verification during ingestion, A* traversal heuristic, context reranking
Noul Binary judgement P(yes) [0, 1] Semantic chunking, entity disambiguation, early termination, hallucination gate, citation verification
Choice Categorical selection Intent routing, ontology alignment, conflict resolution

Switch the AI decision model AND the graph database β€” both independently, with a single environment variable each.


πŸ›‘ Why Traditional GraphRAG Fails

Traditional GraphRAG has three fundamental problems:

  1. LLM at every hop β€” Evaluating 5 edges at depth 4 = 20 serial LLM calls = 30–90 seconds of latency and frequent context-window overflow.
  2. No edge verification β€” Hallucinated relationships extracted at ingestion time are blindly trusted forever. Bad data compounds through every hop.
  3. Database lock-in β€” Traditional implementations hard-wire graph logic to a single database. Swapping Neo4j for Memgraph or AGE requires rewriting the entire pipeline.

⚑ The Solution: End-to-End System One Evaluation

This framework solves all three β€” replacing LLM routing with System One models, actively verifying every edge during ingestion, and abstracting the database entirely behind a unified interface:

Phase What Laya/Jev Evaluates
Ingestion Scores edge validity to purge hallucinations, disambiguates entities to prevent graph bloat, and aligns relationships to enforce strict schema
Pre-Retrieval Routes query intent to skip unnecessary compute, and validates seed nodes to guarantee the search starts at the optimal mathematical anchor
Traversal Laya/Jev dynamically score edges during custom A* search for intelligent semantic routing, while gating early termination to prevent context bloat and save compute
Post-Retrieval Reranks context to maximize token density, resolves contradictory sources for accuracy, gates hallucinations, and strictly verifies citations before LLM synthesis

The generative LLM (Llama-3.1-8B) only runs once, at the very end, to synthesise the already-verified subgraph into a final answer.


🧠 Architecture Philosophy: Three Separated Layers

Most GraphRAG systems tightly couple storage, reasoning, and generation into one hard-to-swap stack. This framework separates them into three fully independent layers:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  LAYER 1 β€” STORAGE  (Your Graph DB)                   β”‚
β”‚  Neo4j Β· Memgraph Β· Apache AGE Β· KΓΉzu                 β”‚
β”‚  Handles: graph structure, PageRank, Cypher queries    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  LAYER 2 β€” DECISION  (Laya / Jev)   ← The CPU         β”‚
β”‚  Handles: every routing, scoring, and gating decision  β”‚
β”‚  Score Β· Noul Β· Choice across all 19 pipeline steps    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€οΏ½οΏ½β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  LAYER 3 β€” GENERATION  (Llama-3.1-8B 4-bit)           β”‚
β”‚  Handles: entity extraction (ingestion) +              β”‚
β”‚           final answer synthesis (post-retrieval)      β”‚
β”‚  Runs exactly TWICE per document lifecycle             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Laya/Jev act as the CPU of your knowledge graph β€” the high-speed decision engine routing data between storage and generation without ever generating a single token themselves.

πŸ”„ The 2-Axis Swappability

This is the key architectural decision: both axes are independent.

Axis Options How to Switch
AI Decision Model Laya (local GPU) ↔ Jev (cloud API) ↔ Ablation (both) DECISION_MODEL_BACKEND=laya|jev|ablation
Graph Database Neo4j ↔ Memgraph ↔ Apache AGE ↔ KΓΉzu GRAPH_DB_BACKEND=neo4j|memgraph|age|kuzu

You can run Jev + Neo4j in production, Laya + KΓΉzu for local development with zero Docker, or Ablation + Memgraph to generate training data β€” all from the same codebase with zero code changes.

πŸ” The RLCD Flywheel: From Cloud to Fully Local

The framework is designed around a self-improving loop:

1. START  β†’  Deploy with Jev (cloud API, zero-shot accurate, instant setup)
2. COLLECT β†’  Ablation mode logs every Laya vs. Jev decision side-by-side to JSONL
3. TRAIN   β†’  Use those JSONL logs as RLCD synthetic training data to fine-tune Laya
4. SWITCH  β†’  Flip DECISION_MODEL_BACKEND=laya for 100% local, zero API cost

The end state: a fully local, frontier-quality GraphRAG engine on your own hardware with no API dependency and no data leaving your network.


πŸ”Œ Backend Configuration

# AI Decision Model (.env)
DECISION_MODEL_BACKEND=laya      # Local CUDA, free, ~33ms/call, ~1.2 GB VRAM
DECISION_MODEL_BACKEND=jev       # TypeSafe cloud API, zero-shot ready, ~50ms/call
DECISION_MODEL_BACKEND=ablation  # Run BOTH, log side-by-side for RLCD fine-tuning

# Graph Database (.env)
GRAPH_DB_BACKEND=neo4j       # Production: index-free adjacency, native GDS
GRAPH_DB_BACKEND=memgraph    # In-memory Bolt: identical Cypher, low-latency analytics
GRAPH_DB_BACKEND=age         # PostgreSQL + Apache AGE: unified SQL/graph stack
GRAPH_DB_BACKEND=kuzu        # Embedded local: no Docker, zero setup for development
Feature Laya (Local) Jev (Cloud)
Model convaiinnovations/laya-typed-decisions 421M jev-1.13 (TypeSafe)
Latency ~33 ms (RTX 5060 FP16) ~50 ms (API round-trip)
Cost Free ~$0.042 / M tokens
Privacy 100% local API
Batch GPU-batched True parallel (1 API call)

All four graph DB backends implement the same BaseGraphClient interface. Zero code changes needed when switching databases.


πŸ—ΊοΈ The 19-Function Pipeline

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  PHASE 1 β€” Ingestion (Offline, runs once per document)  β”‚
β”‚                                                         β”‚
β”‚  1. Semantic Chunking      β†’ Noul   (boundary detect)   β”‚
β”‚  2. Entity Extraction      β†’ LLM    (Llama-3.1-8B)      β”‚
β”‚  3. Entity Disambiguation  β†’ Noul   (merge duplicates)   β”‚
β”‚  4. Edge Verification      β†’ Score  (prune hallucinated) β”‚
β”‚  5. Ontology Alignment     β†’ Choice (snap to schema)     β”‚
β”‚  6. Community Detection    β†’ Leiden / NetworkX           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  PHASE 2 β€” Pre-Traversal (Per query)                    β”‚
β”‚                                                         β”‚
β”‚  7. Intent Routing         β†’ Choice (local/multi/global) β”‚
β”‚  8. Dense Seed Retrieval   β†’ Embedding cosine           β”‚
β”‚  9. Seed Validation        β†’ Score  (filter bad seeds)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  PHASE 3 β€” A* Traversal (Per query)                     β”‚
β”‚                                                         β”‚
β”‚  10. Neighborhood Fetch    β†’ Bolt / Cypher              β”‚
β”‚  11. Edge Scoring          β†’ Score  (semantic heuristic) β”‚
β”‚  12. Structural Anchoring  β†’ PageRank (centrality)       β”‚
β”‚  13. Path Pruning          β†’ Beam cutoff                β”‚
β”‚  14. Early Termination     β†’ Noul   (context sufficient?)β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  PHASE 4 β€” Post-Traversal (Per query)                   β”‚
β”‚                                                         β”‚
β”‚  15. Context Reranking     β†’ Score  (drop low-relevance) β”‚
β”‚  16. Conflict Resolution   β†’ Choice (pick credible src)  β”‚
β”‚  17. Hallucination Gate    β†’ Noul   (abstain if unsafe)  β”‚
β”‚  18. Answer Synthesis      β†’ LLM    (Llama-3.1-8B 4-bit) β”‚
β”‚  19. Citation Verification β†’ Noul   (flag ungrounded)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“š Want to see the full breakdown of all 19 functions? Check out the Architecture Deep Dive (ARCHITECTURE.md) for a complete breakdown of every primitive and routing decision across all 4 phases.

πŸ’‘ Is this a Static Knowledge Store or an Agentic Memory? (And wild use cases) Check out Use Cases (USE_CASES.md) to see how the decoupled intelligence layer allows this to act as both a high-fidelity query engine (fraud, bio-med) and a self-organizing memory store for autonomous agents etc.


πŸš€ Getting Started

Installation

git clone https://github.com/bodepudimuneendra-netizen/laya-jev-GraphRAG.git
cd laya-jev-GraphRAG/graphrag_neo4j_laya

# Install PyTorch with CUDA 12.4 first (for your GPU)
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu124

# Install all remaining dependencies
pip install -r requirements.txt

Configure your backend

cp .env.example .env
# Then edit .env to set:
#   DECISION_MODEL_BACKEND=laya
#   GRAPH_DB_BACKEND=kuzu   ← Start here: no Docker required

Run a query

from graphrag.pipeline import GraphRAGPipeline

pipeline = GraphRAGPipeline()
answer = pipeline.query("What caused the 2008 financial crisis?")
print(answer)

Or from the CLI:

python -m graphrag.pipeline --query "What caused the 2008 financial crisis?" --max-depth 4

Run the ablation harness

from graphrag.models.ablation import AblationHarness

harness = AblationHarness()
result = harness.compare(
    context="Isaac Newton published Principia Mathematica in 1687.",
    instruction="Score the historical significance of this event.",
)
print(f"Laya: {result['laya']['score']:.3f} @ {result['laya']['latency_ms']:.0f}ms")
print(f"Jev:  {result['jev']['score']:.3f}  @ {result['jev']['latency_ms']:.0f}ms")
print(f"Ξ”:    {result['delta']:.4f}")

πŸ“ Project Structure

graphrag_neo4j_laya/
β”œβ”€β”€ graphrag/
β”‚   β”œβ”€β”€ graph/                    # DB abstraction layer
β”‚   β”‚   β”œβ”€β”€ base.py               # BaseGraphClient ABC
β”‚   β”‚   β”œβ”€β”€ factory.py            # GRAPH_DB_BACKEND selector
β”‚   β”‚   β”œβ”€β”€ neo4j_client.py       # Neo4j (Bolt + GDS)
β”‚   β”‚   β”œβ”€β”€ memgraph_client.py    # Memgraph (Bolt)
β”‚   β”‚   β”œβ”€β”€ age_client.py         # Apache AGE (PostgreSQL)
β”‚   β”‚   └── kuzu_client.py        # KΓΉzu (embedded)
β”‚   β”œβ”€β”€ models/                   # AI decision layer
β”‚   β”‚   β”œβ”€β”€ base_decision.py      # BaseDecisionModel ABC (Score/Noul/Choice)
β”‚   β”‚   β”œβ”€β”€ laya.py               # Local CUDA model (421M params)
β”‚   β”‚   β”œβ”€β”€ jev.py                # TypeSafe Jev API client
β”‚   β”‚   β”œβ”€β”€ ablation.py           # Side-by-side comparison harness
β”‚   β”‚   └── decision_factory.py   # DECISION_MODEL_BACKEND selector
β”‚   β”œβ”€β”€ ingestion/                # Phase 1: offline pipeline
β”‚   β”‚   β”œβ”€β”€ chunker.py            # Noul boundary chunking
β”‚   β”‚   β”œβ”€β”€ entity_extractor.py   # LLM NER + Noul disambiguation
β”‚   β”‚   β”œβ”€β”€ edge_verifier.py      # Score-based edge pruning
β”‚   β”‚   β”œβ”€β”€ ontology_aligner.py   # Choice-based schema alignment
β”‚   β”‚   └── community.py          # Leiden community detection
β”‚   β”œβ”€β”€ retrieval/                # Phases 2-4: query pipeline
β”‚   β”‚   β”œβ”€β”€ router.py             # Choice: intent routing
β”‚   β”‚   β”œβ”€β”€ seed_selector.py      # Score: seed validation
β”‚   β”‚   β”œβ”€β”€ post_traversal.py     # Score/Choice/Noul: post-processing
β”‚   β”‚   └── traversal/
β”‚   β”‚       β”œβ”€β”€ astar.py          # A* semantic traversal + early exit
β”‚   β”‚       └── bfs.py            # Score-gated BFS (local intent)
β”‚   β”œβ”€β”€ benchmarks/               # Performance analysis
β”‚   β”‚   β”œβ”€β”€ hop_latency.py        # Per-hop DB latency across all backends
β”‚   β”‚   β”œβ”€β”€ laya_vs_jev.py        # Side-by-side model comparison
β”‚   β”‚   β”œβ”€β”€ greedy_vs_astar.py    # Search strategy comparison
β”‚   β”‚   └── vram_monitor.py       # GPU memory tracking
β”‚   └── pipeline.py               # Full end-to-end orchestrator
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ settings.py               # Pydantic settings (all thresholds)
β”‚   └── .env.example              # Template with all toggles
└── requirements.txt

πŸ”¬ The Ablation Mode: RLCD Data Factory

Setting DECISION_MODEL_BACKEND=ablation silently runs both Laya and Jev in parallel for every primitive call and logs the results to a JSONL file:

{"primitive": "score", "context": "...", "instruction": "...",
 "laya": {"score": 0.83, "latency_ms": 34.1},
 "jev":  {"score": 0.79, "latency_ms": 48.3},
 "delta": 0.04}

This JSONL log is ready-to-use RLCD training data to fine-tune Laya towards Jev-level zero-shot accuracy β€” the path to a fully local, frontier-quality GraphRAG engine.


πŸ“Š Performance

Backend Edge Score Latency Traversal (4-hop) VRAM
Laya (RTX 5060 FP16) ~33 ms ~150 ms ~1.2 GB
Jev (cloud API) ~50 ms ~220 ms 0
LLM-per-hop (baseline) ~2,000 ms ~15,000 ms ~6 GB

🀝 Contributing

Contributions welcome:

  • Additional graph DB connectors (Nebula, TigerGraph, FalkorDB, etc.)
  • Laya fine-tuning scripts from ablation JSONL logs
  • Jev async/streaming support
  • New ingestion sources (PDF, HTML, Markdown)

πŸ“„ License

Licensed under the Apache 2.0 License.

Built on: