Class ReciprocalRankFusion

java.lang.Object
com.tnsai.memory.advanced.ReciprocalRankFusion

public final class ReciprocalRankFusion extends Object
Reciprocal Rank Fusion (RRF) for combining multiple ranked result lists.

RRF is a simple, parameter-light method for combining rankings. For each item, the fused score is the sum across all rankings of 1 / (k + rank), where rank is 1-based and k is a constant (default 60) that mitigates the impact of high rankings.

Reference: Cormack, Clarke & Buettcher, "Reciprocal Rank Fusion outperforms Condorcet and individual Rank Learning Methods", SIGIR 2009.

  • Field Details

    • DEFAULT_K

      public static final int DEFAULT_K
      Default k constant. 60 is the standard value from the RRF paper.
      See Also:
  • Constructor Details

    • ReciprocalRankFusion

      public ReciprocalRankFusion()
      Creates an RRF combiner with the default k=60.
    • ReciprocalRankFusion

      public ReciprocalRankFusion(int k)
      Creates an RRF combiner with a custom k value.
      Parameters:
      k - the rank constant (must be positive)
  • Method Details

    • fuse

      @SafeVarargs public final List<ScoredEntry> fuse(int topK, List<ScoredEntry>... rankedLists)
      Fuses multiple ranked lists into a single ranked list.

      Each input list should be sorted by relevance (most relevant first). The fused score for each entry is the sum of 1/(k+rank) across all lists where it appears.

      Parameters:
      topK - maximum number of results to return
      rankedLists - the ranked result lists to fuse
      Returns:
      fused and re-scored entries, sorted by descending fused score
    • fuseNormalized

      @SafeVarargs public final List<ScoredEntry> fuseNormalized(int topK, List<ScoredEntry>... rankedLists)
      Fuses ranked lists and normalizes the fused scores to 0.0..1.0.

      The normalization ceiling is the score an entry would receive at rank one in every non-empty input list: activeLists * (1 / (k + 1)). Empty lists therefore do not dilute the score, while an entry present at rank one in every active list receives 1.0. The public fuse(int, List[]) method keeps exposing raw RRF scores for callers that rely on the standard formula.

      Parameters:
      topK - maximum number of results to return
      rankedLists - the ranked result lists to fuse
      Returns:
      fused entries with bounded scores, sorted by descending score
    • k

      public int k()
      Returns the k constant used by this combiner.