Skip to main content
For the complete documentation index for agents and LLMs, see llms.txt.

DeepsetAnswerBuilder

Convert Generator replies into GeneratedAnswer objects with document references that you can visualize in the deepset AI Platform interface.

Key Features

  • Attaches document references to generated answers for display in the platform UI
  • Supports a convenient shortcut acm for common reference patterns
  • Optionally extracts content from XML tags in Generator replies
  • Works with any Generator that produces text replies
  • Supports custom regex patterns for answer and reference extraction
  • Adds prompt metadata to answers for traceability

Configuration

  1. Drag the DeepsetAnswerBuilder component onto the canvas from the Component Library.
  2. Click the component to open the configuration panel.
  3. Configure the parameters as needed. Set reference_pattern to match the reference format used in your Generator's prompt. Use the acm shortcut for the common [1, 2] format.

Connections

DeepsetAnswerBuilder accepts a query string, Generator replies, and optionally documents, metadata, and a prompt as input. It outputs a list of GeneratedAnswer objects with references attached. It typically receives documents from a Ranker and replies from a Generator. Because it needs the query but doesn't receive it from a connected component, list it explicitly in the inputs section of your pipeline YAML.

Usage Example

Using the Component in a Pipeline

In this example, DeepsetAnswerBuilder receives documents from the Ranker so that it can attach these documents to the generated answers, and it receives replies from the Generator so that it can convert them into the GeneratedAnswer objects with references that the deepset AI Platform interface can display.

query_yaml: |
components:
# ...
ranker:
type: haystack.components.rankers.transformers_similarity.TransformersSimilarityRanker
init_parameters:
model: "svalabs/cross-electra-ms-marco-german-uncased"
top_k: 8
device: null
model_kwargs:
torch_dtype: "torch.float16"

generator:
type: haystack.components.generators.openai.OpenAIGenerator
init_parameters:
api_key: {"type": "env_var", "env_vars": ["OPENAI_API_KEY"], "strict": False}
model: "gpt-4-turbo-preview"
generation_kwargs:
max_tokens: 400
temperature: 0.0
seed: 0

answer_builder:
type: deepset_cloud_custom_nodes.augmenters.deepset_answer_builder.DeepsetAnswerBuilder
init_parameters:
reference_pattern: acm

connections: # Defines how the components are connected
# ...
- sender: ranker.documents
receiver: answer_builder.documents # DeepsetAnswerBuilder receives documents from ranker
- sender: generator.replies
receiver: answer_builder.replies # DeepsetAnswerBuilder receives replies from the generator

inputs:
query:
# ...
- "ranker.query"
- "answer_builder.query" # We're listing AnswerBuilder here because it needs "query" as input
# and it's not getting it from any other component it's connected to.
# This means AnswerBuilder will receive "query" as input from the pipeline.

outputs:
answers: "answer_builder.answers" # This means we want AnswerBuilder's answers to be the output of the pipeline

Parameters

Inputs

ParameterTypeDefaultDescription
querystrThe query used in the prompts for the Generator. If DeepsetAnswerBuilder doesn't receive the query from a component it's connected to, you must list it in the inputs section of the pipeline YAML under query. You can see an example in the Usage Examples section below.
repliesList[str]The output of the Generator.
metaOptional[List[Dict[str, Any]]]NoneThe metadata returned by the Generator. If not specified, the generated answer contains no metadata.
documentsOptional[List[Document]]NoneThe documents used as input to the Generator. If documents are specified, they are added to the Answer objects. If both documents and reference_pattern are specified, the documents referenced in the Generator's output are extracted from the input documents and added to the Answer objects.
patternOptional[str]NoneThe regular expression pattern to use to extract the answer text from the generator output. If not specified, the whole string is used as the answer. The regular expression can have at most one capture group. If a capture group is present, the text matched by the capture group is used as the answer. If no capture group is present, the whole match is used as the answer. Examples: [^\n]+$ finds "this is an answer" in a string "this is an argument.\nthis is an answer". Answer: (.*) finds "this is an answer" in a string "this is an argument. Answer: this is an answer".
reference_patternOptional[str]NoneThe regular expression pattern to use for parsing the document references. It's assumed that references are specified as indices of the input documents and that indices start at 1. Example: \[(\d+)\] finds "1" in a string "this is an answer[1]". If not specified, no parsing is done, and all documents are referenced. You can use the following shortcuts: - "acm": \[(?:(\d+),?\s*)+\] finds "1" and "2" in a string "this is an answer[1, 2]".
promptOptional[str]NoneThe prompt used in the Generator. If specified, it is added to the metadata of the Answer objects.

Outputs

ParameterTypeDefaultDescription
answersList[GeneratedAnswer]A dictionary with the following keys: - answers: The answers obtained from the output of the Generator

Init Parameters

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
patternOptional[str]NoneThe regular expression pattern to use to extract the answer text from the generator output. If not specified, the whole string is used as the answer. The regular expression can have at most one capture group. If a capture group is present, the text matched by the capture group is used as the answer. If no capture group is present, the whole match is used as the answer. Examples: [^\n]+$ finds "this is an answer" in a string "this is an argument.\nthis is an answer". Answer: (.*) finds "this is an answer" in a string "this is an argument. Answer: this is an answer".
reference_patternOptional[str]NoneThe regular expression pattern to use for parsing the document references. We assume that references are specified as indices of the input documents and that indices start at 1. Example: \[(\d+)\] finds "1" in a string "this is an answer[1]". If not specified, no parsing is done, and all documents are referenced. You can use the following shortcuts: - "acm": \[(?:(\d+),?\s*)+\] finds "1" and "2" in a string "this is an answer[1, 2]".
extract_xml_tagsOptional[List[str]]NoneA list of XML tags to extract content

Run Method Parameters

These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.

ParameterTypeDefaultDescription
querystrThe query used in the prompts for the Generator.
repliesList[str]The output of the Generator.
metaOptional[List[Dict[str, Any]]]NoneThe metadata returned by the Generator. If not specified, the generated answer will contain no metadata.
documentsOptional[List[Document]]NoneThe documents used as input to the Generator. If documents are specified, they are added to the Answer objects. If both documents and reference_pattern are specified, the documents referenced in the Generator output are extracted from the input documents and added to the Answer objects.
patternOptional[str]NoneThe regular expression pattern to use to extract the answer text from the generator output. If not specified, the whole string is used as the answer. The regular expression can have at most one capture group. If a capture group is present, the text matched by the capture group is used as the answer. If no capture group is present, the whole match is used as the answer. Examples: [^\n]+$ finds "this is an answer" in a string "this is an argument.\nthis is an answer". Answer: (.*) finds "this is an answer" in a string "this is an argument. Answer: this is an answer".
reference_patternOptional[str]NoneThe regular expression pattern to use for parsing the document references. We assume that references are specified as indices of the input documents and that indices start at 1. Example: \[(\d+)\] finds "1" in a string "this is an answer[1]". If not specified, no parsing is done, and all documents are referenced. You can use the following shortcuts: - "acm": \[(?:(\d+),?\s*)+\] finds "1" and "2" in a string "this is an answer[1, 2]".
promptOptional[str]NoneThe prompt used in the Generator. If specified, it is added to the metadata of the Answer objects.