Vector Search Alone Isnβt Enough
Youβve built a product search API with Sonamu:- βMacBookβ - Found (semantically similar)
- βMacBook Proβ - Found (Korean also works)
- βMBP14β - Not found (exact model name)
- βSKU-12345β - Not found (product code)
- Weak with exact product names, model names
- Canβt find unique identifiers like product codes, SKUs
- Vulnerable to technical terms, abbreviations
What is Hybrid Search?
Combines vector search (semantics) + full-text search/FTS (keywords). Advantages:- Vector: Semantic understanding, synonyms, typos
- FTS: Exact keywords, partial matching
- Combined: Best accuracy
Implementation in Sonamu
1. PostgreSQL FTS Setup
First, prepare full-text search (FTS).Add tsvector Column
'simple': Handles Korean + Englishsetweight: Higher weight for title (A)- GIN index: Fast search
Auto-Update Trigger
2. Hybrid Search in Sonamu Model
vector_results: Calculate vector similarityfts_results: Calculate FTS scoreLEFT JOIN: Include if either matches- Weighted average:
(vector * 0.7) + (FTS * 0.3)
Weight Strategies
When to Use Which Weights?
Balanced (default)- Use case: General search
- Examples: Blogs, documents, knowledge bases
- Use case: When semantic understanding is important
- Examples: Q&A, customer support, recommendations
- Use case: When exact matching is important
- Examples: Product codes, model names, technical terms
Dynamic Adjustment in Sonamu
Practical Scenario
Scenario: E-commerce Product Search
Youβre building an online store with Sonamu. Step 1: Prepare TablesBenchmarks
Search Accuracy Comparison
Tested on an actual 1000-product DB:| Method | Accuracy (MAP@10) | Pros | Cons |
|---|---|---|---|
| Keyword only (LIKE) | 0.45 | Fast | Canβt find semantics |
| FTS only | 0.68 | Partial matching | Weak on synonyms |
| Vector only | 0.72 | Semantic understanding | Weak on exact matching |
| Hybrid | 0.85 | Best of both | Complex |
Cautions
When to Use Hybrid Search?
Recommend Hybrid
-
E-commerce product search
- Semantics + model names, SKUs
-
Technical documentation search
- Concepts + function names, code
-
Customer support
- Problem descriptions + exact terms
Vector Only is Sufficient
-
Recommendation systems
- Keywords not needed
-
Image search
- No text keywords
-
Finding similar documents
- Only semantics matter
Next Steps
Vector Search
Basic vector search implementation
Chunking
Splitting long documents