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 FusedRankField structure
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Required | Fused document id. |
score | number | Required | Sum of weight / (k + rank) over contributing sources; higher is better. |
contributions | { sourceId: string; rank: number; weight: number; }[] | Required | Contributions in source order, using one-based ranks. |
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);