-
Checked other resources
Commit to Help
Example Codesources = {'b.txt','c.txt'}
all_sources = {'a.txt','b.txt','c.txt'}
retriever = vectordb.as_retriever(search_kwargs={'k': 25,'filter': {'source':list(all_sources)}})
print(len(retriever.invoke(question))) #return 20
retriever.invoke(question)
retriever = vectordb.as_retriever(search_kwargs={'k': 15,'filter': {'source':list(all_sources)}})
print(len(retriever.invoke(question))) #return 15
retriever.invoke(question)
retriever = vectordb.as_retriever(search_kwargs={"k": int(25)})
print(len(retriever.invoke(question))) #return 25
retriever.invoke(question) DescriptionSince i want to use a filter to only retrieve documents from some specific papers, i saw some references: but i fund that it will only return 20 documents when i using filter in retriever, i try to set filter with all papers or increase the value k, but it still return 20 documents. System Info
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey there, @BarryC7! I'm here to help you with any bugs, questions, or contributions you have in mind. Let's get to the bottom of this together! I found a similar issue that might be relevant to your problem. The default value of the Here's how you can modify your code to set the sources = {'b.txt', 'c.txt'}
all_sources = {'a.txt', 'b.txt', 'c.txt'}
retriever = vectordb.as_retriever(search_kwargs={'k': 25, 'fetch_k': 50, 'filter': {'source': list(all_sources)}})
print(len(retriever.invoke(question))) # Should return up to 25 documents
retriever.invoke(question)
retriever = vectordb.as_retriever(search_kwargs={'k': 15, 'fetch_k': 50, 'filter': {'source': list(all_sources)}})
print(len(retriever.invoke(question))) # Should return up to 15 documents
retriever.invoke(question)
retriever = vectordb.as_retriever(search_kwargs={'k': 25, 'fetch_k': 50})
print(len(retriever.invoke(question))) # Should return up to 25 documents
retriever.invoke(question) By setting |
Beta Was this translation helpful? Give feedback.
Hey there, @BarryC7! I'm here to help you with any bugs, questions, or contributions you have in mind. Let's get to the bottom of this together!
I found a similar issue that might be relevant to your problem. The default value of the
fetch_k
parameter in theas_retriever
method is 20, which limits the maximum number of documents fetched regardless of thek
value specified. To retrieve more documents, you should adjust thefetch_k
parameter accordingly [1].Here's how you can modify your code to set the
fetch_k
parameter: