LitServe icon indicating copy to clipboard operation
LitServe copied to clipboard

Embedding responses ignore explicit base64 encoding_format

Open emecii opened this issue 2 months ago • 1 comments

Bug

POST /v1/embeddings accepts encoding_format="base64" but returns a JSON float array in data[*].embedding. The accepted value was added in #388; the response path still ignores it.

To reproduce

Use a CPU embedding API returning deterministic vectors, such as [5.0, -0.5, 0.25], and send:

{"input":"hello","model":"local-embedding","encoding_format":"base64"}

On main at 4c9fecc2a10c71f7cf016beb67ca0cadca2cbfc0, data[0].embedding is [5.0, -0.5, 0.25], a JSON array. The same happens with multiple text inputs and with both multiprocessing and ZeroMQ transports.

A complete deterministic CPU reproduction is in this test file on the prepared branch. Keeping that file while using the main production source, run:

python -m pytest -q tests/integration/test_embedding_encoding.py

Six base64 cases fail; eight omitted/float controls pass. The tests start real inference workers through the project test helper, with synthetic data and no downloaded model or credentials. A cloud Studio was not used.

Expected behavior

An explicit base64 request returns an encoded float32 vector string, as specified by the embeddings API. Omitted or float encoding continues returning float arrays. Indices, model, and usage metadata are unchanged.

Environment

macOS 26.5.2 arm64; Python 3.12.12; editable LitServe main at the SHA above; FastAPI 0.141.1, Pydantic 2.13.5, HTTPX 0.28.1, NumPy 2.5.2. CPU only; no CUDA or GPU. The original minimal reproduction did not need Torch; neighboring suite validation later used Torch 2.14.0.

Additional context

A focused patch is prepared using standard-library float32 packing and base64 encoding after the existing normalization/validation. It adds no runtime dependency. The regression suite passes with that patch. This report and implementation were prepared and tested with Codex assistance; no prior maintainer agreement is asserted.

emecii avatar Sep 06 '26 07:09 emecii

Thanks @emecii for opening the issue! I’ll review your draft PR and apply any necessary fixes there.

bhimrazy avatar Sep 09 '26 08:09 bhimrazy