Skip to content

Commit

Permalink
Return Cohere embeddings as lists of floats (langchain-ai#1394)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kacperlukawski authored Mar 2, 2023
1 parent 1989e7d commit 8947797
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions langchain/embeddings/cohere.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def embed_documents(self, texts: List[str]) -> List[List[float]]:
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.
Expand All @@ -78,4 +78,4 @@ def embed_query(self, text: str) -> List[float]:
embedding = self.client.embed(
model=self.model, texts=[text], truncate=self.truncate
).embeddings[0]
return embedding
return list(map(float, embedding))

0 comments on commit 8947797

Please sign in to comment.