文章目錄
- FastGPT 引申:混合檢索完整實例
- 1. 各檢索方式的初始結果
- 2. RRF合并過程
- 3. 合并后的結果
- 4. Rerank重排序后
- 5. 最終RRF合并
- 6. 內容總結
FastGPT 引申:混合檢索完整實例
下邊通過一個簡單的例子說明不同檢索方式的分值變化過程,假設我們有一個查詢:“如何使用Python進行數據分析”
1. 各檢索方式的初始結果
向量檢索結果 (相似度分數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"
}
2. RRF合并過程
使用公式: 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
3. 合并后的結果
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}]
}
4. Rerank重排序后
假設重排序模型對這些文檔評分:
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}]
}
5. 最終RRF合并
將重排序結果作為第三個來源(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
6. 內容總結
展示如下環節:
- 不同檢索方式的分數范圍不同
- RRF 如何將不同分數統一到相同尺度
- 多次出現的文檔如何累加 RRF 分數
- 重排序如何提供額外的相關性評分
文檔排序綜合考慮:
- 語義相似度(向量檢索)
- 關鍵詞匹配(全文檢索)
- 語義理解(重排序)
- 在不同搜索結果中的排名位置(RRF)