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 Haystack Platform interface.

Key Features

  • Converts Generator replies into GeneratedAnswer objects with document references.
  • Adds references to the answer's _references metadata field for display in the Haystack Platform interface.
  • Supports configurable reference patterns, including the acm shortcut.
  • Optionally extracts content from XML tags in the Generator's reply.
  • Accepts documents from rankers and attaches them to generated answers.
  • Works with both Generators and Chat Generators.

Configuration

  1. Drag the DeepsetAnswerBuilder component onto the canvas from the Component Library.
  2. Click on the component to open the configuration panel.
  3. Configure the component settings:
    • Optionally enter a reference_pattern to parse document references from the Generator's replies. You can use the shortcut acm for the pattern \[(?:(\d+),?\s*)+\].
    • Optionally enter a pattern to extract a specific portion of the Generator's reply as the answer text.
    • Optionally set extract_xml_tags to extract content from specific XML tags in the reply.

Connections

DeepsetAnswerBuilder receives the user query from the pipeline Input or another component, and it receives replies from a Generator. It also optionally receives documents from a ranker to attach them to generated answers.

Connect its answers output to the pipeline Output component to surface the final answers with references.

Usage Examples

Basic Configuration

  DeepsetAnswerBuilder:
type: deepset_cloud_custom_nodes.augmenters.deepset_answer_builder.DeepsetAnswerBuilder
init_parameters: {}

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.
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

ParameterTypeDescription
answersList[GeneratedAnswer]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 from.

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.