Skip to content

About

Agentic RAG engine leveraging AST Code Graphs, Vector Search, and Google Antigravity SDK

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

16 Commits

Folders and files

Repository files navigation

πŸš€ CodeGraph-RAG

Autonomous Polyglot Codebase Intelligence & Blast-Radius Engine

A Production-Grade Full-Stack Monorepo Pairing Deterministic AST Knowledge Graphs with High-Dimensional Vector Search & Model Context Protocol (MCP).


Python FastAPI React Tree--Sitter Neo4j Qdrant Google Gemini Model Context Protocol Docker License: MIT PRs Welcome


Key Features β€’ The Core Problem β€’ System Architecture β€’ Visual Preview β€’ Tech Stack β€’ MCP Tools β€’ Monorepo Structure β€’ 1-Click Quickstart β€’ Benchmarks β€’ Author & License



🌟 Key Features

  • 🌐 Polyglot Scope-Resolved AST Traversal: Uses Tree-sitter parsers across Python, Java, TypeScript, C++, and Go to build deterministic abstract syntax trees, identifying precise class scopes, function signatures, docstrings, and cross-file import statements.
  • πŸ•ΈοΈ Deterministic Property Knowledge Graphs: Ingests files, classes, methods, and call sites into Neo4j with bi-directional relationships ([:CONTAINS], [:CALLS], [:EXTENDS], [:IMPORTS]), unlocking instant $N$-hop multi-level blast-radius analysis.
  • ⚑ Dual-Stream Context Retrieval: Merges high-dimensional dense code vector search (Qdrant + local 384D BGE / 3072D Gemini embeddings) with structural graph traversal context to completely eliminate code-hallucination.
  • πŸ€– Autonomous Refactor & Patch Synthesizer: Produces unified Git patches (--- a/ / +++ b/) tailored to codebase architecture, simulating impacts before changes are committed.
  • πŸ”Œ Native Model Context Protocol (MCP): Exposes a standardized stdio JSON-RPC 2.0 interface for instantaneous integration with VS Code, Cursor IDE, and Claude Desktop.
  • πŸ›‘οΈ Multi-Tier Resilient Model Failover: Built-in automatic retry and fallback across Gemini models (gemini-2.5-flash, gemini-3.8-flash, gemini-1.5-pro) to gracefully mitigate quota (429) and server (503) rate limits.
  • πŸ“Š Blast-Radius Command Center: Visualizes impact assessment, affected callers, and dependency chains in an interactive React 18 dashboard.

🎯 The Core Problem Solved

Standard Code RAG systems rely strictly on naive chunked vector embeddings. When applied to production-scale codebases, this introduces severe context fragmentation:

Warning

πŸ›‘ The Vector Blindspot

Vector search excels at finding textually similar fragments, but is fundamentally blind to execution flows:

  • It cannot answer: "If I modify function generateToken(), which 4 upstream controllers and service layers will break?"
  • It misses indirect callers, inheritance overrides, and cross-file interface implementations.
  • It splits function signatures away from their enclosing class scopes and global decorators.

Tip

πŸ’‘ The Graph-Augmented Solution

CodeGraph-RAG pairs semantic vector retrieval with a deterministic Neo4j Property Knowledge Graph:

  • Deterministic Scope Attribution: Every code chunk is tagged with its fully-qualified hierarchical identifier (package.Class.method).
  • Multi-Hop Dependency Traversal: Cypher queries trace call graphs upstream and downstream to arbitrary depths ($N$-hops).
  • Contextual Fusion: LLM prompts receive both relevant semantic snippets and exact architectural dependency paths.

βš–οΈ Comparison Matrix

Capability Naive Vector-Only RAG Graph-Only Retrieval πŸš€ CodeGraph-RAG (Dual Stream)
Semantic Keyword & Intent Search βœ… High ❌ None βœ… Optimal (Qdrant + BGE)
Blast Radius & Impact Analysis ❌ Fails (Hallucinates) βœ… Strong βœ… 100% Deterministic (Neo4j)
Caller / Callee Hierarchy Tracing ❌ Incomplete βœ… Exact βœ… Exhaustive Multi-Hop
Enclosing Scope Awareness ❌ Chunks Cut Arbitrarily βœ… Structural βœ… Exact Class & Method Mapping
Unified Patch / Diff Generation ⚠️ Fragmented ❌ Code Unaware βœ… Architectural-Aligned Diffs
IDE Agent Integration (MCP) ⚠️ Custom / Partial ⚠️ Custom / Partial βœ… Standard Stdio JSON-RPC 2.0

