Skip to content
中文

Rank Fusion: fuse multiple retrieval results by rank ​

Fuse full-text and vector ranks instead of directly adding raw scores with different semantics.

reciprocalRankFusion(lists,{limit,k?}) returns {id,score,contributions}[]. Each source has a unique sourceId, ids in rank order, and an optional positive weight. The defaults are k=60 and weight=1; a contribution is weight/(k+rank), with rank starting at 1. A repeated ID within one source counts once. The total is ordered by score descending and then by id; limit is 1–1000.

The returned score is a fusion ordering value, not similarity, confidence, or factual correctness. Every source must apply the same permission filtering before fusion; fusion does not re-check whether the source data is visible.

Progressive examples for the same business case ​

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);

Policies & implementations ​

API reference, usage examples and developer guides.