Why architecture matters here
Search architecture matters because the quality-cost trade-offs are subtle. Bigger indexes, more sophisticated retrieval, ML reranking all cost latency and money. Product companies must balance freshness, relevance, cost, and latency.
Cost matters. Elasticsearch clusters at scale run into six-figure monthly bills; vector indexes add more.
Reliability is where analytics + retraining feedback loops shine. Click data trains reranker; refined queries improve future retrieval.
The architecture: every stage explained
Walk the diagram top to bottom.
Docs. Content to index — product data, articles, customer records.
Indexer. Tokenizes, normalizes (lowercase, stem), extracts features.
Inverted Index. Term → list of doc IDs + positions. The foundation.
Query. Parsed, expanded (synonyms), spell-corrected.
Retrieval. BM25 for keyword match; vector search for semantic; hybrid combines. Returns top-k candidates.
Reranking. ML model (learn-to-rank, LLM) reorders top candidates using richer features (query-doc similarity, freshness, popularity).
Personalization. User context (history, preferences) further reorders.
Result page. Snippets, highlights, facets, pagination. UI concerns.
Analytics. Click-through, dwell time, refinements. Feeds reranker training + query understanding.
Sharding + replication. Shard by doc ID or category; replicate for read scale + HA.
End-to-end query flow
Trace a query. User: "red running shoes for men size 10".
Query parser: extracts entities (color=red, category=running_shoes, gender=men, size=10). Expands "shoes" → "footwear."
Retrieval: BM25 against product name + description with entity filters. Simultaneously vector search on query embedding vs product embeddings. Fusion combines top 100.
Reranker (learn-to-rank model) scores each candidate with 40 features: keyword relevance, popularity, price, ratings, in-stock. Returns top 20.
Personalization: user's history shows preference for Nike; boost Nike results. Top 20 reranked.
Result page: snippets with query terms highlighted; facets for brand, price range, ratings.
User clicks 3rd result; spends 2 minutes; adds to cart. Analytics records: query, results shown, clicks, conversions. Feeds reranker retraining.
Sharded across 20 nodes by product ID; queries fan-out; results merged.