Skip to content
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

Add option to RetrievalQA chains to use provided documents in call() and acall() methods #11887

Closed
wants to merge 2 commits into from

Conversation

benchello
Copy link
Contributor

@benchello benchello commented Oct 16, 2023

Description

This PR adds an option to the RetrievalQA chains to use provided documents in _call() and_acall() methods like: qa_chain({"query": question, "from_documents": documents}) where documents is List[Document]

Currently there is no way to reuse documents found from a similarity_search in a RetrievalQA. This PR enables the following sequence:

  1. User embeds query and gets documents
  2. User implements desired logic based on documents
  3. User calls RetrievalQA without needing to re-embed query to find relevant documents.

This option will also be helpful if the user wants to gather documents in any custom way, like combining from different sources.

Usage

Example Usage:


qa_chain  =  RetrievalQA.from_chain_type(
     llm=llm,
     retriever=vector_store.as_retriever(),
)

documents = vector_store.similarity_search("Is the sky blue?")

if "blue" in documents[0].page_content:
	# Reuse documents in LLM call since they passed our condition
	response  =  qa_chain({"query": question, "from_documents": documents})
	
#True
response["source_documents"] == documents 

@vercel
Copy link

vercel bot commented Oct 16, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchain ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 17, 2023 0:31am

@dosubot dosubot bot added Ɑ: models Related to LLMs or chat model modules 🤖:improvement Medium size change to existing code to handle new use-cases labels Oct 16, 2023
@baskaryan
Copy link
Collaborator

if you're not retrieving documents do you need to use the RetrievalQA chain at all or can you just use the combine_documents_chain directly?

@benchello
Copy link
Contributor Author

Ah, sorry, I didn't see that as an option 😅 . Will close this and use that!

@benchello benchello closed this Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:improvement Medium size change to existing code to handle new use-cases Ɑ: models Related to LLMs or chat model modules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants