Skip to content
English

FusedRank ​

KIT · interface · 类型合同

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

导入 ​

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

其他公开入口:@jangts/agent-core/types、@jangts/agent-core/kits、@jangts/agent-core/kits/rank-fusion。

定义 ​

ts
interface FusedRank

字段结构 ​

字段类型必需说明
idstring必需Fused document id.
scorenumber必需Sum of weight / (k + rank) over contributing sources; higher is better.
contributions{ sourceId: string; rank: number; weight: number; }[]必需Contributions in source order, using one-based ranks.

使用示例 ​

先用默认融合参数 ​

入门 · 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);

相同函数增加来源权重与平滑参数 ​

配置 · 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);

相关策略源码 ​

接口参考、使用示例与开发指南。