Skip to content

fix: decode base64 embeddings as little-endian floats - #3711

Open
HostX0 wants to merge 1 commit into
openai:mainfrom
HostX0:fix/embedding-base64-byte-order
Open

fix: decode base64 embeddings as little-endian floats#3711
HostX0 wants to merge 1 commit into
openai:mainfrom
HostX0:fix/embedding-base64-byte-order

Conversation

@HostX0

@HostX0 HostX0 commented Aug 21, 2026

Copy link
Copy Markdown
  • I understand that this repository is auto-generated and my pull request may not be merged

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 <f4 dtype, and byte-swap the stdlib array("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 v2
  • the same test file under the Pydantic v1 compatibility environment — 58 passed
  • targeted Ruff format/check and Pyright checks passed
  • targeted Mypy check for src/openai/lib/_parsing/_embeddings.py passed

The 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.

@HostX0
HostX0 marked this pull request as ready for review August 21, 2026 13:38
@HostX0
HostX0 requested a review from a team as a code owner August 21, 2026 13:38
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.

1 participant