From e2a9072b806b1a45b0e4c107b30dddd0f67a453f Mon Sep 17 00:00:00 2001 From: cccs-eric Date: Tue, 10 Oct 2023 02:26:34 -0400 Subject: [PATCH] Fix CohereRerank configuration (#11583) **Description:** CohereRerank is missing `cohere_api_key` as a field and since extras are forbidden, it is not possible to pass-in the key. The only way is to use an env variable named `COHERE_API_KEY`. For example, if trying to create a compressor like this: ```python cohere_api_key = "......Cohere api key......" compressor = CohereRerank(cohere_api_key=cohere_api_key) ``` you will get the following error: ``` File "/langchain/.venv/lib/python3.10/site-packages/pydantic/v1/main.py", line 341, in __init__ raise validation_error pydantic.v1.error_wrappers.ValidationError: 1 validation error for CohereRerank cohere_api_key extra fields not permitted (type=value_error.extra) ``` --- .../langchain/retrievers/document_compressors/cohere_rerank.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py b/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py index 8199fa46dd2..3db3f7c92fa 100644 --- a/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py +++ b/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py @@ -29,6 +29,8 @@ class CohereRerank(BaseDocumentCompressor): model: str = "rerank-english-v2.0" """Model to use for reranking.""" + cohere_api_key: Optional[str] = None + class Config: """Configuration for this pydantic object."""