reciprocalRankFusion
KIT · function · 运行时值
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.
导入
ts
import { reciprocalRankFusion } from '@jangts/agent-core/kits/rank-fusion';js
import { reciprocalRankFusion } from '@jangts/agent-core/kits/rank-fusion';其他公开入口:@jangts/agent-core/types、@jangts/agent-core/kits、@jangts/agent-core/kits/rank-fusion。
定义
调用
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.
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
lists | readonly RankedList[] | 必需 | — |
options | { limit: number; k?: number; } | 必需 | — |
options 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
limit | number | 必需 | 见类型定义及调用场景。 |
k | number | undefined | 可省略 | 见类型定义及调用场景。 |
返回: FusedRank[]。
使用示例
- Rank Fusion:按名次融合多个检索结果:融合全文与向量结果的名次,避免直接相加语义不同的原始分数。
先用默认融合参数
入门 · 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);