Query Prediction, or How We Gave Up on ANN and Fell in Love with the Inverted Index

Anton Pilkevich30 Jan 2026

Problem

A marketplace with hundreds of millions of products must retrieve candidates fast, apply business rules (geographic availability, stock, delivery time) and explain why a product was shown. A plain inverted index does all this but misses the gap between user wording (typos, slang, transliteration) and product attributes. Approximate nearest-neighbor (ANN) search over embeddings closes the gap, but post-filtering drops relevant items, sharding and compression cost quality, and a single-vector score is hard to explain.

Example from the article: a shopper in Kaliningrad who accepts at most 7 days of delivery loses many relevant products when filters are applied after the ANN search.

Solution in brief

Train a BERT-like model to predict, for each product, the query tokens that lead to add-to-cart on it, using a SPLADE-style target built from three years of search logs. Index the top 50 predicted tokens with their log-probabilities in an ordinary inverted index. Online search stays a normal index lookup, so filters, sharding and match explanations keep working.

Questions this case answers
  • How to add semantic matching to retrieval over a very large catalog while keeping hard filters, low latency, sharding and explainable matches that approximate nearest-neighbor search breaks
  • How to train and evaluate a candidate-generation model when logs come from the old candidate source and offline metrics cannot show new items
  • How to improve the text relevance of search candidates on a catalog of hundreds of millions of products without a vector index?
  • How to keep business filters, sharding and explainability while adding a neural model to retrieval?

Tools and methods

  • SPLADE-style sparse retrieval — model predicts weighted query tokens per product; no ANN index needed
  • Inverted index (Lucene-based engine) — stores predicted tokens; handles filters and sharding
  • BERT-like encoder, MLM-pretrained — 24 layers, 550M parameters, pretrained on product texts
  • KL divergence loss (KLDivLoss) — cross-entropy against a normalized token-weight target
  • LTR re-ranker — re-ranks the mixed candidates
Continue reading — it's free

Google or a one-time email code. No password.