Fix Decouple 'dimensions' parameter in OpenAIEmbedder for third-party compatibility#7396
Fix Decouple 'dimensions' parameter in OpenAIEmbedder for third-party compatibility#7396panchaldhruv27223 wants to merge 9 commits intoagno-agi:mainfrom
Conversation
… AI compatibility) -BY DhruvPanchal
… AI compatibility) -BY DhruvPanchal
PR TriageMissing tests: This PR modifies source code but does not include any test changes. Please add or update tests to cover your changes. |
ysolanky
left a comment
There was a problem hiding this comment.
Review
The core idea is right — adding send_dimensions as a toggle is a good approach. However, as written this PR is a breaking change for several existing subclasses. Here's an alternative that fixes the Together AI bug without changing behavior for anyone else.
Problem with the current auto-detection
The PR changes the auto-detect from:
# current (main)
self.id.startswith("text-embedding-3") or self.base_url is not Noneto:
# this PR
self.id.startswith("text-embedding-3")This silently changes behavior for FireworksEmbedder, NebiusEmbedder, and LangDBEmbedder — all of which have base_url set and currently do send dimensions. Whether those providers accept it or not, changing the default is a breaking change.
Suggested approach
Keep the existing auto-detection logic unchanged, and have TogetherEmbedder (and OpenAILikeEmbedder) explicitly opt out:
openai.py — preserve existing behavior as the default:
send_dimensions: Optional[bool] = None
def __post_init__(self):
if self.dimensions is None:
self.dimensions = 3072 if self.id == "text-embedding-3-large" else 1536
if self.send_dimensions is None:
self.send_dimensions = self.id.startswith("text-embedding-3") or self.base_url is not Nonetogether.py — fix the actual bug:
send_dimensions: Optional[bool] = Falseopenai_like.py — most OpenAI-like providers don't support it:
send_dimensions: Optional[bool] = FalseThis way:
OpenAIEmbedderwithtext-embedding-3: sends dimensions (unchanged)OpenAIEmbedderwith custombase_url: sends dimensions (unchanged)FireworksEmbedder,NebiusEmbedder,LangDBEmbedder: sends dimensions (unchanged)TogetherEmbedder: does NOT send dimensions (bug fixed)- Users can always override with
send_dimensions=True/False
Other notes
- The default model change for
TogetherEmbedder(togethercomputer/m2-bert-80M-32k-retrieval→intfloat/multilingual-e5-large-instruct) is a separate breaking change. The PR description mentionsnomic-ai/nomic-embed-text-v1.5but the code uses a different model. This should be split into its own PR. LangDBEmbedderoverrides__post_init__without callingsuper(), so with the current PRsend_dimensionsstaysNone(falsy) — silently breaking it. The suggested approach above avoids this sincesend_dimensions=Noneis only resolved inOpenAIEmbedder.__post_init__.- Missing tests — at minimum, unit tests for the auto-detection logic would be valuable.
… add tests -BY DhruvPanchal
23bbd84 to
550952f
Compare
|
@ysolanky Thank you for the incredibly thorough review! You were spot on about the downstream breaking changes - I really appreciate you catching the impact on Fireworks, Nebius, and that LangDBEmbedder OOP quirk. I've pushed a new commit that implements your suggested approach exactly. Here is a breakdown of the updates:
Comprehensive Unit Tests Added:
|
|
Any updates on this !? |
Summary
This PR resolves an issue where
OpenAIEmbedderand its subclasses (e.g.,TogetherEmbedder,OpenAILikeEmbedder) would fail with HTTP 400 errors when interacting with OpenAI-compatible endpoints that do not support thedimensionsparameter in their/v1/embeddingspayload (e.g., Together AI, Groq, ...).Key Changes & Architectural Improvements:
send_dimensions: Optional[bool] = NonetoOpenAIEmbedderto act as a clean feature toggle.__post_init__to safely auto-detect this requirement. It defaults toTrueonly if the model `startswith("text-embedding-3"). This preserves perfect backward compatibility for standard OpenAI V3 users while safely stripping the parameter by default for custom/third-party providers.if self.base_url is not None:checks acrossresponse,async_get_embedding,async_get_embedding_and_usage, andasync_get_embeddings_batch_and_usagewith the new safe toggle.TogetherEmbedderfrom the deprecatedtogethercomputer/m2-bert-80M-32k-retrievaltonomic-ai/nomic-embed-text-v1.5so the integration works out-of-the-box again.Resolves #7395
Type of change
Checklist
./scripts/format.shand./scripts/validate.sh)Duplicate and AI-Generated PR Check
Additional Notes
Testing Details
text-embedding-3-smallstill correctly sends thedimensionsparameter to the native OpenAI endpoint.base_urlwith non-OpenAI models safely omitsdimensionsfrom the payload.TogetherEmbeddersuccessfully connects and embeds without throwing HTTP 400 Bad Request errors.