Skip to content

feat(embeddings): optional in-process backends — static (Model2Vec) and fastembed (ONNX) [draft] - #5

Merged
luiscota99 merged 3 commits into
mainfrom
feat/embed-backends-static-fastembed
Oct 15, 2026
Merged

luiscota99 merged 3 commits into
mainfrom
feat/embed-backends-static-fastembed

Conversation

@luiscota99

@luiscota99 luiscota99 commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Commits the July 2026 embedding-backend spike that was sitting uncommitted in a worktree, now merged with current main.

  • ENGRAM_EMBED_BACKEND selects the embedder explicitly: static (Model2Vec, numpy-only), fastembed (quantized ONNX via onnxruntime), or ollama / openai / disabled to pin the existing URL-derived backends.
  • Both new backends are optional extras ([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

  • Cloak: 0 errors, 99 warnings (CLK-PY005 annotations, mostly test functions)
  • ruff clean on src, tests, benchmarks after merging main
  • Merged origin/main into the branch (d88e367), no conflicts
  • Full suite on the merged branch against a scratch DB: 1444 passed, 315 warnings in 120.82s, exit 0
  • pyright: 0 errors after 2ac17ec (CI's first two runs failed in the pyright step because the optional extras are not installed there; the model registry is now typed Any and the three lazy imports carry pyright: ignore[reportMissingImports])
  • Re-run the A/B benchmark on main with the real models (needs model2vec / fastembed installed and an Ollama nomic baseline)

🤖 Generated with Claude Code

luiscota99 and others added 2 commits October 14, 2026 20:49
…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
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>
@luiscota99
luiscota99 merged commit 8f6b274 into main Oct 15, 2026
5 checks passed
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