DocumentationAPI ReferenceπŸ““ TutorialsπŸ§‘β€πŸ³ Cookbook🀝 IntegrationsπŸ’œ Discord

JoinAnswers

The JoinAnswers node takes Answers from two or more Reader or Generator nodes and joins them to produce a single list of Answers. Learn when it's best to use it and how.

Position in a PipelineJoins the output of two or more nodes that return Answers
InputAnswers
OutputAnswers
ClassesJoinAnswers

Usage

To initialize the node, run:

from haystack.nodes import JoinAnswers

join_answers = JoinAnswers(
    join_mode="concatenate",
    sort_by_score=True
)

There are two available join modes:

  • concatenate: Combines documents from multiple readers
  • merge: Aggregates scores of individual answers. If you use this option, you can also specify the weights parameter which assigns importance to the input nodes. By default, all nodes are assigned equal weight.

Optionally, you can use the top_k parameter to specify the number of answers to be displayed.

πŸ‘

Note

Answers coming from a Generator have no score. You will need to set sort_by_score=False to join these with Answers coming from other sources.

To use the node in a pipeline, run:

from haystack.pipelines import Pipeline
from haystack.nodes import JoinAnswers, TableTextRetriever, RouteDocuments, TextReader, TableReader

join_answers = JoinAnswers(
    join_mode="concatenate",
    top_k_join=10
)

pipeline = Pipeline()
pipeline.add_node(component=table_retriever, name="TableTextRetriever", inputs=["Query"])
pipeline.add_node(component=route_docs, name="RouteDocuments", inputs=["TableTextRetriever"])
pipeline.add_node(component=text_reader, name="TextReader", inputs=["RouteDocuments.output_1"])
pipeline.add_node(component=table_reader, name="TableReader", inputs=["RouteDocuments.output_2"])
pipeline.add_node(component=join_answers, name="JoinAnswers",
              inputs=["TextReader", "TableReader"])
res = pipe.run(query="What did Einstein work on?")

Use Case

A typical use case for JoinAnswers is as follows:

  • Your Documents contain different types of data, for example tables and text.
  • You use the RouteDocuments node to split your documents by content type.
  • You use a different Reader for each document type and you get predicted Answers form each Reader separately.
  • You use the JoinAnswers node to join the Answers in a single list.

Here's what an example pipeline with the JoinAnswers node could look like:

1500

A pipeline with two Readers coordinated by a JoinAnswers node.


Related Links