Skip to content

perf(ai): CCIPベクトルをチャンク単位でbulk upsert - #570

Merged
hmjn023 merged 1 commit into
developfrom
feat/ccip-batch-script
Jul 4, 2026
Merged

perf(ai): CCIPベクトルをチャンク単位でbulk upsert#570
hmjn023 merged 1 commit into
developfrom
feat/ccip-batch-script

Conversation

@hmjn023

@hmjn023 hmjn023 commented Jul 4, 2026

Copy link
Copy Markdown
Owner

概要

CCIPバッチスクリプトのLanceDB保存を、1件ごとのdelete/addからチャンク単位のmerge insertへ変更します。

変更内容

  • ICcipVectorStoreへupsertManyを追加
  • LanceDBのmediaId merge insertで複数vectorを一括更新
  • CcipVectorServiceへextractBatchを追加し、成功した推論結果をまとめて保存
  • バッチスクリプトをextractBatch利用へ変更
  • service unit testとLanceDB実体でinsert/updateを検証

検証

  • Biome check
  • server/application typecheck
  • CcipVectorService unit test: 3件成功
  • LanceDB実体で2件insert後の同一mediaId更新を確認

関連Issue

Summary by CodeRabbit

  • 新機能
    • 複数メディアの抽出処理をまとめて実行できるようになり、処理効率が向上しました。
  • バグ修正
    • 既存データの更新方法を改善し、重複や不要な削除を避けて安定した保存ができるようになりました。
    • 取得済みデータの状態確認や検索時の判定を整理し、より一貫した動作になりました。
  • テスト
    • 一括処理と保存の動作を検証するテストを強化しました。

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 29e6c7b8-3cae-49f2-914f-3616be7dbc16

📥 Commits

Reviewing files that changed from the base of the PR and between 62ab604 and ae198d1.

📒 Files selected for processing (5)
  • apps/server/scripts/extract-ccip-batch.ts
  • apps/server/src/infrastructure/ai/lancedb-ccip-vector-store.ts
  • apps/server/src/tests/unit/application/services/ccip-vector-service.test.ts
  • packages/application/src/ports/ccip-vector-store.ts
  • packages/application/src/services/ccip-vector-service.ts

📝 Walkthrough

Walkthrough

CCIPベクトルストアに upsertMany バルクupsertメソッドが追加され、LanceDB実装ではmergeInsertベースのupsert/upsertMany処理に置き換えられた。CcipVectorService の抽出・永続化フローが再構成され、バッチ抽出スクリプトが個別呼び出しから一括呼び出しに変更された。関連ユニットテストも更新・追加された。

Changes

CCIPベクトルのバルクupsert化

Layer / File(s) Summary
upsertMany インターフェース契約
packages/application/src/ports/ccip-vector-store.ts
ICcipVectorStoreupsertMany(records: CcipVectorRecord[]): Promise<void> メソッドが追加された。
LanceDBストアの upsert/upsertMany 実装
apps/server/src/infrastructure/ai/lancedb-ccip-vector-store.ts
upsertupsertMany([record]) への委譲に変更され、upsertManymergeInsert("mediaId") による whenMatchedUpdateAll/whenNotMatchedInsertAll で一括upsertを行う。
CcipVectorService の抽出/永続化フロー変更
packages/application/src/services/ccip-vector-service.ts
prepareExtraction は upsert を行わずレコード判定のみ返し、extract/extractBatch が呼び出し側でそれぞれ単体upsert/バルクupsertを実行。searchSimilar の鮮度判定条件と isCurrent の引数整形も併せて変更。
バッチ抽出スクリプトの呼び出し変更
apps/server/scripts/extract-ccip-batch.ts
各メディアごとの Promise.allSettled + extract 個別呼び出しから、extractBatch へのメディアID配列一括呼び出しに変更。
関連ユニットテストの更新
apps/server/src/tests/unit/application/services/ccip-vector-service.test.ts
ベクトル初期化を Array.from に統一し、extractBatchupsertMany を一度だけ呼び出すことを検証する新規テストを追加。

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Script as extract-ccip-batch
  participant CcipVectorService
  participant TaggingService
  participant LanceDbCcipVectorStore

  Script->>CcipVectorService: extractBatch(sourceId, mediaIds, forceReextract)
  loop 各mediaId
    CcipVectorService->>TaggingService: getCcipFeatureForMedia
    CcipVectorService->>CcipVectorService: prepareExtraction (record作成/判定)
  end
  CcipVectorService->>CcipVectorService: skippedを除外しrecordsを集約
  CcipVectorService->>LanceDbCcipVectorStore: upsertMany(records)
  LanceDbCcipVectorStore-->>CcipVectorService: 完了
  CcipVectorService-->>Script: fulfilled/rejected結果一覧
Loading

Possibly related PRs

  • hmjn023/solid-imager#556: CCIPベクトルストア/サービスとバッチ抽出インフラを導入したPRであり、本PRのextract-ccip-batch.tsCcipVectorService.extractBatchLanceDbCcipVectorStoreのupsert/upsertMany変更と直接関連する。
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed CCIPベクトルをチャンク単位でまとめてupsertする変更を的確に表しており、主な変更内容と一致しています。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/ccip-batch-script

Comment @coderabbitai help to get the list of available commands.

@hmjn023
hmjn023 merged commit d312201 into develop Jul 4, 2026
1 check passed
@hmjn023
hmjn023 deleted the feat/ccip-batch-script branch July 4, 2026 05:24
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.

1 participant