Skip to content

Fix/OpenAI embedding dimensions 4153#4481

Merged
kartik-mem0 merged 2 commits intomem0ai:mainfrom
Himanshu-Sangshetti:fix/openai-embedding-dimensions-4153
Mar 25, 2026
Merged

Fix/OpenAI embedding dimensions 4153#4481
kartik-mem0 merged 2 commits intomem0ai:mainfrom
Himanshu-Sangshetti:fix/openai-embedding-dimensions-4153

Conversation

@Himanshu-Sangshetti
Copy link
Copy Markdown
Contributor

@Himanshu-Sangshetti Himanshu-Sangshetti commented Mar 22, 2026

Description

OpenAIEmbedding always passed dimensions to client.embeddings.create(). The constructor also defaulted embedding_dims to 1536 before the call, so the API always received a dimensions argument. OpenAI-compatible servers that are not matryoshka-capable (e.g. vLLM embedding, Voyage) return 400 when dimensions is sent.

This change records whether embedding_dims was explicitly set in config. We still default config.embedding_dims to 1536 for the rest of mem0 (vector sizing, etc.), but dimensions is only added to the API request when the user explicitly configured embedding_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

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • ruff check mem0/embeddings/openai.py tests/embeddings/test_openai_embeddings.py

  • pytest tests/embeddings/test_openai_embeddings.py (7 tests; on Windows use PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 if pytest fails to start due to a broken global plugin)
    Existing tests were updated so default embed calls do not expect dimensions in the API call. Added test_embed_passes_dimensions_only_when_explicit to ensure dimensions is sent when embedding_dims is explicitly set.

  • Unit Test


Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Maintainer Checklist

@kartik-mem0 kartik-mem0 merged commit f06e2d7 into mem0ai:main Mar 25, 2026
6 of 7 checks passed
farrrr pushed a commit to farrrr/mem0 that referenced this pull request Mar 27, 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 always passes dimensions, breaks non-matryoshka OpenAI-compatible embedding backends

3 participants