fix(embedder): support dimensions param for OpenAI-compatible endpoints with custom api_base#2317
Open
jangrui wants to merge 1 commit into
Open
fix(embedder): support dimensions param for OpenAI-compatible endpoints with custom api_base#2317jangrui wants to merge 1 commit into
jangrui wants to merge 1 commit into
Conversation
…ts with custom api_base When provider is set to "openai" with a custom api_base (e.g. xf-yun or other OpenAI-compatible providers), the _should_send_dimensions() method was always returning False, preventing the dimensions parameter from being sent to the API. This caused the API to return its default dimension instead of the configured one. The fix adds a check for api_base: dimensions are only skipped when using the official OpenAI API (provider="openai" AND no custom api_base). Fixes: custom OpenAI-compatible embedding endpoints not respecting configured dimension values.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨No code suggestions found for the PR. |
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.
Summary
Fixes the
OpenAIDenseEmbedder._should_send_dimensions()method so that thedimensionsparameter is sent to OpenAI-compatible endpoints when a customapi_baseis configured.Problem
When using a custom OpenAI-compatible embedding provider (e.g. xf-yun, SiliconFlow, etc.) with
provider: "openai"in the config, the_should_send_dimensions()method always returnedFalsedue to this condition:This prevented the
dimensionsparameter from being sent to the API, causing the API to return its default dimension instead of the configureddimensionvalue (e.g. 768 instead of 4096).Solution
Added a check for
api_baseto preserve official OpenAI behavior while enabling custom endpoints:Dimensions are now sent when:
"openai", OR"openai"AND a customapi_baseis configuredOfficial OpenAI API behavior (no dimensions, fixed output) is preserved because it uses
provider="openai"with no customapi_base.Test case
provider: "openai",api_base: "https://maas-api.cn-huabei-1.xf-yun.com/v2")xop3qwen8bembeddingDimensionMismatchErrorChecklist