Skip to content

Commit e0cdab3

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 a3c6200 commit e0cdab3

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
@@ -1229,7 +1229,8 @@ def embed_stream(
12291229
for embedding in parser.iter_embeddings():
12301230
# The parser sets embedding.text correctly for multiple embedding types
12311231
# Adjust the global index based on text position in batch
1232-
if embedding.text and embedding.text in batch_texts:
1232+
# Use 'is not None' to handle empty strings correctly (they are falsy but valid)
1233+
if embedding.text is not None and embedding.text in batch_texts:
12331234
# Get or create the set of used indices for this embedding type
12341235
emb_type = embedding.embedding_type
12351236
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)