Source Tracking Skill
graphify 設計上把「每一條知識都知道來自哪裡」當一等公民。每個節點、每條邊都有:
source_file— 來自哪個檔案source_location— 行號- 信心標籤:
EXTRACTED/INFERRED/AMBIGUOUS - 對 LLM 表面的程式碼節點,會標
verification: "unverified"
這意味 graphify 查詢結果永遠可追溯,不像 vector RAG 拿到答案還要去全文找依據。
何時使用
✅ 適合的情境:
- 需要審核 AI 回答(「這個說法從哪來?」)
- 想知道某概念第一次出現在哪個 doc / commit
- 重購前確認哪些 code node 該改
❌ 不適合的情境:
- 只看大方向的 god node 列表(用
GRAPH_REPORT.md即可) - 已經知道答案只是驗證(用
graphify path即可)
節點與邊 schema
節點(node)
{
"id": "auth:login",
"label": "login",
"source_file": "auth.py",
"source_location": 1,
"community": 2,
"degree": 4,
"verification": null, // 或 "unverified"
"file_type": "code" // 或 concept / rationale / document / paper / image
}
邊(edge)
{
"source": "auth:login",
"target": "auth:verify_password",
"relation": "calls",
"source_file": "auth.py",
"source_location": 3,
"confidence": "EXTRACTED"
}
信心標籤三類
graphify 每條邊都有信心標籤:
| 標籤 | 意義 | 例如 |
|---|---|---|
EXTRACTED |
原始程式碼 / 文件中直接出現 | login() → verify_password() 直接看到呼叫 |
INFERRED |
graphify 解析後推論出來 | 跨檔案 import 後的 calls |
AMBIGUOUS |
推論有多個候選 | 兩個同名類別的其中之一 |
💡 從 v0.9.23 起
graphify path顯示的 relation 改為讀邊的真實 stored relation,不再讀 collapsed parallel edge,避免報錯 relation。1
Verification 旗標(v0.9.18+)
LLM 可能 surface code 類型節點但該符號名稱在原始碼根本沒出現(推論或幻覺)。v0.9.18 起 graphify 對這類節點標:
verification: "unverified"
不會 drop 掉節點,但助理在引用時應加「待驗證」字樣。可用 graphify diagnose 檢視 unverified 節點清單。2
範例:審核 AI 回答
助理:根據 graphify 圖譜,`login()` 呼叫了 `verify_password()`。
使用者:這是哪個檔?
助理:根據邊的 source_file / source_location 欄位:
login -[calls]-> verify_password
source: auth.py:3
confidence: EXTRACTED ← 原始碼直接寫的呼叫
→ 在 auth.py 第 3 行就是 `verify_password(user, password)`。
對 INFERRED 邊,助理會提供「graphify 推論」的免責聲明。
範例:找出 stale node
某個 PR 改了 auth.py 但 assistant 仍引用 legacy_login:
graphify diagnose | grep "auth.py"
→ 若 legacy_login 標 verification: "unverified",可能是舊版的残留,跑 graphify extract . --force 清掉幽靈節點即可。
圖譜 diff(refactor 前後)
# 拉 baseline
cp graph.json baseline.json
# refactor 後
graphify extract . --force
# 對比
graphify merge-graphs baseline.json graph.json --out diff.json
後續可用 jq 分析哪節點消失、哪節點新增。
不一樣:graphify source tracking vs vector RAG
| 維度 | Vector RAG | graphify |
|---|---|---|
| 每個事實可追溯到 source | 抓近似 chunk,可丟 | 每條邊標 source_file + line |
| 信心分 | cosine 相似度 | EXTRACTED / INFERRED / AMBIGUOUS |
| Unverified 節點辨識 | 無 | 顯式 verification 旗標 |
graphify 對「需要審核、回滾、refactor 評估」這類事實可驗證情境遠優於 vector RAG。