Skip to content

fix(embedding): don't send encoding_format by default for OpenAI-compatible providers - #652

Merged
pancacake merged 1 commit into
HKUDS:devfrom
eason2026:fix/siliconflow-encoding-format
Jul 23, 2026
Merged

fix(embedding): don't send encoding_format by default for OpenAI-compatible providers#652
pancacake merged 1 commit into
HKUDS:devfrom
eason2026:fix/siliconflow-encoding-format

Conversation

@eason2026

Copy link
Copy Markdown
Contributor

Problem

SiliconFlow (and possibly other OpenAI-compatible embedding providers) returns HTTP 400 when receiving the encoding_format parameter, which is currently always sent as "float" even when the user hasn't explicitly set it.

Root Cause

In openai_compatible.py, the encoding_format defaults to "float" unconditionally:

"encoding_format": request.encoding_format or "float",

Unlike dimensions (which has send_dimensions flag and model-family heuristics), encoding_format has no opt-out mechanism.

Fix

Only include encoding_format in the request payload when the user explicitly sets it via request.encoding_format:

if request.encoding_format:
    payload["encoding_format"] = request.encoding_format

This matches the existing pattern used for dimensions / send_dimensions.

Testing

  • Works with SiliconFlow BAAI/bge-large-zh-v1.5 (previously returned HTTP 400)
  • Backward compatible: users who explicitly set encoding_format are unaffected
  • OpenAI's text-embedding-3-* models still work (no encoding_format = default behavior)

Closes #651

…atible providers

SiliconFlow and other OpenAI-compatible providers reject the
`encoding_format` parameter with HTTP 400. Only send it when
explicitly set by the user, matching the existing opt-in pattern
used for `dimensions` (send_dimensions flag).

Closes HKUDS#651
@pancacake
pancacake changed the base branch from main to dev July 23, 2026 14:38
@pancacake

Copy link
Copy Markdown
Collaborator

Thanks for your contribution!

@pancacake
pancacake merged commit e0023d3 into HKUDS:dev Jul 23, 2026
pancacake added a commit that referenced this pull request Jul 23, 2026
… gateways

#652 added a guard so the gateway adapter only sends encoding_format when
set, but it was a no-op: EmbeddingRequest.encoding_format defaulted to the
truthy "float", so the guard always fired and the param was still posted —
leaving the #651 HTTP 400 from gateways like SiliconFlow intact.

Fix the root cause: default encoding_format to None. The gateway adapter now
omits it unless a caller explicitly opts in, while the official OpenAI SDK
path keeps pinning "float" (that API expects it). The intentional divergence
is documented at both call sites. Adds a payload test proving the gateway
omits it by default and includes it when set.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
vaskoyudha added a commit to vaskoyudha/deeptutor-for-programmer-fork that referenced this pull request Jul 25, 2026
…format

fix(embedding): don't send encoding_format by default for OpenAI-compatible providers
vaskoyudha added a commit to vaskoyudha/deeptutor-for-programmer-fork that referenced this pull request Jul 25, 2026
… gateways

HKUDS#652 added a guard so the gateway adapter only sends encoding_format when
set, but it was a no-op: EmbeddingRequest.encoding_format defaulted to the
truthy "float", so the guard always fired and the param was still posted —
leaving the HKUDS#651 HTTP 400 from gateways like SiliconFlow intact.

Fix the root cause: default encoding_format to None. The gateway adapter now
omits it unless a caller explicitly opts in, while the official OpenAI SDK
path keeps pinning "float" (that API expects it). The intentional divergence
is documented at both call sites. Adds a payload test proving the gateway
omits it by default and includes it when set.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

SiliconFlow Embedding API 不兼容(HTTP 400)

2 participants