defaults to 20.lambda_mult controls the diversity of results returned by the MMR algorithm, with 1 being minimum diversity and 0 being maximum. Defaults to 0.5.filter allows you to define a filter on what documents should be retrieved, based on the documents' metadata. This has no effect if the Vectorstore doesn't store any metadata.Some examples for how these parameters can be used:# Retrieve more documents with higher diversity- useful if your dataset has many similar documentsdocsearch.as_retriever(search_type="mmr", search_kwargs={'k': 6, 'lambda_mult': 0.25})# Fetch more documents for the MMR algorithm to consider, but only return the top 5docsearch.as_retriever(search_type="mmr", search_kwargs={'k': 5, 'fetch_k': 50})# Only retrieve documents that have a relevance score above a certain thresholddocsearch.as_retriever(search_type="similarity_score_threshold", search_kwargs={'score_threshold': 0.8})# Only get the single most similar document from the datasetdocsearch.as_retriever(search_kwargs={'k': 1})# Use a filter to only retrieve documents from a specific paperdocsearch.as_retriever(search_kwargs={'filter': {'paper_title':'GPT-4 Technical Report'}})Return Source Documents‚ÄãAdditionally, we can return the source documents used to answer the question by specifying an optional parameter when constructing the chain.qa = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type="stuff", retriever=docsearch.as_retriever(search_type="mmr", search_kwargs={'fetch_k': 30}), return_source_documents=True)query = "What did the president say about Ketanji Brown Jackson"result = qa({"query": query})result["result"]    " The president said that Ketanji Brown Jackson is one of the nation's top legal minds, a former top litigator in private practice and a former federal public defender from a family of public school educators and police officers, and that she has received a broad range of support from the Fraternal Order of Police to former judges appointed by Democrats and
This example showcases question answering over an index.
This example showcases question answering over an index. ->: defaults to 20.lambda_mult controls the diversity of results returned by the MMR algorithm, with 1 being minimum diversity and 0 being maximum. Defaults to 0.5.filter allows you to define a filter on what documents should be retrieved, based on the documents' metadata. This has no effect if the Vectorstore doesn't store any metadata.Some examples for how these parameters can be used:# Retrieve more documents with higher diversity- useful if your dataset has many similar documentsdocsearch.as_retriever(search_type="mmr", search_kwargs={'k': 6, 'lambda_mult': 0.25})# Fetch more documents for the MMR algorithm to consider, but only return the top 5docsearch.as_retriever(search_type="mmr", search_kwargs={'k': 5, 'fetch_k': 50})# Only retrieve documents that have a relevance score above a certain thresholddocsearch.as_retriever(search_type="similarity_score_threshold", search_kwargs={'score_threshold': 0.8})# Only get the single most similar document from the datasetdocsearch.as_retriever(search_kwargs={'k': 1})# Use a filter to only retrieve documents from a specific paperdocsearch.as_retriever(search_kwargs={'filter': {'paper_title':'GPT-4 Technical Report'}})Return Source Documents‚ÄãAdditionally, we can return the source documents used to answer the question by specifying an optional parameter when constructing the chain.qa = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type="stuff", retriever=docsearch.as_retriever(search_type="mmr", search_kwargs={'fetch_k': 30}), return_source_documents=True)query = "What did the president say about Ketanji Brown Jackson"result = qa({"query": query})result["result"]    " The president said that Ketanji Brown Jackson is one of the nation's top legal minds, a former top litigator in private practice and a former federal public defender from a family of public school educators and police officers, and that she has received a broad range of support from the Fraternal Order of Police to former judges appointed by Democrats and