fix: decode base64 embeddings as little-endian floats - #3711
Open
HostX0 wants to merge 1 commit into
Open
Conversation
HostX0
marked this pull request as ready for review
August 21, 2026 13:38
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.
Root cause
The endpoint's base64 embedding representation contains little-endian float32 bytes, but the handwritten response parser used native byte order in both its NumPy and stdlib paths. On big-endian Python platforms, that silently produces incorrect vector values. The existing fixture was also native-endian, so it followed the host instead of the wire format and could not expose the defect.
Fix
Decode the NumPy path with the explicit
<f4dtype, and byte-swap the stdlibarray("f")path on big-endian hosts. The fixture now constructs little-endian wire bytes explicitly, with a regression test covering the stdlib byte-swap path.Tests
python -m pytest -q -n 0 tests/lib/test_embeddings.py— 58 passed with Pydantic v2src/openai/lib/_parsing/_embeddings.pypassedThe repository-wide lint script was also attempted. Ruff passed, while Pyright stopped on 17 pre-existing errors in unmodified audio helper and UV workflow test files.