Skip to main content

Vector Search Alone Isn’t Enough

You’ve built a product search API with Sonamu:
Problem encountered: When a user searches for β€œMacBook Pro 14”:
  • β€œMacBook” - Found (semantically similar)
  • β€œMacBook Pro” - Found (Korean also works)
  • β€œMBP14” - Not found (exact model name)
  • β€œSKU-12345” - Not found (product code)
Limitations of vector search:
  • Weak with exact product names, model names
  • Can’t find unique identifiers like product codes, SKUs
  • Vulnerable to technical terms, abbreviations
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

Key points:
  • 'simple': Handles Korean + English
  • setweight: Higher weight for title (A)
  • GIN index: Fast search

Auto-Update Trigger

Now search_vector is automatically updated when products are added/modified.

2. Hybrid Search in Sonamu Model

SQL explanation:
  1. vector_results: Calculate vector similarity
  2. fts_results: Calculate FTS score
  3. LEFT JOIN: Include if either matches
  4. 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
Semantic-focused
  • Use case: When semantic understanding is important
  • Examples: Q&A, customer support, recommendations
Keyword-focused
  • Use case: When exact matching is important
  • Examples: Product codes, model names, technical terms

Dynamic Adjustment in Sonamu

Practical Scenario

You’re building an online store with Sonamu. Step 1: Prepare Tables
Step 2: Add Product API
Step 3: Hybrid Search API
Usage examples:

Benchmarks

Search Accuracy Comparison

Tested on an actual 1000-product DB: Conclusion: Hybrid is 15-20% more accurate.

Cautions

Cautions for hybrid search in Sonamu:
  1. Both indexes required: Vector + FTS
  2. tsvector update: Automate with trigger
  3. Weight sum = 1: Normalization
  4. NULL handling: Use COALESCE
  5. LEFT JOIN: OK if only one side matches
  6. Use β€˜simple’ for Korean: FTS language setting
  7. Performance monitoring: EXPLAIN ANALYZE

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