Code-Graph-RAG
An open-source RAG system that builds AI-powered knowledge graphs from multi-language codebases, enabling natural language querying, code editing, and analysis via MCP integration.
At a Glance
About Code-Graph-RAG
Code-Graph-RAG is an open-source Retrieval-Augmented Generation (RAG) system built by Vitali Avagyan under the MIT License. It parses multi-language codebases using Tree-sitter, stores the resulting structure as an interconnected knowledge graph in Memgraph, and lets developers query, edit, and optimize their code using natural language. The project is available on PyPI and integrates directly with Claude Code as an MCP server.
What It Is
Code-Graph-RAG sits at the intersection of static code analysis and AI-powered developer tooling. It addresses the challenge of understanding large polyglot monorepos — where services span Python, TypeScript, Go, Rust, Java, and more — by building a unified graph of all code entities and their relationships. Once the graph is built, developers can ask questions in plain English, retrieve source code by intent, surgically edit functions, detect dead code, and trace data flows, all without manually reading thousands of files.
The system has two main components:
- Multi-language parser: Tree-sitter-based AST parsing across 14 languages (Python, TypeScript, JavaScript, Rust, Java, C, C++, Lua, C#, Go, PHP, Dart, Ruby, Scala) with a unified graph schema
- RAG system: An interactive CLI and MCP server that translates natural language into Cypher graph queries, retrieves matching code, and drives AI-powered editing and optimization
Architecture and Graph Schema
The knowledge graph uses 20 node types (Function, Class, Module, File, Package, Resource, SecurityIssue, CodeSmell, Pattern, and more) and 23 relationship types (CALLS, IMPORTS, CONTAINS, INHERITS, IMPLEMENTS, FLOWS_TO, READS_FROM, WRITES_TO, and others). Every supported language maps to the same schema, so a single Cypher query can span a polyglot monorepo.
Key architectural layers include:
- Tree-sitter AST parsing with libclang and Roslyn semantic frontends for C/C++ and C#
- Memgraph as the graph database backend
- Qdrant for vector embeddings powering semantic search (UniXcoder embeddings)
- ast-grep for structural pattern matching and replacement
- AI Cypher generation supporting Google Gemini, OpenAI, and Ollama
MCP Server and Claude Code Integration
Code-Graph-RAG runs as an MCP server, exposing 15 tools directly to Claude Code and other MCP clients: index_repository, query_code_graph, get_code_snippet, surgical_replace_code, semantic_search, structural_search, structural_replace, ask_agent, and more. Setup involves installing via uv tool install, starting the packaged Memgraph + Qdrant stack with cgr daemon up, and registering the MCP server with claude mcp add.
Core Capabilities
- Natural language querying: AI translates plain English questions into Cypher queries against the knowledge graph
- Semantic code search: Find functions by describing intent using UniXcoder embeddings with similarity scores
- Structural search & replace: Match and rewrite code by AST pattern with ast-grep — structure-aware, not text or regex
- AI code editing: Surgical AST-based function replacement with visual diff previews before applying changes
- Dead code detection: Walk call and reference edges from entry points to surface unreachable functions; CI-friendly with
--fail-on-found - Data-flow tracing:
FLOWS_TOtaint edges follow values from sources through assignments, calls, and returns to I/O sinks - Security & code smell findings: Bundled ast-grep rule packs store hits as SecurityIssue, CodeSmell, or Pattern nodes in the graph
- Real-time graph updates: Debounced file watcher keeps the graph synchronized during active development
- Python SDK: Programmatic access to graph loader, Cypher generator, semantic search, and settings
Update: v0.0.484 and Recent Releases
The project reached version v0.0.484 (published July 2026) and shows active development with frequent releases. Recent additions highlighted in the README include Ruby structural support via the new pluggable ast-grep tier (adding a language from a single YAML pattern file), Structural Search & Replace exposed as agent tools, and Data-Flow Tracing with FLOWS_TO taint edges covering C#, Java, C, and Go. The repository reports 2,424 stars and 404 forks on GitHub (per the project's own homepage display) and holds OpenSSF Best Practices verification and an OpenSSF Scorecard badge.
Deployment Model and Enterprise Services
The core tool is free and open source under the MIT License. Enterprise services — funded to support continued development — include cloud-hosted managed deployments (graph DB + AI agent), on-premise and air-gapped deployments, custom knowledge graph relationship definitions (compliance traceability, data lineage, team ownership), custom language parser development, SLA-backed support contracts, integration consulting, and training workshops. Enterprise pricing is custom-quoted based on organizational needs.
Community Discussions
Be the first to start a conversation about Code-Graph-RAG
Share your experience with Code-Graph-RAG, ask questions, or help others learn from your insights.
Pricing
Community
Open-source, free forever. Full codebase analysis with all features included.
- Full codebase analysis
- All 14 supported languages
- Knowledge graph generation
- Natural language & semantic search
- Structural search & replace
Professional
For teams that need reliable support with cloud-hosted infrastructure and SLA-backed response times.
- Everything in Community
- Cloud-hosted graph DB & agent
- Custom language support
- Priority email support
- SLA-backed response times
- Onboarding assistance
- Configuration review
- Quarterly check-ins
Enterprise
Custom solutions for large organizations with on-premise deployment and dedicated support.
- Everything in Professional
- Custom graph relationships & edge definitions
- On-premise & air-gapped deployment
- Custom development
- Integration consulting
- On-site training workshops
- Dedicated account manager
- Architecture review
Capabilities
Key Features
- Multi-language AST parsing with Tree-sitter across 14 languages
- Knowledge graph storage in Memgraph with 20 node types and 23 relationship types
- Natural language to Cypher query translation
- Semantic code search using UniXcoder embeddings
- Structural search and replace with ast-grep
- AI-powered surgical code editing with diff previews
- Dead code detection with CI-friendly failure mode
- Data-flow tracing with FLOWS_TO taint edges
- Security and code smell findings stored as graph nodes
- MCP server with 15 tools for Claude Code integration
- Real-time graph updates via file watcher
- Python SDK for programmatic graph access
- Graph export in JSON and protobuf formats
- Interactive code optimization with language-specific best practices
- Dependency analysis from pyproject.toml
- Support for Google Gemini, OpenAI, and Ollama for Cypher generation
- Extensible language support via single YAML pattern files
