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

AnswerJoiner

Use AnswerJoiner to merge multiple lists of Answer objects from different pipeline branches into a single list.

Key Features

  • Merges multiple answer lists from different branches into one output
  • Supports CONCATENATE join mode to append all answers in order
  • Optionally limits the output to the top K answers by score
  • Accepts variadic inputs — connect as many answer sources as needed

Configuration

  1. Drag the AnswerJoiner component onto the canvas from the Component Library.
  2. Click the component to open the configuration panel.
  3. Configure the parameters as needed.

Connections

AnswerJoiner accepts multiple List[Answer] inputs — connect it to any number of AnswerBuilder components to combine their outputs. It sends the merged list of answers to the Output component or any downstream component that accepts answers.

Usage Example

This example shows a pipeline that generates answers from multiple sources and joins them.

components:
PromptBuilder1:
type: haystack.components.builders.prompt_builder.PromptBuilder
init_parameters:
template: "Answer this question briefly: {{ query }}"
PromptBuilder2:
type: haystack.components.builders.prompt_builder.PromptBuilder
init_parameters:
template: "Provide a detailed answer to: {{ query }}"
Generator1:
type: haystack.components.generators.openai.OpenAIGenerator
init_parameters:
api_key:
type: env_var
env_vars:
- OPENAI_API_KEY
strict: false
model: gpt-4o-mini
Generator2:
type: haystack.components.generators.openai.OpenAIGenerator
init_parameters:
api_key:
type: env_var
env_vars:
- OPENAI_API_KEY
strict: false
model: gpt-4o-mini
AnswerBuilder1:
type: haystack.components.builders.answer_builder.AnswerBuilder
init_parameters:
pattern:
reference_pattern:
last_message_only: false
return_only_referenced_documents: true
AnswerBuilder2:
type: haystack.components.builders.answer_builder.AnswerBuilder
init_parameters:
pattern:
reference_pattern:
last_message_only: false
return_only_referenced_documents: true
AnswerJoiner:
type: haystack.components.joiners.answer_joiner.AnswerJoiner
init_parameters:
join_mode: concatenate
sort_by_score: false

connections:
- sender: PromptBuilder1.prompt
receiver: Generator1.prompt
- sender: PromptBuilder2.prompt
receiver: Generator2.prompt
- sender: Generator1.replies
receiver: AnswerBuilder1.replies
- sender: Generator2.replies
receiver: AnswerBuilder2.replies
- sender: AnswerBuilder1.answers
receiver: AnswerJoiner.answers
- sender: AnswerBuilder2.answers
receiver: AnswerJoiner.answers

max_runs_per_component: 100

metadata: {}

inputs:
query:
- PromptBuilder1.query
- PromptBuilder2.query
- AnswerBuilder1.query
- AnswerBuilder2.query

outputs:
answers: AnswerJoiner.answers

Parameters

Inputs

ParameterTypeDefaultDescription
answersVariadic[List[AnswerType]]Nested list of Answers to be merged.
top_kOptional[int]NoneThe maximum number of Answers to return. Overrides the instance's top_k if provided.

Outputs

ParameterTypeDefaultDescription
answersList[AnswerType]Merged list of Answers.

Init Parameters

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
join_modeUnion[str, JoinMode]JoinMode.CONCATENATESpecifies the join mode to use. Available modes: concatenate concatenates multiple lists of Answers into a single list.
top_kOptional[int]NoneThe maximum number of Answers to return.
sort_by_scoreboolFalseIf True, sorts the answers by score in descending order. If an answer has no score, it is handled as if its score is -infinity.

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
answersVariadic[List[AnswerType]]Nested list of Answers to be merged.
top_kOptional[int]NoneThe maximum number of Answers to return. Overrides the instance's top_k if provided.