下边通过一个简单的例子说明不同检索方式的分值变化过程,假设我们有一个查询:“如何使用Python进行数据分析”
向量检索结果 (相似度分数0-1):
1. {
id: "doc1",
q: "Python数据分析基础教程",
score: 0.85,
type: "embedding"
}
2. {
id: "doc2",
q: "数据分析工具pandas使用",
score: 0.78,
type: "embedding"
}
全文检索结果 (BM25分数):
1. {
id: "doc2",
q: "数据分析工具pandas使用",
score: 8.5,
type: "fullText"
}
2. {
id: "doc3",
q: "Python编程基础",
score: 6.2,
type: "fullText"
}
使用公式: score = 1/(k + rank)
,这里 k=60
向量检索RRF分数:
doc1: 1/(60 + 1) = 0.0164
doc2: 1/(60 + 2) = 0.0161
全文检索RRF分数:
doc2: 1/(60 + 1) = 0.0164
doc3: 1/(60 + 2) = 0.0161
1. {
id: "doc2", // 出现在两个结果中
q: "数据分析工具pandas使用",
score: [
{type: "embedding", value: 0.78},
{type: "fullText", value: 8.5},
{type: "rrf", value: 0.0325} // 0.0161 + 0.0164
]
}
2. {
id: "doc1",
q: "Python数据分析基础教程",
score: [
{type: "embedding", value: 0.85},
{type: "rrf", value: 0.0164}
]
}
3. {
id: "doc3",
q: "Python编程基础",
score: [
{type: "fullText", value: 6.2},
{type: "rrf", value: 0.0161}
]
}
假设重排序模型对这些文档评分:
1. {
id: "doc2",
q: "数据分析工具pandas使用",
score: [
{type: "embedding", value: 0.78},
{type: "fullText", value: 8.5},
{type: "rrf", value: 0.0325},
{type: "rerank", value: 0.92}
]
}
2. {
id: "doc1",
q: "Python数据分析基础教程",
score: [
{type: "embedding", value: 0.85},
{type: "rrf", value: 0.0164},
{type: "rerank", value: 0.88}
]
}
3. {
id: "doc3",
q: "Python编程基础",
score: [
{type: "fullText", value: 6.2},
{type: "rrf", value: 0.0161},
{type: "rerank", value: 0.75}
]
}
将重排序结果作为第三个来源(k=58)进行最终 RRF 合并:
doc2: 0.0325 + 1/(58 + 1) = 0.0325 + 0.0169 = 0.0494
doc1: 0.0164 + 1/(58 + 2) = 0.0164 + 0.0167 = 0.0331
doc3: 0.0161 + 1/(58 + 3) = 0.0161 + 0.0164 = 0.0325
展示如下环节:
文档排序综合考虑: