Class ReciprocalRankFuser

java.lang.Object
dev.langchain4j.rag.content.aggregator.ReciprocalRankFuser

public class ReciprocalRankFuser extends Object
Implementation of Reciprocal Rank Fusion.
A comprehensive explanation can be found here.
  • Constructor Details

    • ReciprocalRankFuser

      public ReciprocalRankFuser()
  • Method Details

    • fuse

      public static List<Content> fuse(Collection<List<Content>> listsOfContents)
      Fuses multiple List<Content> into a single List<Content> using the Reciprocal Rank Fusion (RRF) algorithm with k=60.
      Parameters:
      listsOfContents - A Collection of List<Content> to be fused together.
      Returns:
      A single List<Content>, the result of the fusion.
    • fuse

      public static List<Content> fuse(Collection<List<Content>> listsOfContents, int k)
      Fuses multiple List<Content> into a single List<Content> using the Reciprocal Rank Fusion (RRF) algorithm.
      Parameters:
      listsOfContents - A Collection of List<Content> to be fused together.
      k - A ranking constant used to control the influence of individual ranks from different ranked lists being combined. A common value used is 60, based on empirical studies. However, the optimal value may vary depending on the specific application and the characteristics of the data. A larger value diminishes the differences between the ranks, leading to a more uniform distribution of fusion scores. A smaller value amplifies the importance of the top-ranked items in each list. K must be greater than or equal to 1.
      Returns:
      A single List<Content>, the result of the fusion.