vitali87 / code-graph-rag
vitali87 / code-graph-rag
Code-Graph-RAG parses a multi-language codebase with Tree-sitter, builds a knowledge graph of its structure in Memgraph, and lets you query, edit, and optimise that code in plain English. It works across a monorepo of mixed languages under one unified graph schema. Code-Graph-RAG 使用 Tree-sitter 解析多语言代码库,在 Memgraph 中构建其结构知识图谱,并允许你用纯英语查询、编辑和优化代码。它可以在统一的图模式下,跨混合语言的单体仓库(monorepo)工作。
Latest News
最新动态
🔥 Ruby Support: Ruby joins the graph through a new pluggable ast-grep tier that adds a language from a single YAML pattern file, emitting Module, Function, and Class nodes plus import edges without a hand-written parser. 🔥 Ruby 支持:Ruby 通过一个新的可插拔 ast-grep 层加入图谱。该层允许通过单个 YAML 模式文件添加语言,无需手写解析器即可生成模块(Module)、函数(Function)和类(Class)节点以及导入(import)边。
Structural Search & Replace: Find and rewrite code by AST pattern with ast-grep, exposed as agent tools so you can match and transform structure across the whole codebase instead of relying on text or regex. 结构化搜索与替换:利用 ast-grep 通过 AST 模式查找并重写代码。这些功能作为智能体工具公开,使你能够匹配并转换整个代码库的结构,而无需依赖文本或正则表达式。
Data-Flow Tracing: New FLOWS_TO taint edges follow values through assignments, function calls, and I/O sinks, with coverage across C#, Java, C, and Go. See NEWS.md for the full history. 数据流追踪:新增的 FLOWS_TO 污点边可以追踪值在赋值、函数调用和 I/O 接收端之间的流向,目前覆盖 C#、Java、C 和 Go 语言。完整历史记录请参阅 NEWS.md。
What It Does
功能概述
Point Code-Graph-RAG at a repository and it reads every source file, extracts functions, classes, methods, modules, and the relationships between them, and stores the result as an interconnected graph. Once the graph exists you can: 将 Code-Graph-RAG 指向一个仓库,它会读取每个源文件,提取函数、类、方法、模块及其相互关系,并将结果存储为一个互联的图谱。一旦图谱建立,你可以:
- Ask questions about the codebase in natural language and get answers grounded in the real structure.
- 用自然语言询问有关代码库的问题,并获得基于真实结构回答。
- Retrieve the actual source of any function, class, or method by name or by intent.
- 通过名称或意图检索任何函数、类或方法的实际源代码。
- Edit code through the agent with AST-based surgical patching and a diff preview before anything changes.
- 通过智能体进行基于 AST 的精准代码修补,并在更改前预览差异(diff)。
- Optimise code against language best practices or your own coding standards.
- 根据语言最佳实践或你自己的编码标准优化代码。
- Find dead code by walking call and reference edges from entry points.
- 通过从入口点遍历调用和引用边来查找死代码。
- Search and rewrite structurally by AST pattern with ast-grep.
- 使用 ast-grep 按 AST 模式进行结构化搜索和重写。
How It Works
工作原理
The system has two components: 该系统包含两个组件:
-
Multi-language parser. A Tree-sitter based parser reads the codebase and ingests functions, classes, methods, modules, and their relationships into Memgraph under a single language-agnostic schema.
-
多语言解析器。 基于 Tree-sitter 的解析器读取代码库,并将函数、类、方法、模块及其关系以统一的、与语言无关的模式存入 Memgraph。
-
RAG system (codebase_rag/). An interactive CLI that turns natural language into Cypher queries, retrieves matching code, and drives AI-powered editing and optimisation.
-
RAG 系统 (codebase_rag/)。 一个交互式 CLI,将自然语言转换为 Cypher 查询,检索匹配的代码,并驱动 AI 辅助的编辑和优化。
Source Code -> Tree-sitter Parser -> AST Analysis -> Memgraph Knowledge Graph | User Query -> AI Model (Cypher Gen) -> Cypher Query -> Graph Results -> Response 源代码 -> Tree-sitter 解析器 -> AST 分析 -> Memgraph 知识图谱 | 用户查询 -> AI 模型 (Cypher 生成) -> Cypher 查询 -> 图谱结果 -> 响应
See the Architecture Overview and Graph Schema for the full picture. 查看架构概览和图谱模式以获取完整信息。
Supported Languages
支持的语言
Python, TypeScript, TSX, JavaScript, Rust, Go, Java, C, C++, C#, PHP, Lua, and Dart are fully supported. Scala is in development, and Ruby has structural support (modules, functions, classes, and imports) through the pluggable ast-grep tier. See the Language Support matrix for per-language capabilities. 完全支持 Python、TypeScript、TSX、JavaScript、Rust、Go、Java、C、C++、C#、PHP、Lua 和 Dart。Scala 正在开发中,Ruby 通过可插拔的 ast-grep 层提供结构化支持(模块、函数、类和导入)。请参阅语言支持矩阵了解各语言的具体能力。
Installation
安装
cgr is published to PyPI. Install it system-wide with the treesitter-full (all languages) and semantic (vector search) extras: cgr 已发布至 PyPI。使用 treesitter-full(所有语言)和 semantic(向量搜索)扩展进行全局安装:
# with uv (recommended)
uv tool install "code-graph-rag[treesitter-full,semantic]"
# or with pipx
pipx install "code-graph-rag[treesitter-full,semantic]"
You also need Docker (for Memgraph), cmake, and ripgrep. Full prerequisites, source installs, and environment setup are in the Installation guide. 你还需要 Docker(用于 Memgraph)、cmake 和 ripgrep。完整的先决条件、源码安装和环境设置请参阅安装指南。
Quick Start
快速开始
# Start the packaged Memgraph + Qdrant stack (no compose file needed)
cgr daemon up
# Parse a repository into the graph, then query it
cgr start --repo-path /path/to/repo --update-graph
cgr start --repo-path /path/to/repo
Repeat the first command for each repository you want indexed; the graph is shared, and syncing one project leaves the others alone. To start over from an empty graph, add —clean — it deletes every project in the shared graph, not just this one, and asks for confirmation first when other projects would be destroyed. The Quick Start guide walks through parsing, querying, and exporting in five minutes.
对每个需要索引的仓库重复第一个命令;图谱是共享的,同步一个项目不会影响其他项目。若要从空图谱重新开始,请添加 --clean 参数——它会删除共享图谱中的所有项目,而不仅仅是当前项目,并在删除其他项目前请求确认。快速入门指南将在五分钟内带你完成解析、查询和导出操作。
MCP Server
MCP 服务器
Code-Graph-RAG runs as an MCP server so Claude Code and other MCP clients can query and edit your codebase directly. See the MCP Server guide for setup. Code-Graph-RAG 可作为 MCP 服务器运行,因此 Claude Code 和其他 MCP 客户端可以直接查询和编辑你的代码库。请参阅 MCP 服务器指南进行设置。
Enterprise Services
企业服务
Code-Graph-RAG is open source and free to use. For organisations that need more, we offer fully managed cloud-hosted solutions and on-premise deployments: Code-Graph-RAG 是开源且免费使用的。对于有更多需求的企业,我们提供完全托管的云端解决方案和本地部署:
-
Cloud-Hosted Deployment: Managed cloud infrastructure for both the graph database and the AI agent connection. Zero infrastructure overhead, so we handle scaling, updates, and availability while your team focuses on building.
-
云端部署: 为图数据库和 AI 智能体连接提供托管云基础设施。零基础设施开销,我们负责扩展、更新和可用性,而你的团队可以专注于构建。
-
On-Premise & Air-Gapped Deployment: Deploy Code-Graph-RAG entirely within your own environment, including air-gapped networks. Full data sovereignty for regulated industries and security-sensitive organisations.
-
本地及离线部署: 将 Code-Graph-RAG 完全部署在你自己的环境中,包括离线网络。为受监管行业和安全敏感型组织提供完全的数据主权。
We also offer custom development, integration consulting, technical support contracts, and team training. View plans & pricing at code-graph-rag.com 我们还提供定制开发、集成咨询、技术支持合同和团队培训。查看方案与定价请访问 code-graph-rag.com。
Contributing
贡献
Please see CONTRIBUTING.md for contribution guidelines. Good first PRs come from the TODO issues. 请参阅 CONTRIBUTING.md 获取贡献指南。好的入门 PR 可以从 TODO 问题中寻找。
Support
支持
For issues or questions, check the Troubleshooting guide first, then open an issue. 如有问题或疑问,请先查看故障排除指南,然后再提交 Issue。
License
许可证
MIT. See LICENSE. MIT 协议。请参阅 LICENSE。