Data Retrieval Chain
The Data Retrieval Chain lets you send a set of data items to a vector store, ask a question, and get back answers for each item. It’s useful when you need to process many records at once—like pulling insights from a large document collection or answering queries for a list of customer records.
How it Works
When you drop this component into your workflow, it takes the data you provide, splits it into batches if needed, and sends each batch to a vector store (the Retriever). The Model you choose then uses a prompt to ask a question about each batch. The component collects all the answers and returns them as a single output called Data. No external API calls are made beyond the vector store and the language model you selected.
Inputs
- Data: The raw data you want to ask questions about. It can be a single record or a list of records.
- Model: The language model that will generate answers for each batch (e.g., GPT‑4, Claude, etc.).
- Retriever: The vector store that holds the context needed to answer the questions. This must be a component that implements a retrieval interface.
- Check if value is array: If checked, the component will look at the Data input; if it’s a single string that contains a separator, it will split it into an array so each element can be processed separately.
- Separator for array: The character or string that separates items when Check if value is array is true (e.g.,
,
or|
). - Prompt: The text that will be sent to the language model for each batch.
Example default prompt:You are an assistant for question-answering tasks. Use the following pieces of retrieved context to answer the question. If you don't know the answer, just say that you don't know.Context: {context}Question: {question}Answer: - Source data input key: The key in each data record that should be appended to the question. For example, if your data records have a field called
description
, set this todescription
. - JSON Flatten: If true, nested JSON objects in the output will be flattened into a single level.
- JSON Mode: If true, the output will be formatted as JSON instead of plain text.
- Max Concurrency: The maximum number of parallel requests the component will send to the vector store and model. Higher values speed up processing but use more resources.
- Output key name: The name of the key that will hold the results in the output data structure. Default is
data
. - Question: The question you want the model to answer for each batch of data.
Outputs
- Data: A list (or JSON object if JSON Mode is true) containing the answers for each input record. Each answer is produced by the language model using the prompt and the context retrieved from the vector store.
Usage Example
- Add a Retriever – Connect a vector store component (e.g., Pinecone, Weaviate) that contains the documents you want to query.
- Add a Model – Choose a language model component (e.g., OpenAI GPT‑4).
- Add the Data Retrieval Chain –
- Set Data to the dataset you want to process.
- Set Question to something like “What is the main topic of this document?”
- Leave Check if value is array unchecked if your data is already an array.
- Use the default prompt or customize it to fit your needs.
- Adjust Max Concurrency to balance speed and resource usage.
- Connect the outputs – Use the Data output to feed into the next component, such as a summarizer or a storage component.
The component will batch the data, retrieve relevant context for each batch, ask the model the question, and return a structured list of answers.
Related Components
- Retriever – Provides the vector store that holds the context.
- Model – Supplies the language model that generates answers.
- Data Batch Retrieval Chain – The component described above.
Tips and Best Practices
- Batch wisely: If your data set is very large, set Max Concurrency to a moderate number (e.g., 5–10) to avoid overloading the model or vector store.
- Use JSON Mode when you need structured output that can be easily parsed by downstream components.
- Flatten JSON if you want to avoid nested structures in the output.
- Check if value is array is handy when you receive a single string that contains multiple items separated by a delimiter.
- Prompt design: Keep prompts concise and include placeholders (
{context}
,{question}
) so the model can focus on the task.
Security Considerations
- The component processes data locally within Nappai, but the vector store and language model may transmit data over the network.
- Ensure that your vector store is secured with proper authentication and that any sensitive data is encrypted at rest.
- If using a public language model, be aware that the prompt and retrieved context may be sent to the model provider. Review the provider’s privacy policy and consider using a private or on‑premise model if confidentiality is critical.