Repository navigation
feat: OpenAI + Ollama embedding backends (#337) - #376
Merged
Merged
Conversation
Three backends now supported via [embedding] backend config: - onnx (default, fully offline, EmbeddingGemma Q4 768d) - openai (text-embedding-3-small 1536d default, Azure-compatible) - ollama (nomic-embed-text 768d default, local server) New files: - crates/uteke-core/src/embed/openai.rs (OpenAiEmbedder + 5 tests) - crates/uteke-core/src/embed/ollama.rs (OllamaEmbedder + 5 tests) Core changes (uteke-core): - EmbedderEnv resolver reads backend config from env vars without pulling the CLI config crate into core. - ensure_embedder() dispatch now constructs OpenAI/Ollama backends with defaults when model/base_url/dims are empty. - Dim mismatch detection: if backend dims != index dims on first embed call, return a clear Validation error pointing at 'uteke repair' instead of silently producing garbage vectors. - VectorIndex::dims() exposed (wraps usearch Index::dimensions()). - reqwest 0.12 gains 'json' feature (always included, no feature flag). CLI config changes (uteke-cli): - EmbeddingConfig extended: api_key, base_url, dims. - SUPPORTED_BACKENDS now [onnx, openai, ollama]. - merge_from_file handles the 3 new fields. - apply_env_overrides handles UTEKE_EMBEDDING_BACKEND/MODEL/API_KEY/ BASE_URL/DIMS. API key falls back to OPENAI_API_KEY. - +6 new config tests (full openai merge, env precedence, fallback, invalid dims). Docs: - configuration.md: expanded Embedding Backend section with backend-specific defaults table, Azure OpenAI recipe, and a dim mismatch error example. Env var table extended with the 5 new UTEKE_EMBEDDING_* vars. - CHANGELOG entry. Acceptance criteria (from issue #337): [x] OpenAiEmbedder implements Embedder trait with HTTP call [x] OllamaEmbedder implements Embedder trait with HTTP call [x] Config [embedding] backend/api_key/base_url/model/dims supported [x] Env vars override config (UTEKE_EMBEDDING_*) [x] ONNX remains default (backward compatible) [x] Dim mismatch detection with clear error message [x] reqwest always included (no feature flags) [x] Documentation updated (configuration.md) [x] Tests for backend selection logic 212 tests pass. Clippy clean. cargo fmt clean. Closes #337.
🔍 Cora AI Code Review❌ Blocked — critical issues found. 🔴 Error (6)
Review powered by cora-cli · BYOK · MIT |
CodeCora found that lazy backend dispatch read only env vars via
EmbedderEnv::resolve, silently ignoring [embedding] api_key/base_url/
model/dims from uteke.toml. Users who set those in config (without env
vars) would see backend defaults used instead.
Fix:
- Replace EmbedderEnv with a public EmbeddingSettings struct + a
resolve_with_defaults() helper that layers env vars on top of
caller-supplied config values.
- Add Uteke::open_with_embedding() constructor that takes the merged
CLI config as EmbeddingSettings. Stored on the Uteke struct so
ensure_embedder() can read it at lazy-init time.
- finish_open() gains the embedding_settings param. All other
constructors forward EmbeddingSettings::default() (no behavior change
for library users who don't supply settings).
- VectorIndex::dims() exposed for dim-mismatch detection.
- CLI main.rs now calls open_with_embedding() and forwards
config.embedding.{api_key,base_url,model,dims} from uteke.toml.
+3 core regression tests covering: defaults-empty, env-overrides-config,
config-only-when-env-absent. Ensures the plumbing precedence
(env > uteke.toml > backend default) is locked in.
215 tests pass. Clippy clean. cargo fmt clean.
, #147, #155) Two real issues from review: 1. base_url validation (#155): OpenAiEmbedder/OllamaEmbedder stored base_url verbatim and only failed later during the HTTP call. Add crate::embed::validate_base_url() — rejects empty, schemeless, or unparseable URLs at construction time so callers see a clear Validation error instead of a confusing 404 later. Called from both OpenAiEmbedder::new and OllamaEmbedder::new. 2. Dimensions param (#146): OpenAiEmbedder accepted a dims field but never sent it in the request body. A user who set dims=3072 with a model defaulting to 1536 would silently get 1536d vectors from the API while the index believed it was 3072d. Now we include 'dimensions: N' in the request JSON when dims > 0. text-embedding-3-* honor this field; older models ignore unknown fields so this is safe to send unconditionally. Docs: - configuration.md Azure OpenAI example had an unclosed quote (#156). Fixed. Tests: +1 (rejects_invalid_base_url) covering schemeless, empty, and unparseable URLs. 187 core tests pass. Clippy clean. fmt clean.
CodeCora finding #154: the dim-mismatch guard blocked any embed-based operation once a user switched backends on an existing store, including 'uteke repair' which is the recovery path. Chicken-and-egg. Fix: skip the check when UTEKE_ALLOW_DIM_MISMATCH=1 is set. The error message now points at this flag directly: 'Rebuild the index (UTEKE_ALLOW_DIM_MISMATCH=1 uteke repair) or switch backend.' Docs: configuration.md dim-mismatch section shows the exact recovery incantation. 187 core tests pass. Clippy clean. fmt clean.
CodeCora finding: std::env::var returns Ok("") for explicitly empty
variables, so setting UTEKE_EMBEDDING_API_KEY="" would silently
overwrite a non-empty api_key from [embedding] in uteke.toml.
Fix: in both lib.rs::EmbeddingSettings::resolve_with_defaults and
cli/config.rs::apply_env_overrides, empty env-var values are now
filtered out via .filter(|v| !v.is_empty()) before falling through to
the config-provided value.
Docs: the Azure OpenAI example now includes the required api-version
query param (?api-version=2024-10-21) since Azure rejects requests
without it.
+1 core regression test (empty env does not overwrite config).
188 core tests pass. Clippy clean. fmt clean.
ajianaz
added a commit
that referenced
this pull request
Aug 13, 2026
* feat: OpenAI + Ollama embedding backends (#337) Three backends now supported via [embedding] backend config: - onnx (default, fully offline, EmbeddingGemma Q4 768d) - openai (text-embedding-3-small 1536d default, Azure-compatible) - ollama (nomic-embed-text 768d default, local server) New files: - crates/uteke-core/src/embed/openai.rs (OpenAiEmbedder + 5 tests) - crates/uteke-core/src/embed/ollama.rs (OllamaEmbedder + 5 tests) Core changes (uteke-core): - EmbedderEnv resolver reads backend config from env vars without pulling the CLI config crate into core. - ensure_embedder() dispatch now constructs OpenAI/Ollama backends with defaults when model/base_url/dims are empty. - Dim mismatch detection: if backend dims != index dims on first embed call, return a clear Validation error pointing at 'uteke repair' instead of silently producing garbage vectors. - VectorIndex::dims() exposed (wraps usearch Index::dimensions()). - reqwest 0.12 gains 'json' feature (always included, no feature flag). CLI config changes (uteke-cli): - EmbeddingConfig extended: api_key, base_url, dims. - SUPPORTED_BACKENDS now [onnx, openai, ollama]. - merge_from_file handles the 3 new fields. - apply_env_overrides handles UTEKE_EMBEDDING_BACKEND/MODEL/API_KEY/ BASE_URL/DIMS. API key falls back to OPENAI_API_KEY. - +6 new config tests (full openai merge, env precedence, fallback, invalid dims). Docs: - configuration.md: expanded Embedding Backend section with backend-specific defaults table, Azure OpenAI recipe, and a dim mismatch error example. Env var table extended with the 5 new UTEKE_EMBEDDING_* vars. - CHANGELOG entry. Acceptance criteria (from issue #337): [x] OpenAiEmbedder implements Embedder trait with HTTP call [x] OllamaEmbedder implements Embedder trait with HTTP call [x] Config [embedding] backend/api_key/base_url/model/dims supported [x] Env vars override config (UTEKE_EMBEDDING_*) [x] ONNX remains default (backward compatible) [x] Dim mismatch detection with clear error message [x] reqwest always included (no feature flags) [x] Documentation updated (configuration.md) [x] Tests for backend selection logic 212 tests pass. Clippy clean. cargo fmt clean. Closes #337. * fix(embedding): plumb uteke.toml settings into backend dispatch CodeCora found that lazy backend dispatch read only env vars via EmbedderEnv::resolve, silently ignoring [embedding] api_key/base_url/ model/dims from uteke.toml. Users who set those in config (without env vars) would see backend defaults used instead. Fix: - Replace EmbedderEnv with a public EmbeddingSettings struct + a resolve_with_defaults() helper that layers env vars on top of caller-supplied config values. - Add Uteke::open_with_embedding() constructor that takes the merged CLI config as EmbeddingSettings. Stored on the Uteke struct so ensure_embedder() can read it at lazy-init time. - finish_open() gains the embedding_settings param. All other constructors forward EmbeddingSettings::default() (no behavior change for library users who don't supply settings). - VectorIndex::dims() exposed for dim-mismatch detection. - CLI main.rs now calls open_with_embedding() and forwards config.embedding.{api_key,base_url,model,dims} from uteke.toml. +3 core regression tests covering: defaults-empty, env-overrides-config, config-only-when-env-absent. Ensures the plumbing precedence (env > uteke.toml > backend default) is locked in. 215 tests pass. Clippy clean. cargo fmt clean. * fix(embedding): validate base_url + send dimensions param (CodeCora #146, #147, #155) Two real issues from review: 1. base_url validation (#155): OpenAiEmbedder/OllamaEmbedder stored base_url verbatim and only failed later during the HTTP call. Add crate::embed::validate_base_url() — rejects empty, schemeless, or unparseable URLs at construction time so callers see a clear Validation error instead of a confusing 404 later. Called from both OpenAiEmbedder::new and OllamaEmbedder::new. 2. Dimensions param (#146): OpenAiEmbedder accepted a dims field but never sent it in the request body. A user who set dims=3072 with a model defaulting to 1536 would silently get 1536d vectors from the API while the index believed it was 3072d. Now we include 'dimensions: N' in the request JSON when dims > 0. text-embedding-3-* honor this field; older models ignore unknown fields so this is safe to send unconditionally. Docs: - configuration.md Azure OpenAI example had an unclosed quote (#156). Fixed. Tests: +1 (rejects_invalid_base_url) covering schemeless, empty, and unparseable URLs. 187 core tests pass. Clippy clean. fmt clean. * fix(embedding): add UTEKE_ALLOW_DIM_MISMATCH escape hatch for repair CodeCora finding #154: the dim-mismatch guard blocked any embed-based operation once a user switched backends on an existing store, including 'uteke repair' which is the recovery path. Chicken-and-egg. Fix: skip the check when UTEKE_ALLOW_DIM_MISMATCH=1 is set. The error message now points at this flag directly: 'Rebuild the index (UTEKE_ALLOW_DIM_MISMATCH=1 uteke repair) or switch backend.' Docs: configuration.md dim-mismatch section shows the exact recovery incantation. 187 core tests pass. Clippy clean. fmt clean. * fix(embedding): treat empty env vars as unset + Azure api-version doc CodeCora finding: std::env::var returns Ok("") for explicitly empty variables, so setting UTEKE_EMBEDDING_API_KEY="" would silently overwrite a non-empty api_key from [embedding] in uteke.toml. Fix: in both lib.rs::EmbeddingSettings::resolve_with_defaults and cli/config.rs::apply_env_overrides, empty env-var values are now filtered out via .filter(|v| !v.is_empty()) before falling through to the config-provided value. Docs: the Azure OpenAI example now includes the required api-version query param (?api-version=2024-10-21) since Azure rejects requests without it. +1 core regression test (empty env does not overwrite config). 188 core tests pass. Clippy clean. fmt clean.
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
Implements #337 (priority: high). Three embedding backends now supported via
[embedding] backend:onnx(default, fully offline, EmbeddingGemma Q4 768d) — unchanged.openai—text-embedding-3-small(1536d) default. Azure-compatible viabase_url.ollama—nomic-embed-text(768d) default. Local server onhttp://localhost:11434.New files
crates/uteke-core/src/embed/openai.rs—OpenAiEmbedder+ 5 unit testscrates/uteke-core/src/embed/ollama.rs—OllamaEmbedder+ 5 unit testsCore changes (
uteke-core)EmbedderEnvresolver in lib.rs reads backend config from env vars without pulling the CLI config crate into core.ensure_embedder()dispatch now constructs OpenAI/Ollama backends with backend-specific defaults whenmodel/base_url/dimsare empty.Validationerror pointing atuteke repairinstead of silently producing garbage vectors:VectorIndex::dims()exposed (wrapsusearch Index::dimensions()).reqwest0.12 gainsjsonfeature — always included, no feature flag.CLI config changes (
uteke-cli)EmbeddingConfigextended:api_key,base_url,dims.SUPPORTED_BACKENDSnow[onnx, openai, ollama].merge_from_filehandles the 3 new fields.apply_env_overrideshandlesUTEKE_EMBEDDING_BACKEND/MODEL/API_KEY/BASE_URL/DIMS. API key falls back toOPENAI_API_KEY.Docs
configuration.md: expanded Embedding Backend section with:UTEKE_EMBEDDING_*vars.Backend defaults
onnxembeddinggemma-q4openaitext-embedding-3-smallhttps://api.openai.com/v1ollamanomic-embed-texthttp://localhost:11434Acceptance criteria (from issue #337)
OpenAiEmbedderimplementsEmbeddertrait with HTTP callOllamaEmbedderimplementsEmbeddertrait with HTTP call[embedding] backend/api_key/base_url/model/dimssupportedUTEKE_EMBEDDING_*)reqwestalways included (no feature flags)configuration.md)Verification
cargo build --workspace— cleancargo clippy --workspace --all-targets -- -D warnings— cleancargo fmt --all -- --check— cleancargo test --workspace— 212 pass (29 CLI + 183 core), 0 failCompetitive impact (per issue)
Notes
Error::genericwith HTTP status + body for debugging.Closes #337