RankedList
KIT · interface · 类型合同
One retriever's ordered result, optionally weighted.
导入
ts
import type { RankedList } from '@jangts/agent-core/kits/rank-fusion';js
/** @typedef {import('@jangts/agent-core/kits/rank-fusion').RankedList} RankedList */其他公开入口:@jangts/agent-core/types、@jangts/agent-core/kits、@jangts/agent-core/kits/rank-fusion。
定义
ts
interface RankedList字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
sourceId | string | 必需 | 只读。Unique source name; duplicate names are rejected because they would double-count. |
ids | readonly string[] | 必需 | 只读。Ids in descending relevance; duplicates inside one list are ignored after the first. |
weight | number | undefined | 可省略 | 只读。Relative source weight, strictly positive; defaults to 1. |
使用示例
- 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);