πŸ—οΈ System Architecture

End-to-End Architectural Pipeline

flowchart TD
    subgraph Client ["Client & Interface Layer"]
        UI["React 18 Dashboard\n(Vite + Tailwind CSS :5173)"]
        IDE["Cursor / VS Code / Claude Desktop\n(Model Context Protocol)"]
    end

    subgraph Backend ["FastAPI Backend & MCP Engine (:8000)"]
        API["FastAPI REST Router\n(/auth, /workspace, /rag)"]
        MCP["FastMCP Stdio Server\n(JSON-RPC 2.0 Protocol)"]
    end

    subgraph CoreEngine ["Ingestion & AST Engine"]
        Parser["Polyglot Tree-sitter Parser\n(Python, TS, Go, Java, C++)"]
        Scope["Hierarchical Scope Resolver\n(Classes, Methods, Imports)"]
    end

    subgraph DualRetrieval ["Dual-Stream Knowledge Engine"]
        Qdrant[("Qdrant Vector Store\n(384D BGE Dense Embeddings)")]
        Neo4j[("Neo4j Property Graph\n(Nodes: File/Class/Method | Edges: CALLS/IMPORTS)")]
    end

    subgraph Reasoning ["LLM Synthesis & Failover Mesh"]
        Fusion["Hybrid Context Fusion & Re-ranker"]
        LLM["Google Gemini Reasoning Engine\n(2.5-Flash βž” 3.8-Flash βž” 1.5-Pro)"]
        Synthesizer["Diff Synthesizer & Blast-Radius Formatter"]
    end

    UI -->|"HTTP / REST API (JWT)"| API
    IDE -->|"Stdio JSON-RPC"| MCP
    API --> CoreEngine
    MCP --> CoreEngine
    CoreEngine --> Parser --> Scope
    Scope -->|"Vectorize Chunks"| Qdrant
    Scope -->|"Populate Topology"| Neo4j
    API --> DualRetrieval
    MCP --> DualRetrieval
    Qdrant -->|"Top-K Semantic Matches"| Fusion
    Neo4j -->|"N-Hop Call Chains & Blast Radius"| Fusion
    Fusion --> LLM --> Synthesizer
    Synthesizer -->|"Unified Diff & Impact Map"| API
    Synthesizer -->|"Structured Tool Output"| MCP

    style Client fill:#eff6ff,stroke:#3b82f6,stroke-width:2px
    style Backend fill:#f8fafc,stroke:#64748b,stroke-width:2px
    style DualRetrieval fill:#f0fdf4,stroke:#22c55e,stroke-width:2px
    style Reasoning fill:#fdf4ff,stroke:#d946ef,stroke-width:2px
