Shopify’s generative discovery model

Shuying Sun, Juhana Kangaspunta, Khalil Hajji11 Nov 2026

Problem

A commerce platform with billions of products must find relevant ones for each buyer within the latency budget of a live request. Search and recommendation usually run as separate systems, although both combine product knowledge with buyer context. A raw product ID carries no meaning, and a billion-entry output vocabulary is hard to learn because most products have few interactions. Recommenders trained on buyer histories also over-weight products the buyer already knows.

Example from the article: two buyers search for "backpack". One has been comparing waterproof laptop bags, the other larger packs for hiking, so each should see different results.

Solution in brief

Shopify encodes each product as a three-token semantic ID and trains one fine-tuned open-weight language model, on search and recommendation data together, to generate those IDs. Search and recommendation experts (search with reinforcement learning) are then distilled back into one shared model. Constrained decoding and multi-token prediction keep serving within the latency budget.

Questions this case answers
  • How to generate retrieval candidates for two related ranking tasks with one generative model when the item catalog is too large for a per-item output vocabulary and the response must fit a tight latency budget
  • How to train one model that generates candidates for both product search and recommendations?
  • How to represent a catalog of billions of products so a language model can generate them?
  • How to make a recommender find products the buyer has never interacted with?

Tools and methods

  • Semantic IDs (RQ-KMeans) — product embedding to a short generatable code
  • Continued pretraining, fine-tuning — product meaning and buyer journeys
  • LLM relevance judge with reinforcement learning — rewards relevant search candidates
  • Multi-teacher distillation — merges two experts into one model
  • Constrained decoding (STATIC trie) — forces valid product codes
  • Multi-token prediction (MTP) plus ranker — one-pass generation of three codes
  • LFM2-2.6B, TensorRT-LLM — serving model and engine
Continue reading — it's free

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