import RetrievalQAExample from "@examples/chains/retrieval_qa.ts";
import RetrievalQAExampleCustom from "@examples/chains/retrieval_qa_custom.ts";
import RetrievalQAExampleCustomPrompt from "@examples/chains/retrieval_qa_custom_prompt.ts";
import CodeBlock from "@theme/CodeBlock";

The `RetrievalQAChain` is a chain that combines a `Retriever` and a QA chain (described above). It is used to retrieve documents from a `Retriever` and then use a `QA` chain to answer a question based on the retrieved documents.

## Usage

In the below example, we are using a `VectorStore` as the `Retriever`. By default, the `StuffDocumentsChain` is used as the `QA` chain.

<CodeBlock language="typescript">{RetrievalQAExample}</CodeBlock>

## Custom `QA` chain

In the below example, we are using a `VectorStore` as the `Retriever` and a `MapReduceDocumentsChain` as the `QA` chain.

<CodeBlock language="typescript">{RetrievalQAExampleCustom}</CodeBlock>

## Custom prompts

You can pass in custom prompts to do question answering. These prompts are the same prompts as you can pass into the base question answering chains.

<CodeBlock language="typescript">{RetrievalQAExampleCustomPrompt}</CodeBlock>
