Theme / v0.9.56

Graphify

Codebase 知識圖譜

基礎觀念

Graphify 是什麼?

graphify 把 codebase(+docs/PDF/圖片/video)建成可查詢的 JSON 知識圖譜;AST 本地解析零 token,只在需要時呼叫 LLM

v0.9.32 更新重點

這個 correctness release 修正了增量抽取與 rebuild 的分層合併:AST 層更新不再誤刪 semantic 層,舊圖譜載入時也會補回 _origin provenance。另修正 graphify update 保留 directed flag、query 顯示所有已訪問節點間的邊、manifest.json 寫入正確輸出目錄,以及 C#、Kotlin、Ruby 等語言的解析與解析度問題。1

一句話說清楚

Graphify 是一個把 codebase 建成可查詢知識圖譜的工具。打 /graphify . 之後,你得到三個檔:

  • graphify-out/graph.json — 完整 JSON 圖譜
  • graphify-out/graph.html — 互動式 force-directed 視覺化
  • graphify-out/GRAPH_REPORT.md — god nodes、communities、建議問題

你的 AI 助理改用 graphify query / path / explain 找答案,而不是 grep 原始檔。

⚠️ 與舊版(已刪除)差異:上一版文件把 graphify 描述為「LLM + Neo4j 知識圖譜資料庫」。這完全錯誤:graphify 不使用 Neo4j,圖譜就是一個 JSON 檔;而且 graphify 的核心是 AST 本地解析,不是 LLM。


為什麼 grep 與 RAG 都不夠用

開發者要理解一個 codebase,傳統做法有兩條路:

Grep 的局限

嘗試 grep 結果
「認證怎麼做?」 grep -r "auth" 兩百個命中點,要逐一讀
「A 怎麼連到 B?」 grep A,再 grep B,人工 connect 心智負擔極重
「這個改動會影響誰?」 找 callers 跨檔追 import 鏈、容易遺漏

Vector RAG 的局限

把 codebase 切 chunk、算 embedding、推向量庫:

  • 每次都要付 embedding 成本
  • 相似度是黑盒子,無法精準回答「兩節點的 path」
  • 容易幻覺(similarity ≠ truth)

Graphify 的定位

graphify 是第三條路:把 codebase 變成 graph(六類邊 + 信心標籤),自然語言問問題時 graphify BFS 出子圖。三個關鍵:

  1. AST-first:程式碼用 tree-sitter 本地解析,零 LLM、零 token
  2. 結構化關係:每條邊是 calls/imports/inherits/references/re_exports/contains,不是模糊 similarity
  3. 可追溯:每條邊標 source_file + 行號 + EXTRACTED/INFERRED/AMBIGUOUS

AST-first:graphify 的核心

graphify 對程式碼的解析跟 grep 與 vector RAG 完全不同:

階段 grep / RAG graphify
解析 字串 match / embedding tree-sitter AST(36+ 種語言)
網路 完全本地 / 全部上 LLM AST 完全本地,零網路
Token 成本 0(grep)/ 大量(RAG) 0(純 code)
信心 EXTRACTED / INFERRED / AMBIGUOUS
Cross-hop 單檔 BFS 跨檔

graphify 把程式碼本身當一等公民,不用 LLM 去猜呼叫關係。

LLM 語意層(可選)

對 docs、PDF、圖片、video 這類非程式碼資源,AST 沒用,graphify 才會呼叫 LLM:

  • README / RFC / ADR → concept / rationale 節點
  • PDF → paper 節點
  • 圖片(schema、diagram)→ image 節點

這些節點再透過 references 邊連回到 codebase 的程式碼節點。

💡 你可以完全不開 LLM--code-only)就使用 graphify 80% 的價值。


graphify 出來的三個檔

graph.json

完整 JSON 圖譜。schema 大致:

{
  "nodes": [
    { "id": "auth:login", "label": "login", "source_file": "auth.py", "source_location": 1, "community": 2 }
  ],
  "edges": [
    { "source": "auth:login", "target": "auth:verify_password", "relation": "calls", "confidence": "EXTRACTED" }
  ]
}

可直接用 jq 檢視、或用 graphify CLI 查。

graph.html

開瀏覽器即可看到:

  • Force-directed 視覺化
  • 每個節點可點開看 connections
  • 可按 community 過濾顏色
  • 可文字搜尋

GRAPH_REPORT.md

graphify 自動為你問的好問題:

  • 🌟 God nodes — degree 最高的節點,這個 codebase 的核心
  • 🎨 Communities — Leiden 分群,子系統邊界
  • 🔗 Surprising connections — 跨檔的、不直覺的連結
  • 💡 Suggested questions — 4-5 個可以問圖譜的問題

助理讀這份報告比讀 README 還快上手 codebase。


與傳統 RAG 的比較

graphify 官方 v0.9.32 README 的 BENCHMARKS.md:1

Benchmark graphify 比較組
LOCOMO recall@10 0.497 mem0 0.048、supermemory 0.149
LOCOMO QA accuracy 45.3% supermemory 49.7%、mem0 27.3%
LongMemEval-S QA 76% tied with dense RAG
Graph build LLM credits 0 per-token for most systems

graphify 不一定要贏所有 benchmark,但 graph build 零 token 這點對 CI / 大 monorepo 極具價值。


graphify 不適合做什麼

  • 取代你的 IDE:graphify 是查詢層,不是編輯器
  • 即時 lint / format:那不是它的職責
  • Vector similarity search:graphify 是 graph 不是 vector index
  • 2 GB 以上單檔 PDF:LLM chunk 成本過高,建議切小

開始用 graphify

3 步驟:

# 1. 安裝(PyPI 套件名 graphifyy,雙 y)
uv tool install graphifyy

# 2. 對助理註冊
cd ~/your-project
graphify claude install --project    # 或 cursor/codex/gemini...

# 3. 建圖
/graphify .                          # 在助理內
# 或
graphify extract . --code-only       # 終端

內部連結


下一步

  1. 快速入門工作流
  2. graphify build 指令詳解
  3. 探索陌生 codebase 範例

Footnotes

  1. Graphify v0.9.32 release notes 2