From e94d615b2b089b3d425b31d402f08aa3a5b7b3ee Mon Sep 17 00:00:00 2001 From: Ali Date: Sun, 15 Dec 2024 21:55:28 -0500 Subject: [PATCH] Fixes issue #7370: return empty array from compressDocuments if the documents parameter is null or empty --- libs/langchain-cohere/src/rerank.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/langchain-cohere/src/rerank.ts b/libs/langchain-cohere/src/rerank.ts index 78a13efa2f83..30eb653667ba 100644 --- a/libs/langchain-cohere/src/rerank.ts +++ b/libs/langchain-cohere/src/rerank.ts @@ -60,6 +60,9 @@ export class CohereRerank extends BaseDocumentCompressor { documents: Array, query: string ): Promise> { + if (documents == null || documents.length == 0) { + return []; + } const _docs = documents.map((doc) => doc.pageContent); const { results } = await this.client.rerank({ model: this.model,