Skip to content

feat(graph): opt-in GraphRAG layer over Decision Structure (D1 edges + traversal)#156

Merged
liplus-lin-lay merged 1 commit into
mainfrom
155-graphrag-layer
Jun 14, 2026
Merged

feat(graph): opt-in GraphRAG layer over Decision Structure (D1 edges + traversal)#156
liplus-lin-lay merged 1 commit into
mainfrom
155-graphrag-layer

Conversation

@liplus-lin-lay

Copy link
Copy Markdown
Member

Closes #155

概要

dense(Vectorize)+sparse(D1 FTS5) の RRF ハイブリッドに、判断知(Decision Structure = wiki エントリ)の関係を索引化する additive なグラフ層を追加。search に opt-in の graph_expand を足し、関連 wiki ページを辿って結果末尾に append する。

設計原則

  • 完全 additive・既定 off: graph_expand=false(既定)時は既存 retrieval と byte-identical(回帰なし)。on の時だけグラフを読む。
  • エッジ抽出は決定的 slug-match(LLM 不要・ロスなし)。dst の vector_id は wikiDocVectorId で計算でき lookup 不要(dangling 可)。
  • まず generic "mention" edge のみ(typed supersede/depend/conflict は後続)。

変更

  • migrations/0002_graph_edges.sql: doc_edges テーブル(src/dst/repo/slugs/edge_kind)+index。
  • src/graph.ts(新規): 抽出(indexWikiEdges)/ upsert / delete / 再帰CTE traversal(queryNeighbors)/ neighbor enrich。
  • src/pipeline/embed-doc.ts: wiki index 直後に抽出フック(失敗しても本体 index を壊さない)。
  • src/mcp.ts: searchgraph_expand/graph_hops param、RRF 後の最終結果を seed に neighbor を append、ResultItemgraph_hop/graph_from、response に graph_expanded/graph_neighbors
  • src/poller.ts: wiki 削除時の edge delete fan-out。
  • src/index.ts: POST /admin/backfill-edges?repo=...(GITHUB_TOKEN 認証)で既存 wiki から一括抽出(GitHub 再取得不要)。
  • docs/0-requirements.{ja,}.md: graph 層の節を追記(同一 PR)。

検証

  • tsc --noEmit 通過(exit 0)。
  • 再帰 CTE の SQL を実 SQLite(=D1 同エンジン)で実行検証: seeds→1-2hop neighbor を正しく辿り provenance も正確、repo フィルタも動作。
  • deploy 後: graph_expand 省略時の回帰なし確認 → backfill 実行 → 実 DS クエリで on/off 比較を実運用観測(Li+ ネイティブ評価)。

デプロイ(auto モード)

AI self-review → merge → wrangler d1 migrations apply github-rag-ftswrangler deploy → backfill → observe(~5分/次 cron)。Master が "実装して ship+実運用観測" を go 済み。

Add an additive graph index over wiki Decision-Structure entries. A new D1
table (doc_edges, migration 0002) stores deterministic slug-mention edges
between wiki pages; src/graph.ts extracts them at wiki index time
(processAndUpsertWikiDoc) via exact slug matching (no LLM) and traverses them
with a recursive CTE. The search tool gains opt-in graph_expand / graph_hops
params: when off (default) retrieval is byte-identical to before; when on,
related wiki pages are appended to results (graph_hop / graph_from). Delete
fan-out (deleteEdgesForVector) and a one-off backfill endpoint
(POST /admin/backfill-edges) are included. Requirements doc updated.

dense(Vectorize)+sparse(D1 FTS5) のハイブリッドに、判断知(Decision Structure)の
関係を索引化する additive なグラフ層を足した。既定 off=既存 retrieval 完全不変、
on の時だけ関連 wiki を辿って末尾に付ける。エッジ抽出は決定的 slug-match で LLM
不要、再帰 CTE は実 SQLite で動作検証済み。評価は本番 ship 後の実運用観測。

Refs #155
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
github-rag-mcp 6b9341f Jun 14 2026, 04:52 AM

@liplus-lin-lay liplus-lin-lay left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

自己レビュー(auto モード / AI self-review)

整合・安全

  • 完全 additive・既定 off: graph_expand 省略時、retrieval は dense+sparse+RRF の既存パスのみを通り byte-identical(graph 層は読まれない)。回帰リスクなし。
  • 抽出フック / delete fan-out / backfill / graph 展開は全て try/catch の best-effort で、失敗しても本体 index・retrieval を壊さない。
  • migration は IF NOT EXISTS・追加テーブルのみ(既存スキーマ非破壊)。

検証

  • tsc --noEmit exit 0。
  • 再帰 CTE を実 SQLite(=D1 同エンジン)で実行検証済(seeds→1-2hop neighbor 正確・provenance 正確・repo フィルタ動作)。
  • CI: test / CI / Workers Builds 全 pass、mergeStateStatus=CLEAN。

deploy(Master go 済み: 「実装して ship+実運用観測」)

merge 後: wrangler d1 migrations apply github-rag-ftswrangler deployPOST /admin/backfill-edges → observe(~5分/次 cron)。回帰確認(graph_expand 省略=不変) を最優先で実施。

判定: マージ可。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(graph): opt-in GraphRAG layer over Decision Structure (D1 edges + traversal)

1 participant