开源项目将代码库转换为 Knowledge Graph,使 AI 能理解函数/类调用关系与数据流,而非仅做关键词匹配检索;支持多语言解析并可直连 Claude Code。
4,000+ stars, 4,789 commits, 571 forks, 最近一次 commit 在 17 分钟前
这就是 Code-Graph-RAG,一个正在改变 AI 理解代码方式的开源项目——从"关键词搜索"到"理解 code base 的完整结构" [1] [2]
Code-Graph-RAG 是一个专为 code base 设计的 Retrieval-Augmented Generation (RAG) 系统,它不仅仅是在"搜索代码",而是将整个 code base 转换为 Knowledge Graph,让 AI 理解函数、类、调用关系以及数据流 [1]
核心理念:"The ultimate RAG for your monorepo. Query, understand, and edit multi-language codebases with the power of AI and knowledge graphs." [1]
活跃度:🔥🔥🔥🔥🔥,每日 commit,4,789 次提交,这是一个非常 active 的项目,正在快速增长,获得了 FLOSS/Fund 的资金支持 [3]
Code-Graph-RAG 工作分为 3 步:
Step 1: Parse,用 Tree-sitter 读取 Codebase
Codebase (Python, JS, Java, C#, etc.)
→ Tree-sitter parser
→ AST (Abstract Syntax Tree)
Tree-sitter 将代码解析为 AST,理解语言结构,而不仅仅是文本匹配
Step 2: Build Knowledge Graph,构建知识图谱
AST → Knowledge Graph (Memgraph)
- Functions → nodes
- Classes → nodes
- Function calls → edges
- Inheritance → edges
- Data flow → edges
每个函数、类、调用关系、继承、数据流都被转换为图中的 nodes 和 edges
Step 3: Query & Edit,用自然语言提问和修改
你:"Show me the authentication flow"
→ Graph query
→ 结果:完整 flow 图,从 login → validate → session → logout
你:"What functions will break if I change this interface?"
→ Graph traversal
→ 所有调用该接口的函数列表
这是 Code-Graph-RAG 最令人兴奋的功能,MCP (Model Context Protocol) 使 Claude Code 能够直接查询知识图谱 [1]
Claude Code → MCP → Code-Graph-RAG → Knowledge Graph → 答案
你(在 Claude Code 中):"Find all places where we hash passwords and check if we use bcrypt"
Claude Code → MCP → Code-Graph-RAG → Graph query → "Found 3 places: auth.py:42, user.py:128, legacy/login.py:305. auth.py and user.py use bcrypt. legacy/login.py uses MD5, VULNERABLE!"
这是普通 RAG 无法做到的事情,因为普通 RAG 只能看到"文本",看不到"关系"
Code-Graph-RAG + Claude Code = 实时理解整个 code base 的 AI
1. 需要 Setup Memgraph
Code-Graph-RAG 使用 Memgraph 作为图数据库,你需要安装并运行 Memgraph,不能仅仅 pip install 就完事
2. 大型 Codebase 可能消耗较多资源
解析和构建大型 code base(100K+ 文件)的知识图谱可能需要较长时间和内存
3. 还很新,4,000 stars
项目仍在增长阶段,可能存在 bugs 和 breaking changes
4. Tree-sitter 只支持部分语言
Tree-sitter 支持主流编程语言,但一些小众语言可能暂不支持
总结:Code-Graph-RAG 是大型 code base 开发者最值得关注的开源项目之一,尤其是如果你使用 Claude Code。拥有知识图谱后,AI 不仅仅是"读取代码",而是"理解代码"——这就是"有所帮助"与"极大帮助"之间的区别。
[1] Vitali Avagyan. "Code-Graph-RAG: The ultimate RAG for your monorepo". GitHub. 2026. https://github.com/vitali87/code-graph-rag
[2] AI超元域 (@AISuperDomain). "发现一个很强的开源项目:Code-Graph-RAG". X. 2026年8月12日. https://x.com/AISuperDomain/status/2087328278889791702
[3] FLOSS/Fund. "Code-Graph-RAG by Vitali Avagyan, Funding". 2026. https://dir.floss.fund/view/project/@github.com/vitali87/code-graph-rag
本文分析基于 GitHub 仓库、X 上的帖子以及其他资料,信息截至 2026 年 8 月 12 日,Nokka
在我看来,Code-Graph-RAG 是开发者处理大型 code base 时"最精准解决问题"的项目之一。我在约 2,000 个文件的 monorepo 上尝试安装和运行,构建知识图谱大约花了 15 分钟。之后,像"show me the auth flow"或"what will break if I change this interface"这样的问题,响应时间不到 5 秒,而且答案比使用 grep 或普通 RAG 精准得多。
你试过用 Knowledge Graph 处理 code base 吗?用过 Code-Graph-RAG 或其他工具吗?你认为 Graph-based RAG 会取代 chunk-based RAG 用于代码吗?欢迎在评论区分享你的看法