Repository navigation
Conversation
The embeddings endpoint dropped encoding_format and always returned float arrays. Clients that explicitly ask for base64 then receive a list where the OpenAI contract promises a base64 string, and the OpenAI Python and Node SDKs, which request base64 by default, always pay for the larger float payload (about 4x for a 1024-dim vector). Encode dense vectors as base64 little-endian float32 when base64 is requested, matching OpenAI. Sparse embeddings have no base64 form and are returned unchanged.
qinxuye
approved these changes
Oct 7, 2026
qinxuye
left a comment
Contributor
There was a problem hiding this comment.
LGTM. Verified dense base64 encoding, unchanged float/default responses and sparse handling. All 14 focused tests passed, and an additional OpenAI SDK check passed for default, float and explicit base64 requests. The Metal CI failure is in F5-TTS model startup (actor connection reset), outside the changed embedding response path.
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.
What
POST /v1/embeddingsacceptedencoding_formatbut dropped it and always returned float arrays.encoding_format="base64"gets a list where the OpenAI API returns a base64 string, so code that decodes the string breaks.base64by default and decode it client-side, so every SDK call to Xinference pays for the float payload. For a 1024-dim vector that is ~22 KB per embedding instead of ~5.5 KB.Fix
When
encoding_format == "base64", each dense vector is encoded the way OpenAI does it: little-endian float32 bytes, base64-encoded. Sparse embeddings (token -> weight dicts) have no base64 form and stay as they are. Default and"float"responses are unchanged.Before / after (openai SDK 3.26.0 against the handler)
The SDK default call (
create(model=..., input=...)) still returns[0.5, -1.0, 2.0]. It now gets base64 on the wire and decodes it.Tests
xinference/api/tests/test_embedding_encoding_format.py:encoding_formatis not forwarded to the model."float"keep lists.pytest xinference/api/tests: all pass, plus pre-commit (black, ruff, isort, mypy, codespell) on the changed files.