RFC: Optional local EmbeddingGemma 2 backend for semantic search
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 18/100
- Issue 类型
- 功能
- 描述清晰度
- 需要澄清
- 活跃度
- 活跃
调研方向
This is a design RFC, not a task: it asks maintainers whether an optional supervised Python worker and per-request embedding_model parameter fit the project's pure-C policy, and no code change is requested. Read the linked #1112 and CONTRIBUTING.md first, then the fork prototype at commit 6d10b2c7 to see the adapter scope. Done means a maintainer answers the two numbered questions and agrees on focused, reviewable increments.
由索引模型根据 Issue 内容生成。
描述
Written with AI assistance (Codex), on behalf of H4M4CHi-ttr.
Request for guidance before an upstream feature PR
I would like guidance on an optional local EmbeddingGemma 2 backend that callers explicitly select for search_graph semantic search. A prototype exists in my fork; I am asking about the integration boundary before proposing an upstream patch.
Related: #1112, including the maintainer's request to characterize a permissively licensed candidate and the independent companion-tool discussion. Those discussions do not establish approval for this adapter or parameter.
What problem does this solve?
CBM's existing semantic search uses bundled Nomic-derived vectors and native ranking. I want to evaluate retrieval from function/class source bodies for questions such as “Where are failed HTTP requests retried?”, including queries written in Japanese.
This is an evaluation goal, not a claim that Gemma improves retrieval quality or resolves the Spanish-language example in #1112. The model is google/embeddinggemma-2, pinned to revision 914f7f89142e33e77833254d9c9b90c3cef7303b; its model card specifies Apache 2.0.
Proposed solution and boundaries
The fork-only prototype is at 6d10b2c7. The provisional selector is embedding_model: "embeddinggemma-2", valid with semantic_query. Omitted or "default" selection preserves existing semantic search. Gemma uses its own index and cosine retrieval; this prototype does not fuse two models' results or scores.
- Inference uses an optional local Python/PyTorch worker. Transformer libraries and weights are not linked into the C binary, but the C adapter, build definition, and MCP schema do change.
- One supervised worker loads on the first explicit Gemma request and is reused within that MCP session. Separate sessions consume separate model memory. The adapter uses argument-vector spawning without a shell and owner-private, bounded JSON files; it adds no listening port.
- The worker is trusted code running with the same OS user's privileges, not an OS sandbox. It opens the native SQLite DB with
mode=roand writes a separate vector DB. Its dependence on the internal native schema needs an agreed integration contract. - After CBM's native watcher publishes changes, the next Gemma search refreshes an existing compatible index, reusing unchanged document vectors and atomically publishing the replacement DB. Initial indexing and profile/library upgrades remain explicit.
- Before/after source checks reject detected inconsistencies. Worker/CUDA failures are explicit errors, without silently selecting the default model or CPU. An editing agent must still reopen current source before modifying it.
Candidates are verified source-backed Function/Method/Class nodes. The fixed profile is text-only, FP32, 768 dimensions, L2 normalization, and a 4096-token limit including the document title/path; truncations are counted. Freshness checks add corpus-dependent I/O.
Configuration prepares the runtime; tool arguments select the model
Users first prepare a native CBM index, optional Python dependencies, cached weights, and an initial Gemma index for each target project. The first model download is allowed only through explicit indexing with --allow-download.
An MCP client's launch configuration can supply:
CBM_GEMMA2_PYTHON=/absolute/path/to/venv/python
CBM_GEMMA2_SCRIPT=/absolute/path/to/tools/embeddinggemma2.py
CBM_GEMMA2_DEVICE=cuda
CBM_GEMMA2_PRELOAD=0
With preload unset or 0, the first explicit Gemma search loads the model. With 1, cached weights load during MCP initialize, before its response; failure fails initialization. Preloading neither builds a project index nor changes the default model. These environment variables must be supplied before CBM starts.
Actual selection is per request:
{
"project": "example",
"semantic_query": ["Where are failed HTTP requests retried?"],
"embedding_model": "embeddinggemma-2",
"semantic_limit": 5
}
An agent can receive that instruction in a prompt or its project instructions; a direct MCP client can supply the argument programmatically. Standing instructions should apply only to projects with a prepared Gemma index, honor an explicit user request for the default model, report errors, and leave embedding_model off BM25-only or structural-only calls. Agent instructions encourage parameter use; the actual tool call is the evidence of selection. CBM does not interpret agent prompts/instruction files to choose a model.
The prototype has no environment/configuration switch for changing the default search model. Explicit selection exposes each project's index requirement and the additional inference cost to the caller.
Fresh verification of the feature-only commit
I rebuilt and reran verification on 6d10b2c7, without cherry-picking the separate Windows fix in #2639 and without changing the source tree.
Environment: Windows x64, MSYS2 CLANG64/Clang 23.1.3, Python 3.12.15, GTX 1070 Ti 8 GiB, driver 581.80, PyTorch 2.14.0+cu126/CUDA 12.6, sentence-transformers 6.1.0, transformers 5.19.0.
| Check | Result |
|---|---|
| Fresh production build | Passed; existing grammar duplicate-symbol warnings unchanged |
| ASan/UBSan C suites: semantic, mcp, watcher, daemon_application | 575 passed, 1 known Watcher fixture failure, 13 platform skips; all six added Gemma C tests passed |
| Python contract tests, using a fake encoder and no weight download | 18 passed |
| Changed-line clang-format, static security allowlist audit, DCO | Passed; one signed-off commit |
| Fresh CUDA index on a self-authored eight-function fixture | 8 indexed, 12 synthetic builtins excluded, 0 truncations; unchanged resume embedded 0 |
| Lazy and preload sessions | Six English/Japanese queries each, intended target first; same worker and one model load per session |
| Failure/lifecycle checks | Stale source refused; active worker crash failed that request, next request recovered; disconnect released workers |
| Actual Git Watcher + CUDA edit/add/delete | Embedded/reused 1/7, 1/8, 0/8; same model worker; pre-publication stale searches refused |
The one C failure is the unchanged watcher_stop_and_unwatch_cancel_blocked_git_without_backstop fixture: cbm_setenv("PATH", path, 1) returns EINVAL when its old narrow getenv reads the non-ASCII toolchain PATH. The same test binary passed that case with an ASCII process PATH and its ASan DLLs available. The native watcher/application/test files match the fork base; their UTF-8 fix remains separate in #2639. Real CUDA integration used ASCII local repository/cache paths.
A first MCP attempt under Windows' default Temp was refused by CBM's native private-directory check because ancestor ACLs grant mutation to sandbox users. A dedicated user-owned local cache succeeded; no global ACL or MCP settings were changed.
Re-executed source checks:
scripts/build.sh CC=clang CXX=clang++ BUILD_DIR=build/gemma-feature-only-prod-20261014
scripts/test.sh --suites semantic,mcp,watcher,daemon_application CC=clang CXX=clang++ BUILD_DIR=build/gemma-feature-only-tests-20261014
python tests/test_embeddinggemma2.py -v
scripts/security-audit.sh
scripts/check-dco.sh main..review/embeddinggemma-2
This is local integration evidence, not a blind quality benchmark, a full-suite/full-tree-lint pass, cross-platform validation, or established upstream CI coverage. No full-corpus adapter latency/quality claim is made. A matched evaluation still needs fixed repositories, queries and gold labels, declared candidate coverage, strong lexical/structural baselines, cold/warm latency, indexing/refresh costs, and resource measurements. English/Japanese results alone cannot resolve the Spanish use case.
Alternatives and questions
- Does an optional supervised local worker fit the pure-C and external-service policies, or should it remain an independent companion using existing public CLI/MCP outputs?
- If an adapter is acceptable in principle, is explicit per-request model selection with lazy loading/optional preload appropriate? The parameter name and schema integration are provisional.
The fork is an experimental reference, not a request to merge its full patch as-is. Any agreed upstream work would need focused, reviewable increments under CONTRIBUTING.md. I am not submitting an upstream Gemma PR with this RFC.
- I searched existing issues; this RFC focuses on the worker/API contract and links the broader capability request in #1112.
The prototype commit carries a human-approved DCO Signed-off-by.
- 主要语言
- C
- 星标
- 45.8k
- 派生
- 3.8k
- 平均合并
- 3 天 6 小时
- 30 天内合并 PR
- 201
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
DeusData/codebase-memory-mcp 的其他 Issue
-
Generated Pi extension (cbmem.ts) breaks Gemini/Antigravity: Type.Union of Type.Literal serializes to anyOf/const可能已有人在做 @divakantpandey 于 1 天前认领。 未关闭bug editor/integration
难度 2/5 1-3 小时 新手友好度 72/100
DeusData/codebase-memory-mcp#2787 · 1 条评论 ·
维护者通常 2 天内回复
-
editor/integration parsing/quality
难度 2/5 1-3 小时 新手友好度 68/100
DeusData/codebase-memory-mcp#2286 ·
维护者通常 2 天内回复
-
install writes an unsupported `args` key into the Claude Code SubagentStart hook, so it never runs未关闭bug editor/integration priority/high stability/performance ux/behavior
难度 2/5 1-3 小时 新手友好度 72/100
DeusData/codebase-memory-mcp#2239 · 1 条评论 ·
维护者通常 2 天内回复
-
bug priority/high ux/behavior
难度 2/5 1-3 小时 新手友好度 72/100
DeusData/codebase-memory-mcp#2232 · 2 条评论 ·
维护者通常 2 天内回复
-
documentation editor/integration parsing/quality priority/normal
难度 2/5 1-3 小时 新手友好度 85/100
DeusData/codebase-memory-mcp#2169 ·
维护者通常 2 天内回复
查看 DeusData/codebase-memory-mcp 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 65/100
JustAResearcher/gpu-unlock-ada#98 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
-
bug intrinsic medium priority rt_lib
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
espressif/esp-vision#18 ·