feat(reference): Vector embedding 検索 MVP(Phase 4-E / Refs #191)#198
Merged
Conversation
SPEC #191 (Phase 4 umbrella) 最終サブタスク E を land する。 fastembed-rs (BGE-Small-EN, ONNX Runtime) で symbol 単位の embedding を生成し、線形 scan ベースの cosine 類似度検索で「Animator まわり で使うコールバック型」のような曖昧 query から関連シンボルを引ける ようにする。子 SPEC は作らず umbrella #191 に統合。 採用方針 (gwt-discussion で確定): - lib: fastembed-rs + 線形 scan (MVP, HNSW は後追い余地) - build timing: 明示的な `reference embed-build` - 対象: Phase 2 / 4-A の symbol index を再利用 (type / method / property) - model: fastembed-rs default (BAAI/bge-small-en-v1.5, ~130MB) 主な変更: - Cargo.toml: fastembed = "4", bincode = "1" を追加 - src/reference/embed.rs (新規): Embedder trait と FastEmbedder / MockEmbedder、symbol_to_text / build_embedding_index / save_embedding_index / load_embedding_index / search / cosine_similarity の純関数 + 9 件のテスト - src/reference/mod.rs: maybe_execute_reference_tool に reference_embed_build と reference_embed_search 分岐、 dispatcher 経由テスト 3 件 - src/cli.rs: ReferenceCommand::EmbedBuild / EmbedSearch variant - src/app/runner.rs::build_reference_call: 2 分岐と 4 件のテスト - src/tooling/tool_catalog.rs: 2 tool を TOOL_NAMES / executor / read_only (search のみ) / params_schema / parity count (127→129) に登録 - skill SKILL.md / references/embed-search-playbook.md (新規) / docs/tools.md: Reference Cache (9→11 tools) と embed-build / embed-search の使い分けを反映 設計上の意図的スコープアウト (umbrella #191 で継続管理): - 多言語 model (multilingual-e5-large) は --model オプションで後追い - HNSW / IVF ベースの ANN は線形 scan の後段に検討 - file-chunk 単位の embedding は別軸として後追い - score 正規化 / re-ranking は未対応 ONNX 実 model を呼ぶ部分は FastEmbedder で隔離し、test 内では MockEmbedder を用いるので CI で model download が発生しない。実 embed-search の動作確認は user の手元で `embed-build` を 1 度 走らせる前提。 ローカル検証: - cargo fmt -- --check: clean - cargo clippy --all-targets -- -D warnings: clean - cargo test --bin unity-cli: 408 passed / 0 failed - cargo llvm-cov --all-targets: TOTAL line coverage 90.67% - unity-cli skills lint --severity error: 15 skills / 0 violations Refs #191 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
vectors.into_iter() は既に IntoIterator なので冗長。zip(vectors) に 書き換え。 Refs #191 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
fastembed-rs(BGE-Small-EN, ONNX Runtime) で symbol 単位の embedding を生成し、線形 scan ベースの cosine 類似度検索で曖昧クエリから関連シンボルを引けるようにする。gwt-discussionで確定したスコープ: lib = fastembed-rs + 線形 scan / build = explicitreference embed-build/ 対象 = symbol unit (Phase 2 + 4-A index 再利用) / model =BAAI/bge-small-en-v1.5(~130MB)。Changes
Cargo.toml:fastembed = "4",bincode = "1"を[dependencies]に追加。fastembedは内部でort(ONNX Runtime) /hf-hub/tokenizersを pull する。src/reference/embed.rs(新規):Embeddertrait +FastEmbedder(ONNX 実装) + test 用MockEmbedderEmbeddedSymbol/EmbeddingIndexの serde 型symbol_to_text/build_embedding_index/save_embedding_index/load_embedding_index/search/cosine_similarityの純関数src/reference/mod.rs:execute_embed_build/execute_embed_searchを追加し、maybe_execute_reference_toolにreference_embed_build/reference_embed_search分岐を登録。dispatcher 経由テスト 3 件 (requiredquery/ cache missing / index missing)。src/cli.rs:ReferenceCommand::EmbedBuild { version }/EmbedSearch { query, version, top_k }variant。src/app/runner.rs::build_reference_call: 2 分岐 + 4 件のテスト。src/tooling/tool_catalog.rs: 2 tool をTOOL_NAMES/tool_executor::Local/is_read_only_tool(search のみ read_only、build は mutating) /tool_params_schema(required:query/ なし) / parity count (127→129) に登録。.claude-plugin/plugins/unity-cli/skills/unity-csharp-reference/SKILL.md:## Preferred Flowに embed-build / embed-search の使い分けを追記。.claude-plugin/plugins/unity-cli/skills/unity-csharp-reference/references/embed-search-playbook.md(新規): Phase 4-E の運用ガイド。docs/tools.md: Reference Cache (9 → 11 tools)、新 tool 行を追加。Testing
cargo fmt -- --check— cleancargo clippy --all-targets -- -D warnings— cleancargo test --bin unity-cli— 408 passed / 0 failed (embed 9 + dispatcher 3 + runner 4 を含む)cargo llvm-cov --all-targets --summary-only -- --test-threads=1— TOTAL line coverage 90.67%unity-cli skills lint --severity error— 15 skills / 0 violationsONNX 実 model を呼ぶ
FastEmbedderは test 内では使わず、MockEmbedderで純関数経路をカバーするため CI でモデル download は発生しない。Closing Issues
Refsのみ)Related Issues / Links
Checklist
MockEmbedderで ONNX を回避)cargo clippy,cargo fmt,unity-cli skills lint)references/embed-search-playbook.md/docs/tools.md).unity-cli-index/symbols.json(Phase 2) には触らず、embeddings.binを別ファイルとして追加する。先行 PR でもgitignore済みの.unity-cli-index/配下。feat)Context
Phase 2 / 4-A で構築した symbol index は名前完全一致の lookup なので、「Animator まわりで使うコールバック型」のような曖昧な要求には応えられなかった。本 PR で
reference embed-search --query "..."を提供し、LLM が自然言語クエリから関連シンボルを発見できるようにする。これで unity-csharp-reference の Phase 1-4 ロードマップ (umbrella #191 含む A/B/C/D/E) がすべて land する。Out of Scope (umbrella #191 で継続管理)
multilingual-e5-large, ~520MB) は--modelオプションで後追いNotes
fastembed = "4"依存追加で Cargo.lock が大きく増えた (+~2000 lines)。ort/hf-hub/tokenizersの解決による。target binary は ONNX Runtime の dynamic load 機構を使うため、起動時 model 読み込み以外のオーバーヘッドは限定的。embed-buildは数千 symbol 規模で数十秒〜数分。--top-kの既定値は 10。MockEmbedderは char コードを使った決定的なベクトルを返すだけの test double で、CI 環境で ONNX の有無に依存しない。