From 8947797250b2f890d6db0df6429dc44575abe482 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20=C5=81ukawski?= Date: Thu, 2 Mar 2023 18:02:10 +0100 Subject: [PATCH] Return Cohere embeddings as lists of floats (#1394) This PR fixes the types returned by Cohere embeddings. Currently, Cohere client returns instances of `cohere.embeddings.Embeddings`. Since the transport layer relies on JSON, some numbers might be represented as ints, not floats, which happens quite often. While that doesn't seem to be an issue, it breaks some pydantic models if they require strict floats. --- langchain/embeddings/cohere.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/langchain/embeddings/cohere.py b/langchain/embeddings/cohere.py index c6d5055f..b5dda307 100644 --- a/langchain/embeddings/cohere.py +++ b/langchain/embeddings/cohere.py @@ -64,7 +64,7 @@ class CohereEmbeddings(BaseModel, Embeddings): embeddings = self.client.embed( model=self.model, texts=texts, truncate=self.truncate ).embeddings - return embeddings + return [list(map(float, e)) for e in embeddings] def embed_query(self, text: str) -> List[float]: """Call out to Cohere's embedding endpoint. @@ -78,4 +78,4 @@ class CohereEmbeddings(BaseModel, Embeddings): embedding = self.client.embed( model=self.model, texts=[text], truncate=self.truncate ).embeddings[0] - return embedding + return list(map(float, embedding))