Skip to content

fix(utils): preserve embedding types across batches - #797

Open
OllieinCanada wants to merge 1 commit into
cohere-ai:mainfrom
OllieinCanada:agent/preserve-late-embedding-types
Open

fix(utils): preserve embedding types across batches#797
OllieinCanada wants to merge 1 commit into
cohere-ai:mainfrom
OllieinCanada:agent/preserve-late-embedding-types

Conversation

@OllieinCanada

@OllieinCanada OllieinCanada commented Aug 15, 2026

Copy link
Copy Markdown

Fixes #796

Summary

  • collect embedding types from every batched response, not only the first
  • continue skipping None values while preserving types returned by later batches
  • add a regression for a later int8 response

Root cause

merge_embed_responses() built its field list from embeddings_type[0]. When that response did not contain a type that a later batch returned, the type was never added to the merged dictionary and its values were silently lost.

Validation

  • regression fails on main (int8 is None)
  • pytest -q tests/test_embed_utils.py (7 passed)
  • mypy . (341 source files, no issues)
  • git diff --check

The complete test collection requires CO_API_KEY in two existing modules, so no live API tests were run. Ruff reports the repository's existing import-format findings in both touched files; this patch does not reformat unrelated code.


Note

Low Risk
Small, targeted change to batch merge logic with a regression test; affects embed response assembly only, not API calls or auth.

Overview
Fixes batched embeddings-by-type merging so embedding types from later API batches are not dropped when the first batch did not return those types.

merge_embed_responses() now decides which fields to merge by checking whether any batch has a non-None value for each type, instead of only inspecting the first response. Merging still skips None per batch when concatenating vectors.

A regression test covers a case where the first batch has only float_ and a later batch adds int8, ensuring both types appear in the merged result.

Reviewed by Cursor Bugbot for commit 9806f64. Bugbot is set up for automated code reviews on this repo. Configure here.

Signed-off-by: Oliver Slapinski <olliefromcanada@gmail.com>
@OllieinCanada
OllieinCanada marked this pull request as ready for review August 15, 2026 23:29
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.

Batched embeddings drop types absent from the first response

1 participant