Retrieval QA Chain
The Retrieval QA Chain is a powerful question-answering system that combines document retrieval with language model processing to provide accurate answers based on a given knowledge base.
Node Details
- Name:
retrievalQAChain
- Type:
RetrievalQAChain
- Category: [[Chains]]
- Version: 2.0
Parameters
-
Language Model (Required)
- Type: BaseLanguageModel
- Description: The language model used for generating answers.
-
Vector Store Retriever (Required)
- Type: BaseRetriever
- Description: The retriever used to fetch relevant documents from a vector store.
-
Return Source Documents (Optional)
- Type: boolean
- Description: Whether to return the source documents used to generate the answer.
-
System Message (Optional)
- Type: string
- Description: Custom system message to set the behavior of the AI assistant.
- Default: A predefined system message template.
- Rows: 4
- Additional Params: true
-
Chain Option (Optional)
- Type: string
- Options: [“stuff”, “map_reduce”, “refine”]
- Description: The method used to process retrieved documents.
- Default: “stuff”
- Additional Params: true
-
Input Moderation (Optional)
- Type: Moderation[]
- Description: Moderation tools to detect and prevent harmful input.
- List: true
Input
- A string containing the user’s question or query.
Output
- If
Return Source Documents
is false:- A string containing the answer to the user’s question.
- If
Return Source Documents
is true:- An object containing:
text
: The answer to the user’s question.sourceDocuments
: An array of documents used to generate the answer.
- An object containing:
How It Works
- The chain receives a user question.
- If input moderation is enabled, it checks the input for potential harmful content.
- The vector store retriever fetches relevant documents based on the question.
- Depending on the chosen Chain Option:
- “stuff”: Combines all retrieved documents into a single context.
- “map_reduce”: Processes each document separately and then combines the results.
- “refine”: Iteratively refines the answer using each document.
- The language model generates an answer based on the processed documents and the original question.
- The answer (and optionally source documents) is returned as output.
Use Cases
- Building question-answering systems based on specific knowledge bases
- Creating AI assistants with access to large document repositories
- Implementing intelligent search functionality for databases or document collections
- Developing automated customer support systems with access to product documentation
- Creating educational tools that can answer questions based on course materials
Special Features
- Flexible Retrieval: Uses vector store for efficient and relevant document retrieval.
- Multiple Processing Options: Supports different methods for handling retrieved documents.
- Source Attribution: Option to return source documents for transparency.
- Customizable System Message: Allows fine-tuning of AI behavior.
- Input Moderation: Can implement safeguards against inappropriate or harmful inputs.
- Scalability: Can handle large document collections efficiently.
Notes
- The quality of answers depends on both the underlying language model and the relevance of retrieved documents.
- The choice of Chain Option can significantly impact performance and accuracy for different types of queries.
- Custom system messages can be used to guide the AI’s behavior and response style.
- The chain supports streaming responses for real-time interaction in compatible environments.
- Proper error handling and input validation should be implemented for production use.
- The effectiveness of the chain can vary depending on the quality and organization of the knowledge base.
The Retrieval QA Chain node provides a robust solution for building AI-powered question-answering systems with access to large document repositories. By combining efficient document retrieval with advanced language model processing, it enables the creation of intelligent systems that can provide accurate, context-aware answers to user queries. This node is particularly valuable in scenarios where answers need to be derived from a specific body of knowledge, such as in specialized customer support, educational platforms, or domain-specific research tools.