Skip to content

Commit d2d3d65

Browse files
committed
fix: Handle empty string texts correctly in embed_stream
Change truthiness check to explicit None check so empty strings are handled correctly and get proper global indices.
1 parent 9636658 commit d2d3d65

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

src/cohere/base_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,8 @@ def embed_stream(
12321232
for embedding in parser.iter_embeddings():
12331233
# The parser sets embedding.text correctly for multiple embedding types
12341234
# Adjust the global index based on text position in batch
1235-
if embedding.text and embedding.text in batch_texts:
1235+
# Use 'is not None' to handle empty strings correctly (they are falsy but valid)
1236+
if embedding.text is not None and embedding.text in batch_texts:
12361237
# Get or create the set of used indices for this embedding type
12371238
emb_type = embedding.embedding_type
12381239
if emb_type not in used_batch_indices_by_type:

src/cohere/v2/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,8 @@ def embed_stream(
610610
for embedding in parser.iter_embeddings():
611611
# The parser sets embedding.text correctly for multiple embedding types
612612
# Adjust the global index based on text position in batch
613-
if embedding.text and embedding.text in batch_texts:
613+
# Use 'is not None' to handle empty strings correctly (they are falsy but valid)
614+
if embedding.text is not None and embedding.text in batch_texts:
614615
# Get or create the set of used indices for this embedding type
615616
emb_type = embedding.embedding_type
616617
if emb_type not in used_batch_indices_by_type:

0 commit comments

Comments
 (0)