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.
When calling
merge_embed_responseswith a list ofEmbeddingsByTypeEmbedResponseobjects where the first response has a given embedding field set (e.g.float_) but a subsequent response has that field asNone, Python raises aTypeError: '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
Noneinstead of an empty list).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
Nonevalues in later responses.