Loading
πŸ“ Text-Based ASCII Architecture View (Click to expand)
                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                      β”‚ Developer / Web / Cursor / IDE  β”‚
                      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                       β”‚
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β–Ό                                                     β–Ό
  [ React 18 SPA Dashboard ]                           [ FastMCP Stdio Server ]
   (Port 5173 - Tailwind)                               (JSON-RPC 2.0 Engine)
            β”‚                                                     β”‚
            β”‚ REST API (Bearer JWT)                               β”‚ Service Calls
            β–Ό                                                     β”‚
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚
  β”‚               FastAPI Backend Server                β”‚         β”‚
  β”‚                     (Port 8000)                     β”‚         β”‚
  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€         β”‚
  β”‚ β€’ /api/auth/*       : Session & JWT Provider        β”‚         β”‚
  β”‚ β€’ /api/workspace/*  : Git Ingestion & AST Pipeline  β”‚β—„β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  β”‚ β€’ /api/rag/impact   : N-Hop Blast Radius Traversal  β”‚
  β”‚ β€’ /api/rag/query    : Dual-Stream Context Fusion    β”‚
  β”‚ β€’ /api/rag/refactor : Automated Patch Synthesizer   β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                             β”‚
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β–Ό                                 β–Ό
 [ Polyglot AST Parser ]          [ Dual-Stream Knowledge Layer ]
  Tree-sitter Scope Engine            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  Python, TS, Go, Java, C++           β–Ό                               β–Ό
                             [ Qdrant Vector DB ]         [ Neo4j Graph DB ]
                             (384D BGE Vectors)           (Property Graph)
                             Semantic Search              Multi-Hop Blast Radius
                                      β”‚                               β”‚
                                      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                      β–Ό
                                           [ Gemini Reasoning Mesh ]
                                           (Automatic Model Failover)

πŸ–ΌοΈ Visual Dashboard & Blast-Radius Preview

Interactive Dependency Visualizer Deterministic Blast-Radius Analysis
Graph Preview Impact Preview
Real-time force-directed topology of files, classes, and method call sites Multi-hop upstream caller tracing and broken-file risk isolation

πŸ› οΈ Complete Tech Stack Matrix

Layer Technology Function / Purpose
Frontend UI React Vite TailwindCSS Interactive graph canvas, real-time blast-radius metrics, and refactor diff sandbox
Backend API FastAPI Python Multi-tenant REST backend, background task queues, and CORS-hardened endpoints
AST Parsing Tree-sitter Polyglot static code analysis, structural entity extraction, and scope resolution
Graph DB Neo4j Hierarchical containment, call hierarchy tracing, and recursive blast radius calculation
Vector DB Qdrant Ultra-fast high-dimensional code snippet indexing and dense similarity retrieval
Embedding Engine sentence-transformers (BAAI/bge-small-en-v1.5) & gemini-embedding-001 CPU-optimized local 384D / cloud 3072D dense vector generation
IDE Protocol MCP Standardized stdio JSON-RPC 2.0 RPC wrapper exposing tools to VS Code & Cursor
Relational DB SQLAlchemy PostgreSQL Relational persistence for user accounts, workspace metadata, and audit logs
LLM Reasoning Google Gemini High-speed synthesized architectural answers, code reasoning, and diff generation
Containerization Docker Multi-service local and production orchestration (backend, frontend, neo4j)

πŸ”Œ Exposed MCP Tools

When registered with an MCP-compliant client (VS Code, Cursor IDE, Claude Desktop), backend/mcp_server.py dynamically exposes 4 production tools over stdio JSON-RPC 2.0:

Tool Name Input Parameters Purpose & Output
search_codebase query: str, top_k: int = 5 Performs dual-stream hybrid semantic vector search and LLM context synthesis across codebase chunks.
analyze_symbol_impact target_symbol: str Traverses multi-hop Neo4j Cypher call paths to return the exact blast radius, all upstream callers, and potentially broken files.
get_file_graph filepath: str Produces an exhaustive structural breakdown: classes, functions, docstrings, imports, and outgoing method invocations.
ingest_repository repo_url: str Clones a remote Git repository or unzips a local project, running end-to-end AST extraction, vector embedding, and graph ingestion.
πŸ” Click to view Sample MCP Tool Output (analyze_symbol_impact)
{
  "target_symbol": "generateToken",
  "total_affected_callers": 4,
  "affected_files": [
    "backend/app/services/auth_service.py",
    "backend/app/api/auth.py",
    "backend/app/api/admin.py",
    "backend/app/services/oauth_provider.py"
  ],
  "call_hierarchy": [
    {
      "caller": "AuthService.login_user",
      "path": "backend/app/services/auth_service.py",
      "depth": 1
    },
    {
      "caller": "OAuthProvider.issue_bearer_token",
      "path": "backend/app/services/oauth_provider.py",
      "depth": 1
    },
    {
      "caller": "api_login_endpoint",
      "path": "backend/app/api/auth.py",
      "depth": 2
    },
    {
      "caller": "admin_impersonate_user",
      "path": "backend/app/api/admin.py",
      "depth": 2
    }
  ]
}

πŸ“ Monorepo Directory Structure

CodeGraph-RAG/
β”œβ”€β”€ backend/                         # FastAPI REST Engine & Ingestion Services
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ main.py                  # FastAPI application entry & CORS middleware
β”‚   β”‚   β”œβ”€β”€ config.py                # Pydantic Settings & environment loader
β”‚   β”‚   β”œβ”€β”€ database.py              # SQLAlchemy engine & session provider
β”‚   β”‚   β”œβ”€β”€ models/                  # SQLAlchemy ORM schemas
β”‚   β”‚   β”‚   β”œβ”€β”€ user.py              # User entity model
β”‚   β”‚   β”‚   └── workspace.py         # Workspace repository model
β”‚   β”‚   β”œβ”€β”€ services/                # Core domain & ingestion services
β”‚   β”‚   β”‚   β”œβ”€β”€ ast_parser.py        # Polyglot Tree-sitter scope extractor
β”‚   β”‚   β”‚   β”œβ”€β”€ vector_store.py      # Qdrant vector database client
β”‚   β”‚   β”‚   β”œβ”€β”€ graph_store.py       # Neo4j Cypher call graph engine
β”‚   β”‚   β”‚   β”œβ”€β”€ repo_ingestor.py     # Git clone & ZIP extraction pipeline
β”‚   β”‚   β”‚   └── agent_workflow.py    # Dual-stream RAG reasoning & retry mesh
β”‚   β”‚   └── api/                     # REST API route handlers
β”‚   β”‚       β”œβ”€β”€ auth.py              # /api/auth (register, login, demo)
β”‚   β”‚       β”œβ”€β”€ workspace.py         # /api/workspace (list, ingest)
β”‚   β”‚       └── rag.py               # /api/rag (impact, query, refactor)
β”‚   β”œβ”€β”€ mcp_server.py                # Stdio JSON-RPC 2.0 FastMCP Server for IDEs
β”‚   β”œβ”€β”€ requirements.txt             # Production Python dependencies
β”‚   └── Dockerfile                   # Backend container definition
β”‚
β”œβ”€β”€ frontend/                        # React 18 SPA (Vite + Tailwind CSS)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   └── api.js               # Centralized HTTP client with JWT handling
β”‚   β”‚   β”œβ”€β”€ App.jsx                  # Main dashboard (Graph visualizer, RAG & Blast Radius)
β”‚   β”‚   β”œβ”€β”€ main.jsx                 # React root bootstrap
β”‚   β”‚   └── index.css                # Tailwind directives & global styling
β”‚   β”œβ”€β”€ package.json                 # Web client dependencies & build scripts
β”‚   β”œβ”€β”€ vite.config.js               # Vite frontend configuration
β”‚   └── Dockerfile                   # Frontend container definition
β”‚
β”œβ”€β”€ evaluation/                      # Automated Evaluation Framework
β”‚   └── evaluator.py                 # LLM-as-a-Judge benchmark suite
β”œβ”€β”€ docs/
β”‚   └── assets/                      # Architectural & UI screenshots
β”‚       β”œβ”€β”€ graph_preview.png        # Interactive dependency graph preview
β”‚       └── impact_preview.png       # Blast-radius impact analysis preview
β”œβ”€β”€ docker-compose.yml               # 1-Click Multi-container orchestration
β”œβ”€β”€ mcp_server.py                    # Stdio FastMCP Server entry point
β”œβ”€β”€ main.py                          # Standalone CLI interactive interface
β”œβ”€β”€ requirements.txt                 # Root Python dependencies
β”œβ”€β”€ .env.example                     # Environment template
└── README.md                        # Documentation

πŸš€ 1-Click Quickstart with Docker Compose

The simplest way to run the entire CodeGraph-RAG full-stack system is with Docker Compose.

Step 1: Clone the Repository & Configure Environment

git clone https://github.com/HarshaAppikatla/CodeGraph-RAG.git
cd CodeGraph-RAG
cp .env.example .env

Add your API credentials to .env:

# Google Gemini API Key
GEMINI_API_KEY="your_gemini_api_key_here"

# Neo4j Password (defaults to 'password' in docker-compose)
NEO4J_PASSWORD="your_secure_password"

Step 2: Launch All Services

docker compose up --build

Step 3: Access Live Endpoints

Service Access URL Description
React 18 Dashboard http://localhost:5173 Interactive visualizer, blast radius explorer, and refactor sandbox
FastAPI Swagger Docs http://localhost:8000/docs Auto-generated OpenAPI interactive API documentation
Neo4j Browser http://localhost:7474 Cypher query console and property graph explorer

πŸ’» Alternative: Local Development Setup

If you prefer to run services individually without Docker:

1. Backend Setup

# Navigate to backend and install dependencies
cd backend
pip install -r requirements.txt

# Start the FastAPI server
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

2. Frontend Setup

# Navigate to frontend and install dependencies
cd frontend
npm install

# Start the Vite development server
npm run dev

3. MCP Integration for Cursor & VS Code

To use CodeGraph-RAG directly inside Cursor or VS Code, add this to your MCP configuration (.vscode/mcp.json or ~/.cursor/mcp.json):

{
  "servers": {
    "codegraph-rag": {
      "type": "stdio",
      "command": "python",
      "args": [
        "backend/mcp_server.py"
      ],
      "env": {
        "GEMINI_API_KEY": "your_gemini_api_key",
        "NEO4J_URI": "bolt://localhost:7687",
        "NEO4J_USERNAME": "neo4j",
        "NEO4J_PASSWORD": "your_password"
      }
    }
  }
}

For Claude Desktop, add to claude_desktop_config.json:

{
  "mcpServers": {
    "codegraph-rag": {
      "command": "python",
      "args": [
        "/path/to/CodeGraph-RAG/backend/mcp_server.py"
      ],
      "env": {
        "GEMINI_API_KEY": "your_gemini_api_key",
        "NEO4J_URI": "bolt://localhost:7687",
        "NEO4J_USERNAME": "neo4j",
        "NEO4J_PASSWORD": "your_password"
      }
    }
  }
}

πŸ“Š System Performance Benchmark

Evaluated across production multi-module repositories (including Study-Sync, 211 source files):

Metric Measured Benchmark Description
Ingestion Throughput 211 files / ~4.2s Automated Tree-sitter parsing, vector chunking, and graph creation
Graph Scale 2,533 Nodes / 1,195 Edges Scope-attributed caller/callee links populated in Neo4j
Impact Recall 100% Caller Recall Zero unnamed_entity drops for enclosed method and function calls
Protocol Latency < 15ms stdio RPC Native stdio JSON-RPC 2.0 communication overhead
Faithfulness Score 5.0 / 5.0 Factual AST alignment scored via automated LLM-as-a-Judge
Relevancy Score 5.0 / 5.0 Direct adherence to query constraints and structural specifics
Failover Resilience 100% Zero failure rate during rate limits via dynamic model failover

πŸ› οΈ Common Troubleshooting

  • Neo4j Connection Timeout: Verify your URI uses neo4j+s:// for Neo4j AuraDB or bolt://localhost:7687 for local Docker containers. Fast failover (2-second timeout) is active by default.
  • Tree-sitter Parsing Error: Ensure C compiler toolchains (gcc / clang / MSVC) are installed if building tree-sitter language bindings from source.
  • MCP Stdio Logs: MCP servers communicate strictly over stdout. All debug print statements in Python modules write to sys.stderr to prevent JSON-RPC stream corruption.

πŸ—ΊοΈ Roadmap

  • Polyglot Tree-sitter Scope-Resolved AST Extraction
  • Dual-Stream Neo4j + Qdrant Integration
  • FastMCP Server with stdio JSON-RPC 2.0 support
  • Multi-Tier Gemini LLM Failover Mesh
  • Full-Stack Monorepo (FastAPI Backend + React 18 SPA)
  • Multi-Container Docker Compose Orchestration
  • Language Server Protocol (LSP) Dynamic Symbol Resolution
  • Real-time Git Webhook incremental graph synchronization
  • Visual Interactive 3D Call-Graph Web Sandbox

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create your feature branch (git checkout -b feature/amazing-feature).
  3. Commit your changes (git commit -m 'feat: Add amazing feature').
  4. Push to the branch (git push origin feature/amazing-feature).
  5. Open a Pull Request.

πŸ“ License

Distributed under the MIT License. See LICENSE for more information.


πŸ‘€ Author

Appikatla Harsha Vardhan

About

Agentic RAG engine leveraging AST Code Graphs, Vector Search, and Google Antigravity SDK

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages