mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-17 02:03:44 +00:00
# Fix: Handle empty documents in ContextualCompressionRetriever (Issue #5304) Fixes #5304 Prevent cohere.error.CohereAPIError caused by an empty list of documents by adding a condition to check if the input documents list is empty in the compress_documents method. If the list is empty, return an empty list immediately, avoiding the error and unnecessary processing. @dev2049 --------- Co-authored-by: Dev 2049 <dev.dev2049@gmail.com>
This commit is contained in:
parent
1366d070fc
commit
99a1e3f3a3
@ -50,6 +50,8 @@ class CohereRerank(BaseDocumentCompressor):
|
||||
def compress_documents(
|
||||
self, documents: Sequence[Document], query: str
|
||||
) -> Sequence[Document]:
|
||||
if len(documents) == 0: # to avoid empty api call
|
||||
return []
|
||||
doc_list = list(documents)
|
||||
_docs = [d.page_content for d in doc_list]
|
||||
results = self.client.rerank(
|
||||
|
Loading…
Reference in New Issue
Block a user