From 37e1275f9ec6675912984add3a166d27abc8632f Mon Sep 17 00:00:00 2001 From: Abhishek Jain Date: Tue, 13 Feb 2024 11:27:27 +0530 Subject: [PATCH] community[patch]: Fixed the 'aembed' method of 'CohereEmbeddings'. (#16497) **Description:** - The existing code was trying to find a `.embeddings` property on the `Coroutine` returned by calling `cohere.async_client.embed`. - Instead, the `.embeddings` property is present on the value returned by the `Coroutine`. - Also, it seems that the original cohere client expects a value of `max_retries` to not be `None`. Hence, setting the default value of `max_retries` to `3`. --------- Co-authored-by: Bagatur --- .../langchain_community/embeddings/cohere.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libs/community/langchain_community/embeddings/cohere.py b/libs/community/langchain_community/embeddings/cohere.py index fd95b58ea6c..2d4676d1254 100644 --- a/libs/community/langchain_community/embeddings/cohere.py +++ b/libs/community/langchain_community/embeddings/cohere.py @@ -34,7 +34,7 @@ class CohereEmbeddings(BaseModel, Embeddings): cohere_api_key: Optional[str] = None - max_retries: Optional[int] = None + max_retries: Optional[int] = 3 """Maximum number of retries to make when generating.""" request_timeout: Optional[float] = None """Timeout in seconds for the Cohere API request.""" @@ -92,11 +92,13 @@ class CohereEmbeddings(BaseModel, Embeddings): async def aembed( self, texts: List[str], *, input_type: Optional[str] = None ) -> List[List[float]]: - embeddings = await self.async_client.embed( - model=self.model, - texts=texts, - input_type=input_type, - truncate=self.truncate, + embeddings = ( + await self.async_client.embed( + model=self.model, + texts=texts, + input_type=input_type, + truncate=self.truncate, + ) ).embeddings return [list(map(float, e)) for e in embeddings]