-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cohere rerank exception: invalid request: list of documents must not be empty #7370
Comments
To resolve the "Cohere rerank exception: invalid request: list of documents must not be empty" error, ensure that the list of documents passed to the Here's what you can do:
Here's a basic example of how you might implement such a check: const documents = await retriever.retrieve(sanitizedText);
if (documents.length === 0) {
console.error("No documents retrieved. Skipping reranking.");
// Handle the empty case as needed, e.g., return a default response or log an error.
} else {
const rerankedDocuments = await cohereRerank.compressDocuments(documents, sanitizedText);
// Proceed with using rerankedDocuments
} By ensuring that the list of documents is not empty before calling the rerank method, you can avoid this error [1]. To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
P.S: This is similar to the issues reported in the Java and Python versions of Langchain, which were fixed a long time ago:
@hwchase17 Could you apply the patch from the above packages to langchainjs? |
Below are the two issues that are causing this error and the proposed fixes:
Example:
Example:
|
…nts if the documents parameter is null or empty
Created PRs to address this issue. Please review. Thanks! |
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
BadRequestError
Status code: 400
Body: {
"message": "invalid request: list of documents must not be empty"
}
/node_modules/langchain/dist/chains/combine_documents/base.js:8
const formattedDocs = await Promise.all(documents.map((document) => documentPrompt
^
TypeError: Cannot read properties of undefined (reading 'map')
at formatDocuments (/node_modules/langchain/dist/chains/combine_documents/base.js:8:55)
at RunnableLambda.func (/node_modules/langchain/dist/chains/combine_documents/stuff.js:27:90)
at /node_modules/@langchain/core/dist/runnables/base.js:1735:44
at MockAsyncLocalStorage.run (/node_modules/@langchain/core/dist/singletons/async_local_storage/index.js:10:16)
at AsyncLocalStorageProvider.runWithConfig (/node_modules/@langchain/core/dist/singletons/async_local_storage/index.js:53:24)
at output (/node_modules/@langchain/core/dist/runnables/base.js:1733:53)
at new Promise ()
at RunnableLambda._transform (/node_modules/@langchain/core/dist/runnables/base.js:1732:30)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async RunnableLambda._transformStreamWithConfig (/node_modules/@langchain/core/dist/runnables/base.js:301:30)
Description
I'm using the Cohere reranker, and it throws an exception when the retriever has empty documents. This prevents the AI for generating a response.
The ideal behavior should be to return an empty list so that the AI can generate a response based on the instructions we've given it.
Edit: this issue is similar to the ones reported in the Java and Python versions of Langchain, which were fixed a long time ago:
langchain4j/langchain4j#770
langchain-ai/langchain#5304
System Info
Package versions:
"langchain": "^0.3.7"
"@langchain/cohere": "^0.3.1"
"@langchain/core": "^0.3.23"
The text was updated successfully, but these errors were encountered: