Function: fuseRankedLists()
fuseRankedLists(
lists,options?):FusedDoc[]
Defined in: packages/agentos/src/cognition/memory/retrieval/hybrid/reciprocalRankFusion.ts:164
Reciprocal Rank Fusion over any number of weighted ranked lists:
score(d) = Σ weight_i / (k + rank_i(d))
A list that holds an id twice counts it once, at its first rank. A list of weight 0 adds its ids at no score and moves no other score. With two lists of weights 0.7 and 0.3, and no id repeated within a list, it equals reciprocalRankFusion id for id and score for score.
Parameters
lists
readonly object[]
The ranked lists (1-based ranks) and their weights.
options?
k?
number
Smoothing constant (default 60).
Returns
FusedDoc[]
Sorted by score descending, equal scores by id ascending.
Example
fuseRankedLists([
{ ranked: [{ id: 'a', rank: 1 }, { id: 'b', rank: 2 }], weight: 0.7 },
{ ranked: [{ id: 'b', rank: 1 }], weight: 0.3 },
]);
// => [{ id: 'b', score: 0.0162, ranks: [2, 1] }, { id: 'a', score: 0.0115, ranks: [1, undefined] }]