codescout icon indicating copy to clipboard operation
codescout copied to clipboard

ONNX local-embed path does not support CodeRankEmbed — blocks migration off the llama-server container

Open mic-urs opened this issue 3 months ago • 3 comments

Follow-up to #15 (dense embedder slot-context issue). You suggested moving to the ONNX in-process path — I audited the current code and found two blockers for hosts already running CodeRankEmbed over HTTP.

Blocker 1: no CodeRankEmbed on the ONNX path

Verified against crates/codescout-embed/src/local.rs + lib.rs on current experiments:

  • local-dir: is hardcoded to AllMiniLM-L6-v2-Q (384-dim) — LocalEmbedder::from_dir assumes that model's tokenizer/pooling/quantization regardless of directory contents (the in-code comment documents this, including the "plausible but silently wrong vectors" risk if another model's weights sit in the directory).
  • local: resolves through fastembed's registry: AllMiniLM-L6 (384d), NomicEmbedTextV15(Q) (768d), JinaEmbeddingsV2BaseCode (768d), BGE-small (512d). CodeRankEmbed is not there.

Consequence: an existing CodeRankEmbed (768-dim) deployment switching to ONNX today must change the embedding model entirely → all stored vectors become incompatible → full reindex of every code index and every memory, plus an unmeasured retrieval-quality regression (CodeRankEmbed Q4_K_M was the benchmark champion on the legacy-natural bench per the compose comments).

