Vấn Đề Với Pure Vector Search
Vector search rất mạnh với semantic similarity, nhưng có điểm yếu:
1. Keyword Mismatch: Query "GPT-4" có thể không match document nói về "GPT-4o" do embedding space khác nhau.
2. Rare Terms: Technical terms, product names, proper nouns embedding kém.
3. Exact Match: Khi user muốn exact phrase, semantic search có thể trả về paraphrased results.
Hybrid Search: Best of Both Worlds
Kết hợp:
- Sparse vectors (BM25/TF-IDF): Keyword matching
- Dense vectors (embeddings): Semantic understanding
Reciprocal Rank Fusion (RRF)
Công thức kết hợp rankings từ multiple retrievers:
RRF_score = Σ (1 / (k + rank_i))
Trong đó k thường = 60 (constant).
Implementation với Weaviate
# Hybrid search với alpha blending
results = client.query.get("Document", ["content"]) \
.with_hybrid(
query="GPT-4 fine-tuning",
alpha=0.5 # 0 = pure BM25, 1 = pure vector
) \
.with_limit(10) \
.do()
Với Qdrant
# Sparse + Dense search
results = client.search(
collection_name="docs",
query_vector=NamedVector(
name="dense",
vector=dense_embedding
),
query_vector=NamedSparseVector(
name="sparse",
vector=sparse_embedding
),
fusion=Fusion.RRF
)
Tuning Alpha
- alpha = 0.3: More keyword-focused (good for technical docs)
- alpha = 0.5: Balanced (default recommendation)
- alpha = 0.7: More semantic (good for natural language queries)
Pro Tips
- Query expansion: Thêm synonyms vào sparse query
- A/B testing: Test alpha values với real user queries
- Domain-specific: Tune per collection type
💡 Start với alpha=0.5, tune dựa trên retrieval evaluation metrics (MRR, NDCG).
