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字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
id | string | 必需 | Fused document id. |
score | number | 必需 | 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. |
使用示例
- 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);