Since CodeRankEmbed derives from nomic-embed-text-v1.5 (already in fastembed's registry as NomicEmbedTextV15), is a generic from_dir / user-defined-model path planned — i.e. load CodeRankEmbed ONNX weights from a local directory with explicit pooling/quantization params? That would make the ONNX migration vector-compatible (same model, same dim, no reindex).

Blocker 2: hybrid sparse leg refuses local backends

guard_sparse (per commit 9a62a4a6) errors when a local backend is selected while the sparse leg is configured. Hosts currently running hybrid dense+sparse over HTTP must either drop sparse (unmeasured retrieval change) or stay on the container. Is dense-only the intended end-state for the local path, or is hybrid-with-local-backend on the roadmap?

Suggestion

Even a short note in the retrieval-stack docs — "ONNX local path currently implies: model change + full reindex + dense-only" — would save others from discovering this by audit.

Environment: codescout experiments (build 2026-08-19), sqlite-vec backend, dense = CodeRankEmbed-Q4_K_M via llama-server, sparse + reranker active.

mic-urs avatar Aug 20 '26 10:08 mic-urs

Leaving this open, because the honest answer is that your audit was correct on both blockers, only the documentation was fixed, and your two actual questions have not been answered.

What shipped: 652589fa (patch-id 14e7e21a09c938934c689ac260a08a4eba622628) — the retrieval-stack docs now say outright that "the ONNX path currently implies a model change, a full reindex of every code index and every memory, and dense-only retrieval," and that local:<name> resolves a fixed allowlist which does not include CodeRankEmbed. That is the short note you suggested, and it was the right thing to do first — but it documents the cost rather than removing it.

Both blockers are still present in code, and are intentional:

  • Blocker 1a — parse_model has exactly seven arms (NomicEmbedTextV15, …V15Q, JinaEmbeddingsV2BaseCode, BGESmallENV15Q, AllMiniLML6V2Q, BGESmallENV15, AllMiniLML6V2) and bails with a self-documenting list otherwise. No CodeRankEmbed.
  • Blocker 1b — from_dir_blocking builds its UserDefinedEmbeddingModel from module constants (Pooling::Mean, QuantizationMode::Dynamic, output_key: None) regardless of directory contents. Your read is exact, including the consequence: dims are probed from the model, so a wrong-model directory yields a plausible, wrong vector rather than an error. The in-code comment says so.
  • Blocker 2 — guard_sparse is unchanged; it refuses a local backend while the sparse leg is configured, naming both remedies.

Your two questions, answered as straightforwardly as I can:

is a generic from_dir / user-defined-model path planned?

Not currently. There is no tracker, plan, or roadmap entry for it — I checked, and that absence is the real status rather than a deferral. If it is built, the seam is LocalEmbedder::from_dir_blocking taking pooling/quantization/output_key from a caller-supplied spec or a sidecar — plus chunk_size_for_model's local-dir: arm, which currently hardcodes delegation to local:AllMiniLML6V2Q. Those two must move together or the token budget silently mismatches the model, which would reintroduce the class of bug #15 was about.

is hybrid-with-local-backend on the roadmap?

Also not currently, and also unrecorded.

So: dense-only is the de facto end state of the local path today, not a declared one. Keeping this issue open as the place those two decisions live, since closing it would file them nowhere.

mareurs avatar Sep 15 '26 08:09 mareurs

Heads-up on a commit you may see and misread, since it points the opposite way to this issue.

cargo rb — the Linux dev-box alias in .cargo/config.toml — no longer builds local-embed. It is now build --release --features server-stack (a73415fc). This host configures its embedder entirely over HTTP (llama-server / CodeRankEmbed), so nothing here ever resolved a local: or local-dir: model, and the feature was costing ~21 MB of binary and the ort/fastembed compile on every live rebuild. Measured 62 MB → 40 MB.

This is not a step away from the ONNX path, and I want to be explicit because the commit alone could read that way:

  • The local-embed feature is untouched in Cargo.toml.
  • It still has CI lanes on all three platforms, plus the gate's clippy --features local-embed, plus every_declared_feature_has_a_lane_or_a_reason in tests/feature_lanes.rs, which reds the build if any declared feature silently loses its lane.
  • docs/manual/src/concepts/retrieval-stack.md continues to document the path.

What actually changed is one developer's build command. Three surfaces already described cargo rb as server-stack only — the command-reference memory, the manual (cargo rb --features local-embed, i.e. add it), and ci.yml:385, which quotes the alias verbatim. The alias was the outlier; this converged it.

The alias comment now says in as many words that the feature must not be deleted, and cites this issue as the reason:

the feature itself is untouched in Cargo.toml and still has CI lanes on all three platforms plus the gate's clippy — this changes one build command, not the project's support for the ONNX path (GitHub #16 is open and wants that path extended, so do not delete the feature)

The two questions in my earlier reply are still open and still unrecorded in any tracker or roadmap: a generic from_dir / user-defined-model path, and hybrid-with-local-backend. This issue remains the only place they live.

mareurs avatar Sep 15 '26 13:09 mareurs

Correcting my own reply above. I told you both of your questions were unplanned and unrecorded. That was wrong on both counts, and the real answers are better than the ones I gave you.

What I did: searched docs/trackers/ and ROADMAP.md, found nothing, and published that as a claim about the project. The design lives in docs/superpowers/specs/2026-08-11-local-onnx-embedding-query-path-design.md — status active — which that search never reached. The value was right for the corpus I looked at and I reported it as a fact about the codebase. Apologies: "nobody has considered this" is the one answer that tells a reporter to stop looking, and it is the answer I gave you.

Blocker 2 is a decided design, not a de facto outcome

I wrote that dense-only is "the de facto end state of the local path today, not a declared one." It is declared. § Architecture:

Local implies dense-only. A local ONNX backend produces no sparse vector. Selecting one sets dense_only, a third reason beside lite and disable_sparse. server-stack compiled in and sparse expected and a local backend selected is an error, not a downgrade.

The guard_sparse refusal you hit is that sentence being enforced. § Error handling specifies it as RecoverableError — "an operator-fixable config conflict, not a bug" — required to name both remedies, and Testing row 7 pins the behaviour.

So the answer to "is dense-only the intended end-state?" is yes, deliberately, and the reasoning is that a silent hybrid downgrade would surface as degraded recall rather than as a failure. That is a defensible position you can now argue with, which is what I owed you instead of a shrug.

Blocker 1: the seam is not just planned, the architecture was built around it

Your read of the code was exact — from_dir_blocking uses module constants regardless of directory contents, and dims are probed, so a wrong-model directory yields a plausible wrong vector. All still true. What I missed is that the design anticipated the extension:

  • Component 1 specifies from_dir loading "via fastembed's try_new_from_user_defined" — the user-defined mechanism is the one already in use.
  • § Decision lists "add a second weights source" among the change scenarios absorbed by the chosen boundary.
  • § Decision's Revisit-when trigger reads: "librarian needs directory-loaded weights (then local-dir: belongs in its documented grammar too)."

What genuinely is not delivered is a caller-supplied pooling / quantization / output_key spec. Testing row 2 pins a 384-d vector and the § Goal names AllMiniLM, and that is what scopes the design — not an oversight about other models. Your CodeRankEmbed case is precisely the second weights source the architecture says it absorbs, and nobody has written the spec-passing layer.

What changed as a result

Both questions are now in that spec's § Deferred, whose stated purpose is "listed as deferred, not absent, so the next person does not rediscover it expensively" — which is exactly what you had to do by audit. Recorded with the constraint I flagged earlier: from_dir_blocking's constants and chunk_size_for_model's local-dir: arm (hardcoded to local:AllMiniLML6V2Q) must move together, or the token budget silently mismatches the model and reintroduces the class #15 was about.

Still open, and still the right place for these two decisions. Your audit has been correct at every step; the gap was in what I could find, not in what you reported.

mareurs avatar Sep 16 '26 06:09 mareurs