Fix/OpenAI embedding dimensions 4153#4481
Merged
kartik-mem0 merged 2 commits intomem0ai:mainfrom Mar 25, 2026
Merged
Conversation
utkarsh240799
approved these changes
Mar 25, 2026
7 tasks
15 tasks
farrrr
pushed a commit
to farrrr/mem0
that referenced
this pull request
Mar 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
OpenAIEmbeddingalways passeddimensionstoclient.embeddings.create(). The constructor also defaultedembedding_dimsto 1536 before the call, so the API always received adimensionsargument. OpenAI-compatible servers that are not matryoshka-capable (e.g. vLLM embedding, Voyage) return 400 whendimensionsis sent.This change records whether
embedding_dimswas explicitly set in config. We still defaultconfig.embedding_dimsto 1536 for the rest of mem0 (vector sizing, etc.), butdimensionsis only added to the API request when the user explicitly configuredembedding_dims(e.g. matryoshka / truncated embeddings).Dependencies: None.
Fixes #4153
Duplicate effort with #4181 (same issue #4153). Maintainer can merge either; I’ll close this PR if #4181 goes in first.
Type of change
How Has This Been Tested?
ruff check mem0/embeddings/openai.py tests/embeddings/test_openai_embeddings.pypytest tests/embeddings/test_openai_embeddings.py(7 tests; on Windows usePYTEST_DISABLE_PLUGIN_AUTOLOAD=1if pytest fails to start due to a broken global plugin)Existing tests were updated so default embed calls do not expect
dimensionsin the API call. Addedtest_embed_passes_dimensions_only_when_explicitto ensuredimensionsis sent whenembedding_dimsis explicitly set.Unit Test
Checklist:
Maintainer Checklist