class_docstr: A component that joins input lists of Documents from multiple connections and outputs them as one list.
  
  The component allows multiple join modes:
  * concatenate: Combine Documents from multiple components. Discards duplicate Documents.
                  Documents get their scores from the last component in the pipeline that assigns scores.
                  This join mode doesn't influence Document scores.
  * merge: Merge scores of duplicate Documents coming from multiple components.
          Optionally, you can assign a weight to the scores and set the top_k limit for this join mode.
          You can also use this join mode to rerank retrieved Documents.
  * reciprocal_rank_fusion: Combine Documents into a single list based on their ranking received from multiple components.
  
  Example usage in a hybrid retrieval pipeline:
  ```python
  document_store = InMemoryDocumentStore()
  p = Pipeline()
  p.add_component(instance=InMemoryBM25Retriever(document_store=document_store), name="bm25_retriever")
  p.add_component(
          instance=SentenceTransformersTextEmbedder(model="sentence-transformers/all-MiniLM-L6-v2"),
          name="text_embedder",
      )
  p.add_component(instance=InMemoryEmbeddingRetriever(document_store=document_store), name="embedding_retriever")
  p.add_component(instance=DocumentJoiner(), name="joiner")
  p.connect("bm25_retriever", "joiner")
  p.connect("embedding_retriever", "joiner")
  p.connect("text_embedder", "embedding_retriever")
  query = "What is the capital of France?"
  p.run(data={"bm25_retriever": {"query": query},
              "text_embedder": {"text": query}})
  ```
class_docstr_tok: ["A","component","that","joins","input","lists","of","Documents","from","multiple","connections","and","outputs","them","as","one","list",".","The","component","allows","multiple","join","modes",":","*","concatenate",":","Combine","Documents","from","multiple","components",".","Discards","duplicate","Documents",".","Documents","get","their","scores","from","the","last","component","in","the","pipeline","that","assigns","scores",".","This","join","mode","does","n't","influence","Document","scores",".","*","merge",":","Merge","scores","of","duplicate","Documents","coming","from","multiple","components",".","Optionally",",","you","can","assign","a","weight","to","the","scores","and","set","the","top_k","limit","for","this","join","mode",".","You","can","also","use","this","join","mode","to","rerank","retrieved","Documents",".","*","reciprocal_rank_fusion",":","Combine","Documents","into","a","single","list","based","on","their","ranking","received","from","multiple","components",".","Example","usage","in","a","hybrid","retrieval","pipeline",":","``","`","python","document_store","=","InMemoryDocumentStore","(",")","p","=","Pipeline","(",")","p.add_component","(","instance=InMemoryBM25Retriever","(","document_store=document_store",")",",","name=","''","bm25_retriever","''",")","p.add_component","(","instance=SentenceTransformersTextEmbedder","(","model=","''","sentence-transformers\/all-MiniLM-L6-v2","''",")",",","name=","''","text_embedder","''",",",")","p.add_component","(","instance=InMemoryEmbeddingRetriever","(","document_store=document_store",")",",","name=","''","embedding_retriever","''",")","p.add_component","(","instance=DocumentJoiner","(",")",",","name=","''","joiner","''",")","p.connect","(","``","bm25_retriever","''",",","``","joiner","''",")","p.connect","(","``","embedding_retriever","''",",","``","joiner","''",")","p.connect","(","``","text_embedder","''",",","``","embedding_retriever","''",")","query","=","``","What","is","the","capital","of","France","?","''","p.run","(","data=","{","``","bm25_retriever","''",":","{","``","query","''",":","query","}",",","``","text_embedder","''",":","{","``","text","''",":","query","}","}",")","``","`"]
docstr: Initialize the DocumentJoiner.
  
  :param join_mode: Specifies the join mode to use. Available modes: `concatenate` to combine Documents from multiple Retrievers, `merge` to aggregate the scores of
                    individual Documents, `reciprocal_rank_fusion` to apply rank-based scoring.
  :param weights: A component-wise list (the length of the list must be equal to the number of input components) of weights for
                  adjusting Document scores when using the `merge` join_mode. By default, equal weight is given
                  to each Retriever score. This param is not compatible with the `concatenate` join_mode.
  :param top_k: The maximum number of Documents to be returned as output. By default, returns all Documents.
  :param sort_by_score: Whether the output list of Documents should be sorted by Document scores in descending order.
                        By default, the output is sorted.
                        Documents without score are handled as if their score was -infinity.
docstr_tok: ["Initialize","the","DocumentJoiner",".",":","param","join_mode",":","Specifies","the","join","mode","to","use",".","Available","modes",":","`","concatenate","`","to","combine","Documents","from","multiple","Retrievers",",","`","merge","`","to","aggregate","the","scores","of","individual","Documents",",","`","reciprocal_rank_fusion","`","to","apply","rank-based","scoring",".",":","param","weights",":","A","component-wise","list","(","the","length","of","the","list","must","be","equal","to","the","number","of","input","components",")","of","weights","for","adjusting","Document","scores","when","using","the","`","merge","`","join_mode",".","By","default",",","equal","weight","is","given","to","each","Retriever","score",".","This","param","is","not","compatible","with","the","`","concatenate","`","join_mode",".",":","param","top_k",":","The","maximum","number","of","Documents","to","be","returned","as","output",".","By","default",",","returns","all","Documents",".",":","param","sort_by_score",":","Whether","the","output","list","of","Documents","should","be","sorted","by","Document","scores","in","descending","order",".","By","default",",","the","output","is","sorted",".","Documents","without","score","are","handled","as","if","their","score","was","-infinity","."]
code: def __init__(
      self,
      join_mode: str = "concatenate",
      weights: Optional[List[float]] = None,
      top_k: Optional[int] = None,
      sort_by_score: bool = True,
  ):
      """
      Initialize the DocumentJoiner.
  
      :param join_mode: Specifies the join mode to use. Available modes: `concatenate` to combine Documents from multiple Retrievers, `merge` to aggregate the scores of
                        individual Documents, `reciprocal_rank_fusion` to apply rank-based scoring.
      :param weights: A component-wise list (the length of the list must be equal to the number of input components) of weights for
                      adjusting Document scores when using the `merge` join_mode. By default, equal weight is given
                      to each Retriever score. This param is not compatible with the `concatenate` join_mode.
      :param top_k: The maximum number of Documents to be returned as output. By default, returns all Documents.
      :param sort_by_score: Whether the output list of Documents should be sorted by Document scores in descending order.
                            By default, the output is sorted.
                            Documents without score are handled as if their score was -infinity.
      """
      if join_mode not in [
          "concatenate",
          "merge",
          "reciprocal_rank_fusion",
      ]:
          raise ValueError(
              f"DocumentJoiner component does not support '{join_mode}' join_mode."
          )
      self.join_mode = join_mode
      self.weights = (
          [float(i) / sum(weights) for i in weights]
          if weights
          else None
      )
      self.top_k = top_k
      self.sort_by_score = sort_by_score
  
file_path: haystack/haystack/components/joiners/document_joiner.py
imports: import itertools
  import logging
  from collections import defaultdict
  from math import inf
  from typing import List, Optional
  from haystack.core.component.types import Variadic
  from haystack import component, Document
label_desc: Use image node_id 1 to create a new DocumentJoiner object  with example: obj = DocumentJoiner(join_mode, weights, top_k, sort_by_score)