Skip to content

fix: bypass LiteLLM for Ollama embeddings to resolve 400 Bad Request (v1.9 regression)#1509

Open
GratefulDave wants to merge 4 commits intoagent0ai:mainfrom
GratefulDave:fix/ollama-embed-v1.9
Open

fix: bypass LiteLLM for Ollama embeddings to resolve 400 Bad Request (v1.9 regression)#1509
GratefulDave wants to merge 4 commits intoagent0ai:mainfrom
GratefulDave:fix/ollama-embed-v1.9

Conversation

@GratefulDave
Copy link
Copy Markdown

Problem

After the v1.9 refactor of LiteLLMEmbeddingWrapper, the _ollama_embed() bypass that was previously working was removed. This reintroduced the Ollama embedding 400 Bad Request error for users running Ollama as their embedding provider.

Error:

litellm.exceptions.APIConnectionError: OllamaException - Client error '400 Bad Request'
for url 'http://host.docker.internal:11434/api/embed'

Root Cause

LiteLLM's Ollama embedding handler sends a malformed request to Ollama's /api/embed endpoint on Ollama 0.18.x+. Specifically, it passes the model name with the ollama/ prefix intact (e.g. ollama/nomic-embed-text) which Ollama does not recognize.

Fix

  • Restores _ollama_embed() to LiteLLMEmbeddingWrapper — calls Ollama's /api/embed directly via httpx, stripping the ollama/ prefix from the model name
  • Routes embed_query and embed_documents through this helper when provider == "ollama", bypassing LiteLLM entirely
  • Wraps search_similarity_threshold in try/except so an embedding failure returns [] instead of crashing the agent

Testing

Verified working against Ollama 0.18.x with nomic-embed-text model over host.docker.internal:11434.

Fixes #1425

lexgenius and others added 4 commits April 13, 2026 12:53
LiteLLM's Ollama embedding handler sends a malformed request to Ollama's
/api/embed endpoint, causing a 400 Bad Request error on Ollama 0.18.x.

- Add `_ollama_embed()` to `LiteLLMEmbeddingWrapper` that calls Ollama's
  `/api/embed` directly via httpx, stripping the "ollama/" prefix from
  the model name (the root cause of the malformed request)
- Route `embed_query` and `embed_documents` through this helper when
  provider == "ollama", bypassing LiteLLM entirely
- Wrap `search_similarity_threshold` in try/except so an embedding
  failure returns [] instead of crashing the agent

Fixes agent0ai#1425

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

Gemini said [BUG] Persistent 400 Bad Request on /api/embed using Ollama with LiteLLM

2 participants