Commit Graph

2 Commits

Author SHA1 Message Date
Bingxi Zhao (Frank)
c4a6f1b228 fix(embedding): recover from gateways that require an explicit encoding_format
ModelScope reads a missing `encoding_format` as `''` and refuses the request:
`encoding_format must be 'float' or 'base64', got ''`. So the probe and every
real embedding call failed for #934, while the same config worked through the
vendor SDK, which defaults the field to "float".

The report's root cause is right and its suggested fix keys off the wrong
thing. Special-casing the qwen3-embedding family reads the constraint as
belonging to the model, but it belongs to the gateway, and the gateways
disagree: SiliconFlow rejects the param when it is *present* (#651, which is
why it is omitted), ModelScope when it is *absent*. The same Qwen3-Embedding
weights are served on both sides of that disagreement, so no default and no
model-family rule can satisfy both.

Recover from the provider's own refusal instead. The happy path is
byte-identical — the param is still omitted, so every working config sends
exactly what it sent before — and a 400 that names both the parameter and the
value we are about to send earns one retry with `encoding_format="float"`.
Requiring the body to name "float" is what separates "you must send this"
from "I do not support this", so a gateway in the second camp is not retried
into the same failure. The retry is bounded by the param then being present.

Also notes at the omit site why a default must not be reintroduced there:
it would trade #934 for #651.
2026-08-21 16:25:18 +08:00
Bingxi Zhao (Frank)
fc9cc75736 fix(embedding): omit encoding_format by default for OpenAI-compatible 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>
2026-07-23 22:42:13 +08:00