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

Closed
opened 2026-05-21 14:41:57 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

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

Base: devHead: osc/22671-ollama-rag-embedding-v2


📝 Commits (1)

  • b7adc6b fix: handle ollama embedding errors for bge-m3 and similar models

📊 Changes

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

View changed files

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

📄 Description

Summary

Fixes Error 500 when using ollama as the RAG embedding engine with bge-m3 and similar models that may exceed context length.

Changes

  1. Explicit truncate: true added to both sync and async ollama embed request payloads. This tells Ollama to truncate input exceeding the model's context length rather than returning a 500 error.

  2. Error response body parsing replaces raise_for_status(). Now the actual error message from Ollama (e.g., "context length exceeded") is surfaced in the exception instead of an opaque HTTP error.

  3. None guards added in generate_embeddings for all three engine paths (ollama, openai, azure_openai). Previously, when an embedding function returned None on failure, embeddings[0] would throw a TypeError that masked the original error.

Testing

  • Verified the changes match the existing code patterns in the embedding pipeline
  • The truncate parameter is documented in the Ollama API

Fixes #22671

This contribution was developed with AI assistance (Claude Code).

Contributor License Agreement


🔄 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/22705 **Author:** [@mvanhorn](https://github.com/mvanhorn) **Created:** 3/15/2026 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `osc/22671-ollama-rag-embedding-v2` --- ### 📝 Commits (1) - [`b7adc6b`](https://github.com/open-webui/open-webui/commit/b7adc6b14734a98b1dfd21f15ec8f7a8ae61e9c0) fix: handle ollama embedding errors for bge-m3 and similar models ### 📊 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 Fixes Error 500 when using ollama as the RAG embedding engine with bge-m3 and similar models that may exceed context length. ## Changes 1. **Explicit `truncate: true`** added to both sync and async ollama embed request payloads. This tells Ollama to truncate input exceeding the model's context length rather than returning a 500 error. 2. **Error response body parsing** replaces `raise_for_status()`. Now the actual error message from Ollama (e.g., "context length exceeded") is surfaced in the exception instead of an opaque HTTP error. 3. **`None` guards** added in `generate_embeddings` for all three engine paths (ollama, openai, azure_openai). Previously, when an embedding function returned `None` on failure, `embeddings[0]` would throw a `TypeError` that masked the original error. ## Testing - Verified the changes match the existing code patterns in the embedding pipeline - The `truncate` parameter is documented in the Ollama API Fixes #22671 This contribution was developed with AI assistance (Claude Code). ### Contributor License Agreement - [x] By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. --- <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-21 14:41:57 -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#130481