Skip to content

Commit

Permalink
Fixes issue langchain-ai#7370: return empty array from compressDocume…
Browse files Browse the repository at this point in the history
…nts if the documents parameter is null or empty
  • Loading branch information
ahm750 committed Dec 16, 2024
1 parent 538ea0d commit e94d615
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions libs/langchain-cohere/src/rerank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export class CohereRerank extends BaseDocumentCompressor {
documents: Array<DocumentInterface>,
query: string
): Promise<Array<DocumentInterface>> {
if (documents == null || documents.length == 0) {
return [];
}
const _docs = documents.map((doc) => doc.pageContent);
const { results } = await this.client.rerank({
model: this.model,
Expand Down

0 comments on commit e94d615

Please sign in to comment.