Skip to content

feat: OpenAI + Ollama embedding backends (reqwest, ONNX stays default) #337

Closed

Description

@ajianaz

Problem

Uteke only supports ONNX (EmbeddingGemma Q4) for embeddings. The Embedder trait exists but no alternative backends are implemented. Competitors (Mem0, Zep, Letta) all support OpenAI, Ollama, and custom backends.

Users who already use OpenAI or Ollama embeddings cannot migrate to uteke.

Design Decision

reqwest always included (not behind feature flag). ONNX remains default backend. Binary size increase is acceptable (~1-2MB from reqwest + TLS).

Proposed Solution

1. OpenAI Embedder (crates/uteke-core/src/embed/openai.rs)

pub struct OpenAiEmbedder {
    client: reqwest::blocking::Client,
    api_key: String,
    base_url: String,    // default: https://api.openai.com/v1
    model: String,       // default: text-embedding-3-small
    dims: usize,         // 1536 for small, 3072 for large
}

impl Embedder for OpenAiEmbedder {
    fn embed(&self, text: &str) -> Result<Vec<f32>, Error> {
        // POST {base_url}/embeddings
        // Body: { "model": "{model}", "input": "{text}" }
        // Parse response: data[0].embedding
    }
    fn dims(&self) -> usize { self.dims }
    fn max_seq_len(&self) -> usize { 8191 }
    fn name(&self) -> &str { "openai" }
}

2. Ollama Embedder (crates/uteke-core/src/embed/ollama.rs)

pub struct OllamaEmbedder {
    client: reqwest::blocking::Client,
    base_url: String,    // default: http://localhost:11434
    model: String,       // default: nomic-embed-text
    dims: usize,         // model-dependent
}

impl Embedder for OllamaEmbedder {
    fn embed(&self, text: &str) -> Result<Vec<f32>, Error> {
        // POST {base_url}/api/embed
        // Body: { "model": "{model}", "input": "{text}" }
        // Parse response: embeddings[0]
    }
}

3. Backend selection in ensure_embedder()

*guard = Some(match self.embedder_backend.as_str() {
    "onnx" | "" => Box::new(OnnxEmbedder::new()?),
    "openai" => Box::new(OpenAiEmbedder::new(&api_key, &model, &base_url)?),
    "ollama" => Box::new(OllamaEmbedder::new(&base_url, &model)?),
    other => return Err(Error::Validation(format!(
        "Unknown embedding backend: '{other}'. Supported: onnx, openai, ollama."
    ))),
});

4. Config (uteke.toml)

[embedding]
backend = "onnx"          # onnx (default), openai, ollama
model = ""                # backend-specific model name
api_key = ""              # for openai (can also use env var)
base_url = ""             # custom endpoint (Azure, Ollama URL, etc.)

5. Environment Variables

Env Var Description Default
UTEKE_EMBEDDING_BACKEND Backend: onnx, openai, ollama onnx
UTEKE_EMBEDDING_API_KEY API key (OpenAI) —
UTEKE_EMBEDDING_BASE_URL Custom endpoint URL —
UTEKE_EMBEDDING_MODEL Model name backend-specific

Env vars override config file values.

6. Dim mismatch handling

When opening an existing store with a different backend (different dims):

  • Detect mismatch between index dims and embedder dims
  • Return clear error: "Index has 768d vectors but backend 'openai' produces 1536d. Rebuild index or switch backend."
  • Provide uteke repair --rebuild-embeddings to re-embed all memories with new backend

Dependencies

  • reqwest = { version = "0.12", features = ["blocking", "json"] } — always included
  • No feature flags needed

Acceptance Criteria

  • OpenAiEmbedder implements Embedder trait with HTTP call
  • OllamaEmbedder implements Embedder trait with HTTP call
  • Config [embedding] backend/api_key/base_url/model supported
  • Env vars override config
  • ONNX remains default (backward compatible)
  • Dim mismatch detection with clear error message
  • reqwest always included (no feature flags)
  • Documentation updated (configuration.md, cli-reference.md)
  • Tests for backend selection logic

Competitive Impact

Feature Uteke (after) Mem0 Zep Letta
ONNX local ✅ Default ❌ ❌ ❌
OpenAI ✅ ✅ ✅ ✅
Ollama ✅ ❌ ✅ ✅
Zero-dep mode ✅ (ONNX) ❌ ❌ ❌

Effort

~1-2 days

Activity

  1. added
    enhancement
    scope:core
    type:feature
    priority:high
    on Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementpriority:highscope:coretype:feature

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions