Skip to content

Commit 09fb178

Browse files
committed
udpate embed request with embedding_types
1 parent abfbac4 commit 09fb178

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

cohere/client.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,21 +395,20 @@ def embed(
395395
texts: List[str],
396396
model: Optional[str] = None,
397397
truncate: Optional[str] = None,
398-
compression: Optional[str] = None,
399398
input_type: Optional[str] = None,
399+
embedding_types: Optional[List[str]] = None,
400400
) -> Embeddings:
401401
"""Returns an Embeddings object for the provided texts. Visit https://cohere.ai/embed to learn about embeddings.
402402
403403
Args:
404404
text (List[str]): A list of strings to embed.
405405
model (str): (Optional) The model ID to use for embedding the text.
406406
truncate (str): (Optional) One of NONE|START|END, defaults to END. How the API handles text longer than the maximum token length.
407-
compression (str): (Optional) One of "int8" or "binary". The type of compression to use for the embeddings.
408407
input_type (str): (Optional) One of "classification", "clustering", "search_document", "search_query". The type of input text provided to embed.
408+
embedding_types (List[str]): (Optional) Specifies the types of embeddings you want to get back. Not required and default is None, which returns the float embeddings in the response's embeddings field. Can be one or more of the following types: "float", "int8", "uint8", "binary", "ubinary".
409409
"""
410410
responses = {
411411
"embeddings": [],
412-
"compressed_embeddings": [],
413412
}
414413
json_bodys = []
415414

@@ -420,20 +419,18 @@ def embed(
420419
"model": model,
421420
"texts": texts_batch,
422421
"truncate": truncate,
423-
"compression": compression,
424422
"input_type": input_type,
423+
"embedding_types": embedding_types,
425424
}
426425
)
427426

428427
meta = None
429428
for result in self._executor.map(lambda json_body: self._request(cohere.EMBED_URL, json=json_body), json_bodys):
430429
responses["embeddings"].extend(result["embeddings"])
431-
responses["compressed_embeddings"].extend(result.get("compressed_embeddings", []))
432430
meta = result["meta"] if not meta else meta
433431

434432
return Embeddings(
435433
embeddings=responses["embeddings"],
436-
compressed_embeddings=responses["compressed_embeddings"],
437434
meta=meta,
438435
)
439436

cohere/client_async.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,25 +279,25 @@ async def embed(
279279
texts: List[str],
280280
model: Optional[str] = None,
281281
truncate: Optional[str] = None,
282-
compression: Optional[str] = None,
283282
input_type: Optional[str] = None,
283+
embedding_types: Optional[List[str]] = None,
284284
) -> Embeddings:
285285
"""Returns an Embeddings object for the provided texts. Visit https://cohere.ai/embed to learn about embeddings.
286286
287287
Args:
288288
text (List[str]): A list of strings to embed.
289289
model (str): (Optional) The model ID to use for embedding the text.
290290
truncate (str): (Optional) One of NONE|START|END, defaults to END. How the API handles text longer than the maximum token length.
291-
compression (str): (Optional) One of "int8" or "binary". The type of compression to use for the embeddings.
292291
input_type (str): (Optional) One of "classification", "clustering", "search_document", "search_query". The type of input text provided to embed.
292+
embedding_types (List[str]): (Optional) Specifies the types of embeddings you want to get back. Not required and default is None, which returns the float embeddings in the response's embeddings field. Can be one or more of the following types: "float", "int8", "uint8", "binary", "ubinary".
293293
"""
294294
json_bodys = [
295295
dict(
296296
texts=texts[i : i + cohere.COHERE_EMBED_BATCH_SIZE],
297297
model=model,
298298
truncate=truncate,
299-
compression=compression,
300299
input_type=input_type,
300+
embedding_types=embedding_types,
301301
)
302302
for i in range(0, len(texts), cohere.COHERE_EMBED_BATCH_SIZE)
303303
]
@@ -306,9 +306,6 @@ async def embed(
306306

307307
return Embeddings(
308308
embeddings=[e for res in responses for e in res["embeddings"]],
309-
compressed_embeddings=[e for res in responses for e in res["compressed_embeddings"]]
310-
if compression
311-
else None,
312309
meta=meta,
313310
)
314311

0 commit comments

Comments
 (0)