Skip to content

fix(utils): embed(texts=[]) crashes with IndexError on empty input - #778

Merged
fern-support merged 3 commits into
cohere-ai:mainfrom
devteamaegis:fix/embed-empty-list
Jun 10, 2026
Merged

fix(utils): embed(texts=[]) crashes with IndexError on empty input#778
fern-support merged 3 commits into
cohere-ai:mainfrom
devteamaegis:fix/embed-empty-list

Conversation

@devteamaegis

@devteamaegis devteamaegis commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

What's broken

Client.embed(texts=[]) (default batching, no images) produces an empty responses list, which merge_embed_responses indexes unconditionally:

>>> import cohere
>>> co = cohere.Client(api_key="fake-no-network")
>>> co.embed(texts=[])
IndexError: list index out of range   # src/cohere/utils.py, responses[0].response_type

The crash happens before any network I/O, so an empty input list never gets a meaningful error.

Why it happens

merge_embed_responses reads responses[0] without checking for an empty list.

Fix

Guard the empty case and raise a clear ValueError. The SDK can't synthesise a typed empty EmbedResponse (it wouldn't know response_type), so an explicit, actionable error is the smallest correct behavior and matches the library's existing input-validation pattern.

Test

Added a case asserting merge_embed_responses([]) raises ValueError instead of IndexError.

Fixes #777


Note

Low Risk
Localized input-validation change in embed merge utilities with a regression test; version bump only affects release metadata and User-Agent strings.

Overview
Fixes Client.embed(texts=[]) crashing with IndexError when batched embed yields no responses and merge_embed_responses accessed responses[0]. An early guard now raises a clear ValueError instead of failing opaquely (before any network call).

Adds a unit test for merge_embed_responses([]) and bumps the package/SDK version to 7.0.4 (including Fern metadata and HTTP client version headers).

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

@fern-support
fern-support enabled auto-merge (squash) June 10, 2026 21:23
@fern-support
fern-support merged commit c81e8a7 into cohere-ai:main Jun 10, 2026
1 check passed
@fern-api fern-api Bot mentioned this pull request Jul 20, 2026
fern-api Bot added a commit that referenced this pull request Jul 21, 2026
Patches with unresolved conflicts (2):
  - patch-c81e8a75: fix(utils): embed(texts=[]) crashes with IndexError on empty input (#778)
  - patch-41f344bd: feat(client): forward max_retries through Client/ClientV2 constructors (#779)
    Run `fern-replay resolve` to apply these customizations.
daniel-cohere pushed a commit that referenced this pull request Jul 21, 2026
* [fern-generated] Update SDK

Generated by Fern
CLI Version: unknown
Generators:
  - fernapi/fern-python-sdk: 5.20.0

* [fern-replay] Applied customizations

Patches with unresolved conflicts (2):
  - patch-c81e8a75: fix(utils): embed(texts=[]) crashes with IndexError on empty input (#778)
  - patch-41f344bd: feat(client): forward max_retries through Client/ClientV2 constructors (#779)
    Run `fern-replay resolve` to apply these customizations.

---------

Co-authored-by: fern-api[bot] <115122769+fern-api[bot]@users.noreply.github.com>
@fern-api fern-api Bot mentioned this pull request Jul 23, 2026
daniel-cohere pushed a commit that referenced this pull request Jul 23, 2026
* [fern-generated] Update SDK

Generated by Fern
CLI Version: unknown
Generators:
  - fernapi/fern-python-sdk: 5.22.1

* [fern-replay] Applied customizations

Patches with unresolved conflicts (2):
  - patch-c81e8a75: fix(utils): embed(texts=[]) crashes with IndexError on empty input (#778)
  - patch-41f344bd: feat(client): forward max_retries through Client/ClientV2 constructors (#779)
    Run `fern-replay resolve` to apply these customizations.

---------

Co-authored-by: fern-api[bot] <115122769+fern-api[bot]@users.noreply.github.com>
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.

Client.embed(texts=[]) raises IndexError instead of handling empty input

4 participants