Skip to content

BUG: TypeError in merge_embed_responses when later batches have None embedding fields #770

Description

@devteamaegis

When calling merge_embed_responses with a list of EmbeddingsByTypeEmbedResponse objects where the first response has a given embedding field set (e.g. float_) but a subsequent response has that field as None, Python raises a TypeError: 'NoneType' object is not iterable.

This is a realistic batching scenario: a first batch may return float embeddings while a later batch omits that key (returning None instead of an empty list).

Traceback (most recent call last):
  File "repro.py", line 10, in <module>
    result = merge_embed_responses([resp1, resp2])
  File "src/cohere/utils.py", line 231, in merge_embed_responses
    for embedding in getattr(embedding_by_type, field)
TypeError: 'NoneType' object is not iterable

The fields to merge are determined by checking the first response only (line 225), but the inner comprehension at line 231 iterates each field over all responses without guarding against None values in later responses.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions