Repository navigation
feat(embeddings): optional in-process backends — static (Model2Vec) and fastembed (ONNX) [draft] - #5
Merged
Conversation
…nd fastembed (ONNX) Spike from the July 2026 session, committed as-is for review. ENGRAM_EMBED_BACKEND selects the embedder explicitly: `static` (Model2Vec dictionary embeddings, numpy-only), `fastembed` (quantized ONNX via onnxruntime, ~10–50 ms), or `ollama` / `openai` / `disabled` to pin the existing URL-derived backends. The two new backends are optional extras (`[static]`, `[fastembed]`); the core install is unchanged, and a missing dependency degrades to the existing path instead of failing. Includes benchmarks/embed_backend_bench.py — an A/B harness that runs each backend in its own scratch DB, since a static query vector is not comparable to a nomic-768 document vector — and dep-free tests for backend selection, graceful degradation, and the encode round-trip via an injected fake model. Reported by the spike session (not re-run here): LongMemEval R@5 vs nomic — static ≈ −2 pts, fastembed ≈ +10 pts. Verified before commit: Cloak 0 errors (99 annotation warnings), ruff clean, tests in both touched test files pass on a scratch DB with ENGRAM_EMBED_URL=disabled. Based on ca2c380 (2026-07-20); needs a rebase onto main (src/embeddings.py MRL truncation, src/database.py v27/v28). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
luiscota99
marked this pull request as ready for review
October 15, 2026 03:59
…installed CI's pyright step runs without model2vec/fastembed/numpy, so the lazy imports were unresolved and the lazily loaded model, typed `object`, had no `.encode`/`.embed`. Type the model registry and loader as `Any` and mark the three optional imports `pyright: ignore[reportMissingImports]`. Behaviour unchanged; ruff, pyright (0 errors), Cloak (0/0) and the embedding tests pass locally. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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
Commits the July 2026 embedding-backend spike that was sitting uncommitted in a worktree, now merged with current
main.ENGRAM_EMBED_BACKENDselects the embedder explicitly:static(Model2Vec, numpy-only),fastembed(quantized ONNX via onnxruntime), orollama/openai/disabledto pin the existing URL-derived backends.[static],[fastembed]). Core install unchanged; a missing dependency degrades to the existing path.benchmarks/embed_backend_bench.py: A/B harness, one scratch DB per backend (static query vectors are not comparable to nomic-768 document vectors).tests/test_embed_backends.py: dependency-free tests for selection, degradation, and the encode round-trip via an injected fake model.Reported by the spike session, not re-run for this PR: LongMemEval R@5 vs nomic was about −2 points for static and about +10 for fastembed.
Decision
Keep both backends (Luis, 2026-10-14). Relation to ADR-0009 (accepted): in remote mode the embedder runs on the VM, so these backends do not buy hook latency; fastembed's quality gain is the server-side argument, alongside the spec's Gemini option.
Verification
src,tests,benchmarksafter merging mainorigin/maininto the branch (d88e367), no conflicts2ac17ec(CI's first two runs failed in the pyright step because the optional extras are not installed there; the model registry is now typedAnyand the three lazy imports carrypyright: ignore[reportMissingImports])model2vec/fastembedinstalled and an Ollama nomic baseline)🤖 Generated with Claude Code