[PR #12715] [MERGED] embeddings: base64 encoding fix #39797

Closed
opened 2026-04-23 00:47:35 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/12715
Author: @npardal
Created: 10/21/2025
Status: Merged
Merged: 10/22/2025
Merged by: @npardal

Base: mainHead: nicole/embeddings


📝 Commits (3)

📊 Changes

4 files changed (+386 additions, -12 deletions)

View changed files

📝 middleware/openai.go (+15 -4)
middleware/openai_encoding_format_test.go (+220 -0)
📝 openai/openai.go (+26 -8)
openai/openai_encoding_format_test.go (+125 -0)

📄 Description

WHAT
added support for encoding_format param in OpenAI-compatible /v1/embeddings endpoint, allows clients to request embeddings in either float (JSON array) or base64 (base64-encoded string) format.

WHY
The /v1/embeddings endpoint was not respecting the encoding_format parameter that OpenAI clients send in requests. This caused compatibility issues with:

  • C# clients (Azure.AI.OpenAI SDK) - which default to requesting base64 format and would crash with "Invalid base64 string" errors

CHANGES

  • Added EncodingFormat field to openai.EmbedRequest struct to accept the parameter from clients
  • Modified Embedding struct to use any type for the Embedding field, allowing it to hold either []float32 or string
  • Updated ToEmbeddingList() function to accept encodingFormat parameter and convert embeddings to JSON or base-64 encoded string
  • Updated middleware to pass encoding_format from request through to response transformation

🔄 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/ollama/ollama/pull/12715 **Author:** [@npardal](https://github.com/npardal) **Created:** 10/21/2025 **Status:** ✅ Merged **Merged:** 10/22/2025 **Merged by:** [@npardal](https://github.com/npardal) **Base:** `main` ← **Head:** `nicole/embeddings` --- ### 📝 Commits (3) - [`3ee19e4`](https://github.com/ollama/ollama/commit/3ee19e4602ea5b0f3b0008531691c7581f715cf7) allowed base64 encoding - [`7b88c89`](https://github.com/ollama/ollama/commit/7b88c893ebac623e8a4c18161d8c0d557f78fbc1) simplfied logic and added tests - [`d436303`](https://github.com/ollama/ollama/commit/d436303bbed88994448a496e546a917c1b209890) shortened tests ### 📊 Changes **4 files changed** (+386 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `middleware/openai.go` (+15 -4) ➕ `middleware/openai_encoding_format_test.go` (+220 -0) 📝 `openai/openai.go` (+26 -8) ➕ `openai/openai_encoding_format_test.go` (+125 -0) </details> ### 📄 Description **WHAT** added support for encoding_format param in OpenAI-compatible `/v1/embeddings` endpoint, allows clients to request embeddings in **either** float (JSON array) or base64 (base64-encoded string) format. **WHY** The /v1/embeddings endpoint was not respecting the encoding_format parameter that OpenAI clients send in requests. This caused compatibility issues with: - C# clients (Azure.AI.OpenAI SDK) - which default to requesting base64 format and would crash with "Invalid base64 string" errors **CHANGES** - Added EncodingFormat field to openai.EmbedRequest struct to accept the parameter from clients - Modified Embedding struct to use any type for the Embedding field, allowing it to hold either []float32 or string - Updated ToEmbeddingList() function to accept encodingFormat parameter and convert embeddings to JSON or base-64 encoded string - Updated middleware to pass encoding_format from request through to response transformation --- <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-04-23 00:47:35 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#39797