Skip to content

fix(embedder): support dimensions param for OpenAI-compatible endpoints with custom api_base#2317

Open
jangrui wants to merge 1 commit into
volcengine:mainfrom
jangrui:fix/openai-compatible-dimensions
Open

fix(embedder): support dimensions param for OpenAI-compatible endpoints with custom api_base#2317
jangrui wants to merge 1 commit into
volcengine:mainfrom
jangrui:fix/openai-compatible-dimensions

Conversation

@jangrui
Copy link
Copy Markdown

@jangrui jangrui commented May 29, 2026

Summary

Fixes the OpenAIDenseEmbedder._should_send_dimensions() method so that the dimensions parameter is sent to OpenAI-compatible endpoints when a custom api_base is 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 returned False due to this condition:

if self._provider == "openai":
    return False

This prevented the dimensions parameter from being sent to the API, causing the API to return its default dimension instead of the configured dimension value (e.g. 768 instead of 4096).

Solution

Added a check for api_base to preserve official OpenAI behavior while enabling custom endpoints:

if self._provider == "openai" and not self.api_base:
    return False

Dimensions are now sent when:

  • Provider is NOT "openai", OR
  • Provider is "openai" AND a custom api_base is configured

Official OpenAI API behavior (no dimensions, fixed output) is preserved because it uses provider="openai" with no custom api_base.

Test case

  • Provider: xf-yun MaaS (provider: "openai", api_base: "https://maas-api.cn-huabei-1.xf-yun.com/v2")
  • Model: xop3qwen8bembedding
  • Configured dimension: 4096
  • Before fix: API returned 768 (default) → DimensionMismatchError
  • After fix: API correctly returns 4096

Checklist

  • Code follows project style
  • Changes are minimal (1-line fix)
  • Tests added/updated (embedder tests may need updating)
  • Documentation updated if applicable

…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.
@github-actions
Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
🏅 Score: 95
🧪 No relevant tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ No major issues detected

@github-actions
Copy link
Copy Markdown

PR Code Suggestions ✨

No code suggestions found for the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant