SIGN IN SIGN UP

refactor(api): share embedding response decoding (#3699)

- [x] I understand that this repository is auto-generated and my pull
request may not be merged

## Changes being requested

Move the duplicated embeddings response decoder into the SDK-owned
`lib/_parsing/_embeddings.py` module. Both resource methods use the
existing
`post_parser` hook. The decoder logic is unchanged: omitted encoding
requests
base64 and decodes it in place; explicit formats pass through; empty
data keeps
the existing `ValueError`; NumPy and stdlib decoding keep their existing
errors.

Public signatures, exports, request fields and order, sync/async
behavior, and
raw/streaming response wrappers are unchanged. No compiler, schema,
dependency,
or generation-metadata changes are included.

## Additional context & links

New handwritten coverage is in `tests/lib/test_embeddings.py`:

- `test_decode_preserves_response_and_non_string_vectors` checks
in-place
decoding, both omitted-value sentinels, and untouched non-string
vectors.
- `test_explicit_format_is_untouched`,
  `test_missing_data_keeps_existing_error`, and
`test_invalid_data_preserves_decoder_errors` cover passthrough and
failures.
- `test_sync_create_uses_decoder` and `test_async_create_uses_decoder`
cover
normal, raw, and streaming responses with both decoder implementations.

Validation:

- Command: `python -m pytest -q -n 4
tests/api_resources/test_embeddings.py tests/lib/test_embeddings.py`
  passed 77 tests under Pydantic v2 and 77 under Pydantic v1.
- `./scripts/format` and `./scripts/lint` passed, including Ruff,
Pyright, mypy,
and import checks. Unrelated formatter-only reporter edits are excluded.
- `./scripts/build` passed; the wheel and source distribution both
contain the
  new private helper.
- The public custom-code report verifies 41 mixed files, only the
embeddings
customization changed, and 40 other customizations unchanged. The
embeddings
patch shrinks from +73/-22 to +27/-21. `.castiron.stats.yml` is
unchanged.

Command to reproduce the report from this branch:

```sh
$ python3 scripts/castiron/custom_code_report.py report \
    --base 8edd9ae411f9d0a5385447a4697c9f7042868213 \
    --head 38cf9c9ccb2c4e007ada4672424733845e0c29e9 \
    --fetch --require-head-hash --public \
    --out /tmp/castiron-embedding-decoder
```
A
Alex Chang committed
50de9af45900fa2c88ac11efbb7f9a7ff0057c42
Parent: 04ecb3c
Committed by GitHub <noreply@github.com> on 8/20/2026, 10:50:10 PM