Skip to content

fix: pass encoding_format='float' in OpenAI embeddings for proxy compatibility#4058

Merged
whysosaket merged 1 commit intomem0ai:mainfrom
AtharvaJaiswal005:fix/openai-embedding-encoding-format-4057
Mar 18, 2026
Merged

fix: pass encoding_format='float' in OpenAI embeddings for proxy compatibility#4058
whysosaket merged 1 commit intomem0ai:mainfrom
AtharvaJaiswal005:fix/openai-embedding-encoding-format-4057

Conversation

@AtharvaJaiswal005
Copy link
Copy Markdown
Contributor

Closes #4057

Summary

  • Added encoding_format="float" to embeddings.create() call in mem0/embeddings/openai.py
  • The OpenAI Python SDK defaults to encoding_format="base64" when not specified (confirmed by OpenAI), which breaks OpenAI-compatible proxies (OpenRouter, LiteLLM, vLLM, Ollama) that don't support base64 decoding
  • Users get intermittent ValueError: No embedding data received errors when using openai_base_url with non-OpenAI providers

Changes

  • mem0/embeddings/openai.py - added encoding_format="float" to the embeddings.create() call
  • tests/embeddings/test_openai_embeddings.py - updated existing test assertions and added a new test verifying encoding format is always passed

Test plan

  • All 6 OpenAI embedding tests pass
  • No breaking changes - encoding_format="float" works with all providers including direct OpenAI API

…atibility (mem0ai#4057)

The OpenAI Python SDK defaults to encoding_format='base64' when not
specified, which breaks OpenAI-compatible proxies (OpenRouter, LiteLLM,
vLLM, etc.) that don't support base64 decoding. This causes intermittent
'ValueError: No embedding data received' errors for users pointing
openai_base_url at non-OpenAI providers.

Explicitly passing encoding_format='float' ensures compatibility with
all providers while producing identical results.
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Feb 16, 2026

CLA assistant check
All committers have signed the CLA.

@AtharvaJaiswal005
Copy link
Copy Markdown
Contributor Author

Hi! Just checking in on this PR. Let me know if there's anything you'd like me to change or any feedback on the approach. Happy to adjust!

@kartik-mem0 kartik-mem0 self-requested a review March 18, 2026 15:57
Copy link
Copy Markdown
Contributor

@kartik-mem0 kartik-mem0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for your contribution @AtharvaJaiswal005

the solution lgtm!

@whysosaket whysosaket merged commit a172de9 into mem0ai:main Mar 18, 2026
1 of 2 checks passed
jamebobob pushed a commit to jamebobob/mem0-vigil-recall that referenced this pull request Mar 29, 2026
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.

OpenAIEmbedding fails with OpenAI-compatible proxies — SDK defaults to encoding_format="base64" which proxies may not support

4 participants