hybrid-search-implementation
結合向量相似度和關鍵字搜尋的混合搜尋模式與融合方法
中文翻譯
---
name: hybrid-search-implementation
description: 結合向量與關鍵字搜尋以提升檢索效果。適用於實作 RAG 系統、建構搜尋引擎,或單靠任一種方法召回率都不夠的時候。
---
# 混合搜尋實作
結合向量相似度與關鍵字搜尋的模式。
## 什麼時候用這個 Skill
- 建構召回率更高的 RAG 系統
- 結合語意理解與精確比對
- 處理帶有特定詞彙(名稱、代碼)的查詢
- 改善針對特定領域詞彙的搜尋
- 純向量搜尋漏掉關鍵字命中的時候
## 核心概念
### 1. 混合搜尋架構
```
Query → ┬─► Vector Search ──► Candidates ─┐
│ │
└─► Keyword Search ─► Candidates ─┴─► Fusion ─► Results
```
### 2. 融合方法
| 方法 | 說明 | 最適合 |
| ----------------- | ------------------------ | --------------- |
| **RRF** | Reciprocal Rank Fusion | 通用 |
| **Linear** | 分數的加權總和 | 可調整的平衡 |
| **Cross-encoder** | 用神經網路模型重新排序 | 品質最高 |
| **Cascade** | 先過濾再重新排序 | 效率 |
## 範本與詳細實作範例
完整的範本庫和詳細實作範例放在 `references/details.md`,需要具體範本的時候去讀那份檔案。
## 最佳實務
### 該做的
- **憑經驗調整權重**:用你自己的資料測試
- **為了簡單用 RRF**:不用調整也運作得很好
- **加上 reranking**:品質大幅提升
- **兩種分數都記 log**:方便除錯
- **做 A/B 測試**:衡量對真實使用者的影響
### 不該做的
- **不要以為一種設定通吃**:不同的查詢需要不同的權重
- **不要跳過關鍵字搜尋**:它處理精確比對比較好
- **不要抓太多**:在召回率與延遲之間取得平衡
- **不要忽略邊界案例**:空結果、單字查詢英文原文
---
name: hybrid-search-implementation
description: Combine vector and keyword search for improved retrieval. Use when implementing RAG systems, building search engines, or when neither approach alone provides sufficient recall.
---
# Hybrid Search Implementation
Patterns for combining vector similarity and keyword-based search.
## When to Use This Skill
- Building RAG systems with improved recall
- Combining semantic understanding with exact matching
- Handling queries with specific terms (names, codes)
- Improving search for domain-specific vocabulary
- When pure vector search misses keyword matches
## Core Concepts
### 1. Hybrid Search Architecture
```
Query → ┬─► Vector Search ──► Candidates ─┐
│ │
└─► Keyword Search ─► Candidates ─┴─► Fusion ─► Results
```
### 2. Fusion Methods
| Method | Description | Best For |
| ----------------- | ------------------------ | --------------- |
| **RRF** | Reciprocal Rank Fusion | General purpose |
| **Linear** | Weighted sum of scores | Tunable balance |
| **Cross-encoder** | Rerank with neural model | Highest quality |
| **Cascade** | Filter then rerank | Efficiency |
## Templates and detailed worked examples
Full template library and detailed worked examples live in `references/details.md`. Read that file when you need the concrete templates.
## Best Practices
### Do's
- **Tune weights empirically** - Test on your data
- **Use RRF for simplicity** - Works well without tuning
- **Add reranking** - Significant quality improvement
- **Log both scores** - Helps with debugging
- **A/B test** - Measure real user impact
### Don'ts
- **Don't assume one size fits all** - Different queries need different weights
- **Don't skip keyword search** - Handles exact matches better
- **Don't over-fetch** - Balance recall vs latency
- **Don't ignore edge cases** - Empty results, single word queries