Graphify:将任意代码库转化为AI编程助手可查询的知识图谱
Graphify 是一个将代码库、文档、PDF、图片和视频映射为知识图谱的开源工具,专为 AI 编程助手(如 Claude Code、Cursor、Gemini CLI 等 20+ 平台)设计。它使用 tree-sitter AST 对代码进行确定性解析(完全本地、无需 LLM),对文档/媒体则通过 AI 助手模型做语义提取。输出是一个可交互的 HTML 可视化、一份 Markdown 报告和可复用的 graph.json,支持用户通过自然语言查询、路径追踪和概念解释。每一条边都带有置信度标签(EXTRACTED / INFERRED),让开发者明确区分“读到的”和“推测的”。适合需要快速理解大型陌生代码库或在长尾维护中依赖 AI 助手的工程师。
Graphify is an open-source tool that turns any codebase into a queryable knowledge graph. It parses code, documentation, images, and even video to build a real graph (not a vector index), enabling AI coding assistants and developers to ask questions like “How are X and Y connected?” or “Explain Z” instead of grepping through files or relying on embeddings. The graph is fully local for code (using tree-sitter AST) and optionally extends to other media via LLM calls.
Graphify 是一个开源工具,能将任意代码库转化为可查询的知识图谱。它解析代码、文档、图片甚至视频,构建一个真实的图结构(而非向量索引),让 AI 编码助手和开发者可以直接提问“X 和 Y 如何连接?”或“解释一下 Z”,而不再需要逐文件 grep 或依赖嵌入向量。代码部分完全本地运行(使用 tree-sitter AST),其他介质可选择性调用 LLM 进行语义提取。
Traditionally, understanding a large codebase requires developers or AI assistants to repeatedly read files and manually trace call chains and inheritance relationships—time-consuming and error-prone. Vector databases offer semantic similarity but fail to capture precise structural relationships. Graphify uses deterministic AST parsing via tree-sitter for code, plus optional semantic extraction for docs and media, to build a knowledge graph that includes edges like calls, imports, inherits, and mixes-in. Users can then query with natural language or path traversal to instantly locate cross-file concept relationships, making the entire codebase navigable in seconds.
传统上,理解大型代码库需要开发者或 AI 助理反复阅读文件、手动追踪调用链和继承关系,既耗时又易出错。向量数据库虽能提供语义相似度,却无法精确表达结构关系。Graphify 利用 tree-sitter 确定性解析代码 AST,再结合文档与介质的可选语义提取,构建出包含调用、导入、继承、混入等边界的知识图谱。用户可以通过自然语言问题或路径查询,瞬间定位到跨文件的概念关系,使整个代码库在几秒内变得可导航。
Graphify's core design is "graph over vectors." Every node represents a concept (function, class, file, document, etc.), and every edge carries a confidence tag: EXTRACTED (explicit in source, e.g., a function call) or INFERRED (derived by resolution, e.g., indirect dependencies). It uses no embeddings or vector store, so queries are exact and interpretable. Additionally, it identifies "god nodes" (the most connected concepts) and performs community detection via the Leiden algorithm to automatically split the project into subsystems, each with a readable label. The output includes three files: graph.json (full graph), graph.html (interactive visualization), and GRAPH_REPORT.md (highlights, god nodes, suggested questions).
Graphify 的核心设计是“用图而非向量”。每个节点代表一个概念(函数、类、文件、文档等),每条边都带有置信度标签:EXTRACTED(源文件明确的关系,如函数调用)或 INFERRED(通过解析推导的关系,如间接依赖)。它完全不使用嵌入或向量存储,因此查询结果精确、可解释。此外,它还识别“上帝节点”(连接最多的概念),并通过 Leiden 算法进行社区检测,自动将项目划分为子系统并生成可读标签。输出包括三个文件:graph.json(完整图数据)、graph.html(交互式可视化)以及 GRAPH_REPORT.md(高亮点、上帝节点、建议问题)。
Graphify's extraction pipeline is split into two parts: code files are parsed locally via tree-sitter AST—no LLM, nothing leaves the machine. For docs, PDFs, images, and video, the system invokes the AI assistant's model or a configured API key for a semantic pass. After extraction, Leiden community detection runs (configurable parameters like resolution), and labels can be generated automatically or with an LLM backend. The entire workflow is controllable via CLI commands such as graphify extract, graphify cluster-only, and graphify label, enabling incremental updates, skipping visualization, or exporting to Neo4j. The pipeline also supports git hooks for automatic rebuild after commits.
Graphify 的提取流程分为两部分:代码文件通过 tree-sitter AST 在本地解析——不调用 LLM,数据不出机器。文档、PDF、图片和视频则调用 AI 助手的模型或配置的 API 进行语义提取。解析后,运行 Leiden 社区检测(可配置分辨率等参数),标签可由 LLM 自动生成或手动指定。整个工作流可通过 CLI 命令精细控制,如 graphify extract、graphify cluster-only、graphify label,支持增量更新、跳过可视化或导出到 Neo4j。流水线还支持 git hook,可在提交后自动重建图。
Installation is straightforward: use uv tool install graphifyy (recommended) or pipx install graphifyy. Then run graphify install to register the skill with your AI assistant (supports 20+ platforms: Claude Code, Cursor, Codex, Gemini CLI, etc.). After that, type /graphify . in the assistant to build a knowledge graph for the current directory. Common queries include /graphify query "...", /graphify path A B, and /graphify explain "...". Outputs go to the graphify-out/ directory. For headless or CI usage, use graphify extract with explicit backend configuration.
安装非常简单:推荐使用 uv tool install graphifyy 或 pipx install graphifyy。然后运行 graphify install 将技能注册到你的 AI 助理(支持 Claude Code、Cursor、Codex、Gemini CLI 等 20 多个平台)。之后在助理中输入 /graphify . 即可为当前目录构建知识图谱。常用查询包括 /graphify query "..."、/graphify path A B 和 /graphify explain "..."。输出文件位于 graphify-out/ 目录。对于无头或 CI 使用场景,可使用 graphify extract 并明确指定后端。
Graphify is ideal for static codebase analysis and exploration, especially large projects where cross-file relationship understanding boosts AI context. It also integrates docs, papers, and video. However, graph building is batch-oriented, so it's not suitable for real-time streaming or rapidly changing codebases. Code parsing is fully local, but document/media semantic extraction relies on external API (unless using local Ollama), which may introduce data privacy and cost considerations. For code-only workflows, it runs completely offline. Note that the graph.json file has a default 512 MiB cap, and browser visualization may become unresponsive beyond 5000 nodes. Graphify supports confidence tags and duplicate merging to ensure reliability.
Graphify 最适合静态代码库的分析与探索,尤其适用于大型项目中跨文件关系理解以增强 AI 上下文感知的场景。它也能集成文档、论文和视频。但图构建是批处理的,不适合实时流或频繁变更的代码库。代码解析完全本地运行,但文档和媒体的语义提取依赖外部 API(除非使用本地 Ollama),可能带来数据隐私和成本方面的考量。对于纯代码任务,可完全离线运行。注意:graph.json 默认大小上限为 512 MiB,浏览器可视化在节点超过 5000 时可能无响应。Graphify 通过置信度标签和重复节点合并来保证可靠性。