Problem
A grocery catalog with millions of products has a taxonomy that groups items by type, not by how people shop. Parmigiano Reggiano sits under "Dairy > Cheese > Parmesan", while the olives, tapenade and cheese tray that go with it sit in other branches with no shared ancestor below "Food". Three things break. New products have no purchase history and stay invisible. Sparse categories lack interaction data, so recommenders favor popular staples. Mislabeled items go unnoticed.
Example from the article: a protein bar filed under "Candy" and a sparkling water filed under "Soda" were placed by the codes among other protein bars and other sparkling waters.
Solution in brief
Compress product text embeddings into four-level codes (semantic IDs) with a residual vector quantizer. Add a contrastive term to training that uses distance in the category tree as the similarity signal, so no engagement data is needed. Build two code variants, one for precision and one for discovery, and evaluate the codes directly.
Questions this case answers
- How to represent items with compact discrete codes so that similar items share code prefixes even when they sit in different branches of a fixed taxonomy and have no interaction history
- How to find items whose taxonomy label disagrees with their learned neighbourhood when the only signal is the label itself
- How to make new products with no purchase history show up next to related items from other categories?
- How to give millions of catalog products short discrete codes that group related items across taxonomy branches?
Tools and methods
- Semantic IDs (RQ-VAE) — compress product embeddings into 4-level codes where shared prefixes mean similar products
- Contrastive regularization — uses category-tree distance to pull related products together in code space
- Hierarchical batch sampling — batches with both related and unrelated categories
- Gemini Flash — extracts structured attributes before embedding (discovery variant)
- Gemma — off-the-shelf embedding model for the cleaned attributes
- LLM-as-a-judge — scores each leaf group of codes
Google or a one-time email code. No password.