Skip to content
中文

FusedRank ​

KIT · interface · Type contract

One fused result with the per-source ranks that produced its score.

Import ​

ts
import type { FusedRank } from '@jangts/agent-core/kits/rank-fusion';
js
/** @typedef {import('@jangts/agent-core/kits/rank-fusion').FusedRank} FusedRank */

Other public entry points:@jangts/agent-core/types, @jangts/agent-core/kits, @jangts/agent-core/kits/rank-fusion.

Definition ​

ts
interface FusedRank

Field structure ​

FieldTypeRequiredDescription
idstringRequiredFused document id.
scorenumberRequiredSum of weight / (k + rank) over contributing sources; higher is better.
contributions{ sourceId: string; rank: number; weight: number; }[]RequiredContributions in source order, using one-based ranks.

Examples ​

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

API reference, usage examples and developer guides.