reciprocalRankFusion
KIT · function · Runtime value
Fuse ranked lists with one-based reciprocal rank fusion.
Raw retriever scores are intentionally not mixed. Ties break on id, so the output is deterministic for a given input.
Import
ts
import { reciprocalRankFusion } from '@jangts/agent-core/kits/rank-fusion';js
import { reciprocalRankFusion } from '@jangts/agent-core/kits/rank-fusion';Other public entry points:@jangts/agent-core/types, @jangts/agent-core/kits, @jangts/agent-core/kits/rank-fusion.
Definition
Call
ts
reciprocalRankFusion(lists: readonly RankedList[], options: { limit: number; k?: number; }): FusedRank[]Fuse ranked lists with one-based reciprocal rank fusion.
Raw retriever scores are intentionally not mixed. Ties break on id, so the output is deterministic for a given input.
| Parameter | Type | Passing | Description |
|---|---|---|---|
lists | readonly RankedList[] | Required | — |
options | { limit: number; k?: number; } | Required | — |
Fields of options
| Field | Type | Required | Description |
|---|---|---|---|
limit | number | Required | See the type definition and usage context. |
k | number | undefined | Optional | See the type definition and usage context. |
Returns: FusedRank[].
Examples
- Rank Fusion: fuse multiple retrieval results by rank: Fuse full-text and vector ranks instead of directly adding raw scores with different semantics.
First use the default fusion parameters
Beginner · Node.js
ts
import { reciprocalRankFusion } from '@jangts/agent-core/kits/rank-fusion';
const result = reciprocalRankFusion([
{ sourceId: 'text', ids: ['workflow', 'model'] },
{ sourceId: 'vector', ids: ['model', 'workflow'] },
], { limit: 5 });
console.log(result);js
import { reciprocalRankFusion } from '@jangts/agent-core/kits/rank-fusion';
const result = reciprocalRankFusion([
{ sourceId: 'text', ids: ['workflow', 'model'] },
{ sourceId: 'vector', ids: ['model', 'workflow'] },
], { limit: 5 });
console.log(result);Add source weights and the smoothing parameter to the same function
Configuration · Node.js
ts
import { reciprocalRankFusion } from '@jangts/agent-core/kits/rank-fusion';
const result = reciprocalRankFusion([
{ sourceId: 'text', ids: ['workflow', 'model'], weight: 2 },
{ sourceId: 'vector', ids: ['model', 'workflow'], weight: 1 },
], { limit: 2, k: 30 });
console.log(result[0].contributions);js
import { reciprocalRankFusion } from '@jangts/agent-core/kits/rank-fusion';
const result = reciprocalRankFusion([
{ sourceId: 'text', ids: ['workflow', 'model'], weight: 2 },
{ sourceId: 'vector', ids: ['model', 'workflow'], weight: 1 },
], { limit: 2, k: 30 });
console.log(result[0].contributions);