Improving search relevance in hyperlocal food delivery using (small) language models

Adityakiran, Jose Mathew, Srinivas N, Jairaj Sathyanarayana13 Mar 2024

Problem

Swiggy's food search must serve millions of items from hundreds of thousands of restaurants across India. Queries often pack several intents into one phrase: dish, diet, cuisine, time of day, mood. String matching works for plain dish names but fails on such queries. Off-the-shelf embedding models rank such queries poorly: for "I just finished gym" the base model returned grilled protein meal and dal with rotis. The model also has to embed a query in under 100 ms on existing CPU servers.

Example from the article: for "healthy bakery items" the base model returns lemon loaf and honey almond pastry, while the fine-tuned model returns multigrain loaf and a sugar-free keto brownie.

Solution in brief

Fine-tune a small open-source sentence-embedding model in two stages. Stage one is unsupervised (TSDAE) on documents built from past orders, so the model learns the food vocabulary. Stage two is supervised on 300,000+ curated query-item pairs with Multiple Negatives Ranking loss. Retrieval is nearest-neighbor search by embedding similarity.

Questions this case answers
  • How to retrieve relevant catalog items for long, multi-intent natural-language queries when keyword matching fails and the embedding model must run on CPU within a tight latency budget
  • How to domain-adapt a small pre-trained embedding model for retrieval when only a few curated query-item pairs exist and hard negatives are unavailable
  • How to retrieve relevant dishes for complex, multi-intent search queries where string matching fails?
  • How to adapt a small open-source embedding model to a domain catalog when real query-item data is thin?

Tools and methods

  • all-mpnet-base-v2 (Hugging Face) — base embedding model with the best results (all-MiniLM-L6-v2 was weaker)
  • TSDAE — unsupervised domain adaptation on order documents
  • Multiple Negatives Ranking (MNR) loss — supervised training on (query, item) pairs without labeled negatives
  • LLM-assisted pair generation — enriches item metadata and augments queries, then checked by hand
  • BM25 — lexical baseline
Continue reading — it's free

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