Skip to content

feat(diff-index): add commit diff retrieval surface (#80) - #81

Merged
liplus-lin-lay merged 1 commit into
mainfrom
80-enhancement-index-commit-diffs-for-judgment-history-retrieval
Apr 19, 2026
Merged

feat(diff-index): add commit diff retrieval surface (#80)#81
liplus-lin-lay merged 1 commit into
mainfrom
80-enhancement-index-commit-diffs-for-judgment-history-retrieval

Conversation

@liplus-lin-lay

Copy link
Copy Markdown
Member

Closes #80

概要

commit diff を semantic 検索可能な retrieval surface として追加しました(Option 2b)。push webhook の commits[] を iterate し、各 commit に対し GET /repos/{repo}/commits/{sha} で per-file patch を取得、1 commit × N files → N vectors を batch embedding(Workers AI text: string[])で 1 call にまとめて Vectorize に upsert します。

削除済みファイルや非 .md 拡張子(.pal など)の判断履歴も semantic で引けるようになります。契機は 2026-04-19 に momeri.pal(liplus-language、削除済み)を RAG 経由で届かせられなかった事例です。

変更内容

file 変更
src/types.ts DiffRecord / DiffFileStatus 追加、VectorMetadata に diff 用フィールドを optional 拡張(type union に "diff" を追加)
src/store.ts diffs テーブル(PK = repo, commit_sha, file_path)と CRUD + HTTP endpoint。resetForReEmbed にも diffs 含める
src/pipeline.ts generateEmbeddingBatch 追加。processAndUpsertCommitDiffMAX_EMBEDDING_BATCH_SIZE (=20) で chunk し batch embed → batch upsert → DO store 書き込み。Vector ID = {repo}#commit-{sha}#file-{base64url(path)}。binary / oversized で patch が無い file は skip
src/webhook.ts handlePushEvent の既存 .md 処理を無改造のまま、同じ commits[] iterate に fetchCommitDetailprocessAndUpsertCommitDiff を並行追加。1 commit 失敗は他に波及しない
src/mcp.ts search_issuestype enum に "diff" を追加、description 更新、結果 URL は commit page、タイトルは "{short-sha} {file_path}"list_recent_activity にも diff 追加
docs/0-requirements(.ja).md 新 retrieval surface を反映(ja/en 両方)

設計選択

  • batch embed fallback: 1 commit が 20 files を超える場合は複数 batch call に分割。各 chunk の失敗は他 chunk に波及しない(失敗 count を返却)。
  • truncation: 既存 MAX_EMBEDDING_INPUT_CHARS (=8000) を流用。embedding input は commit message + "\n\n" + file path + "\n\n" + patch の先頭 8000 文字。
  • file_path を input に含める: patch 本体のみだと削除 commit で - 行に path が出ない場合があるため、意図的に file path を input に inline する。
  • Vector ID の base64url encode: file path に / が含まれるため、+/=-_ + 空に replace(RFC 4648 §5 相当)。
  • 既存 .md surface を保持: type: "doc" live index は完全に無改造。diff は type: "diff" で別 scope。

本 PR 対象外(issue 本文の決定通り)

  • 歴史 commit backfill(poller 拡張)
  • per-hunk chunking
  • cost 実測+閾値自動調整
  • 独立の search_diff MCP tool(search_issuestype: "diff" filter で足りる想定)

検証

  • npx tsc --noEmit で型チェック通過。
  • npx wrangler deploy --dry-run で bundle success(Total Upload 2142 KiB / gzip 365 KiB)。

関連

…tors

commit diff を retrieval surface として追加する。push webhook の commits[] を
iterate し、各 commit について GET /repos/{repo}/commits/{sha} で per-file patch を
取得、1 commit × N files を batch embedding(Workers AI `text: string[]`)で 1 call に
まとめて N vector として Vectorize に upsert する。Option 2b 採択。

- types.ts: DiffRecord / DiffFileStatus を追加、VectorMetadata の type union に
  "diff" と commit_sha/file_path/file_status/commit_date/commit_author/
  blob_sha_before/blob_sha_after フィールドを optional で拡張。
- store.ts: diffs テーブル(PK = repo, commit_sha, file_path)と CRUD + HTTP
  endpoint を追加。resetForReEmbed にも diffs を含める。
- pipeline.ts: generateEmbeddingBatch を新設し batch embed を提供。
  processAndUpsertCommitDiff は MAX_EMBEDDING_BATCH_SIZE (=20) で chunk し、
  chunk ごとに batch embed -> batch upsert -> DO store 書き込みを行う。
  Vector ID = "{repo}#commit-{sha}#file-{base64url(path)}"。binary や
  oversized で patch が無い file は skip。
- webhook.ts: handlePushEvent の既存 .md 処理を無改造のまま、同じ commits[]
  iterate で fetchCommitDetail -> processAndUpsertCommitDiff を並行呼出し。
  1 commit の失敗は他 commit に波及しない。
- mcp.ts: search_issues の type enum に "diff" を追加、diff 結果の URL は
  commit page に組み立て、タイトルは "{short-sha} {file_path}"。
  list_recent_activity にも commit diff activity を追加。
- docs/0-requirements: .ja.md / .md の両方で新 retrieval surface を反映。

削除済みファイル・非 .md 拡張子の判断履歴が semantic で引けるようになる。
2026-04-19 に `momeri.pal`(削除済み)を引けなかった事例が契機。

本 PR 対象外: 歴史 commit backfill、per-hunk chunking、cost 自動調整、独立 MCP tool。

Closes #80

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@liplus-lin-lay liplus-lin-lay linked an issue Apr 19, 2026 that may be closed by this pull request
@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 2958063 Apr 19 2026, 06:07 AM

@liplus-lin-lay
liplus-lin-lay merged commit b220647 into main Apr 19, 2026
3 checks passed
@liplus-lin-lay
liplus-lin-lay deleted the 80-enhancement-index-commit-diffs-for-judgment-history-retrieval branch April 19, 2026 06:11
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.

enhancement: index commit diffs for judgment-history retrieval

1 participant