Replies: 1 comment
-
Answer generated by a 🤖 AnswerI understand that you're trying to limit the number of documents returned by a retriever in the LangChain framework. You've tried passing a To address this, you can modify the Here's how you can modify the def _get_docs(
self,
question: str,
inputs: Dict[str, Any],
*,
run_manager: CallbackManagerForChainRun,
k: int = 1 # Add this line
) -> List[Document]:
"""Get docs."""
docs = self.retriever.get_relevant_documents(
question, callbacks=run_manager.get_child()
)
return self._reduce_tokens_below_limit(docs[:k]) # Modify this line In this version of Please note that this is one potential solution and it will affect all retrievals using this class. If you want to set If you find this solution correct and it's not covered in the existing documentation, I encourage you to make a pull request to update the documentation. This will help other users who might encounter the same issue. SourcesThis response is meant to be useful, save you time, and share context. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. |
Beta Was this translation helpful? Give feedback.
-
I am using a retriever within a chain, and would like the retriever to limit the number of docs it returns to a given number
k
(e.g.k=1
). How can I do that? I have code like:I have tried passing a parameter
k=1
tofrom_llm()
but it got quietly ignored, langsmith still shows me that the retriever is returning 4 documents, not 1.Otherwise in code like
again I tried passing a
k=1
toas_retriever()
, which got quietly ignored too.Beta Was this translation helpful? Give feedback.
All reactions