[PR #22702] [CLOSED] fix: handle ollama embedding errors for bge-m3 and similar models #81694

Closed
opened 2026-05-13 16:04:12 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/22702
Author: @mvanhorn
Created: 3/15/2026
Status: Closed

Base: mainHead: osc/22671-ollama-rag-embedding-500


📝 Commits (1)

  • f697266 fix: handle ollama embedding response format for bge-m3

📊 Changes

1 file changed (+30 additions, -4 deletions)

View changed files

📝 backend/open_webui/retrieval/utils.py (+30 -4)

📄 Description

Summary

  • Explicitly pass truncate: true in ollama /api/embed requests to ensure input is truncated to fit the model's context length, preventing HTTP 500 errors with models like bge-m3 that have limited context windows (num_ctx=4096)
  • Replace raise_for_status() with error response body parsing in both sync and async ollama embedding functions, so the actual ollama error message is logged instead of a generic "500 Internal Server Error"
  • Add None guards in generate_embeddings to prevent TypeError: 'NoneType' object is not subscriptable when an upstream embedding call fails and returns None

Root cause

When using RAG_EMBEDDING_ENGINE=ollama with RAG_EMBEDDING_MODEL=bge-m3, ollama can return HTTP 500 if the input text exceeds the model's context length. While ollama's API documents truncate as defaulting to true, certain model/version combinations (bge-m3 on ollama 0.18.0) fail without it being explicitly set. The error was further obscured because raise_for_status() discarded ollama's error response body, and the None return from the embedding function caused a cascading TypeError.

Test plan

  • Verify embedding generation works with RAG_EMBEDDING_ENGINE=ollama and RAG_EMBEDDING_MODEL=bge-m3
  • Verify that when ollama returns an error, the actual error message appears in Open WebUI logs
  • Verify existing embedding functionality (openai, azure_openai, sentence-transformers) is unaffected

Fixes #22671

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/22702 **Author:** [@mvanhorn](https://github.com/mvanhorn) **Created:** 3/15/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `osc/22671-ollama-rag-embedding-500` --- ### 📝 Commits (1) - [`f697266`](https://github.com/open-webui/open-webui/commit/f69726630a05849f09966546b7f62e195ffb64f6) fix: handle ollama embedding response format for bge-m3 ### 📊 Changes **1 file changed** (+30 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/retrieval/utils.py` (+30 -4) </details> ### 📄 Description ## Summary - Explicitly pass `truncate: true` in ollama `/api/embed` requests to ensure input is truncated to fit the model's context length, preventing HTTP 500 errors with models like bge-m3 that have limited context windows (num_ctx=4096) - Replace `raise_for_status()` with error response body parsing in both sync and async ollama embedding functions, so the actual ollama error message is logged instead of a generic "500 Internal Server Error" - Add `None` guards in `generate_embeddings` to prevent `TypeError: 'NoneType' object is not subscriptable` when an upstream embedding call fails and returns `None` ## Root cause When using `RAG_EMBEDDING_ENGINE=ollama` with `RAG_EMBEDDING_MODEL=bge-m3`, ollama can return HTTP 500 if the input text exceeds the model's context length. While ollama's API documents `truncate` as defaulting to `true`, certain model/version combinations (bge-m3 on ollama 0.18.0) fail without it being explicitly set. The error was further obscured because `raise_for_status()` discarded ollama's error response body, and the `None` return from the embedding function caused a cascading `TypeError`. ## Test plan - [ ] Verify embedding generation works with `RAG_EMBEDDING_ENGINE=ollama` and `RAG_EMBEDDING_MODEL=bge-m3` - [ ] Verify that when ollama returns an error, the actual error message appears in Open WebUI logs - [ ] Verify existing embedding functionality (openai, azure_openai, sentence-transformers) is unaffected Fixes #22671 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-13 16:04:12 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#81694