Making Search Fast: From 30 Seconds to Under 1
How I rebuilt a broken search system using hybrid search, vector embeddings, and a bit of LLM magic.
Making Search Fast: From 30 Seconds to Under 1
The search was broken. Not "kinda slow" broken. 30 seconds per query broken. Users were abandoning the page before results loaded. Sales were being lost.
This is the story of how I rebuilt it.
The Problem
The client, a European licensed apparel supplier, had a catalog of over 100,000 products. Their existing search was a simple SQL LIKE query:
SELECT * FROM products WHERE name LIKE '%batman%' OR description LIKE '%batman%'
This worked when they had 5,000 products. At 100,000, it didn't.
Worse, users misspell things. "Batmna" returned nothing. "Spiderman" found nothing because the database had "Spider-Man" (with a hyphen).
The Approach
I built a hybrid search system combining three techniques:
- Typesense for full-text search with typo tolerance
- Vector embeddings for semantic similarity (finding "superhero costumes" when searching "Marvel apparel")
- LLM-powered query expansion for edge cases
The architecture looked like this:
User Query → Query Processor → [Typesense + Vector DB] → Rank Fusion → Results
The Typo Problem
Typesense handles typos out of the box, but I needed to tune it. By default, it would match "bat" to "bathroom," which isn't helpful when selling Batman merchandise.
I configured a custom ranking formula that weighted:
- Exact matches (highest)
- Prefix matches (high)
- Typo-tolerant matches (medium)
- Semantic matches (fallback)
The Vectorization Challenge
Vectorizing 100k products was expensive. The initial approach using OpenAI's embedding API would have cost ~$400 and taken hours.
I switched to:
- Sentence Transformers running locally for the initial bulk vectorization
- Incremental updates using a queue system for new products
Total cost: $0. Time: 2 hours for the full catalog.
The Result
30 seconds → under 1 second.
More importantly:
- 99% accuracy on misspelled terms
- Zero abandoned searches in the first month
- The client's sales team could finally demo the product without apologizing
What I Learned
-
Start with the data. Half the performance issues came from unclean product data: duplicate entries, inconsistent naming, missing categories.
-
Hybrid beats pure. Neither full-text nor vector search alone was good enough. The combination, with proper rank fusion, was key.
-
Cost matters. The "easy" solution (OpenAI embeddings) would have created ongoing costs. The harder solution (local models) was worth the upfront investment.
This project was completed during my contract at WIZEWERX. The system is now handling production traffic for one of Europe's largest licensed merchandise suppliers.