Semantic IDs for Generative Search and Recommendation

Gustavo Penha, Edoardo D'Amico, Marco De Nadai, Enrico Palumbo, Alexandre Tamborrino, Ali Vardasbi, Max Lefarov, Shawn Lin, Timothy Heath, Francesco Fabbri, Hugues Bouchard1 Sep 2025

Problem

Teams that want one generative model for search and recommendation must decide how to write items as tokens. Unique IDs and sequential IDs scale poorly and handle cold-start items badly. Semantic IDs tokenize an item's embedding so similar items share tokens, but they depend strongly on the embedding space. Search-tuned embeddings give good retrieval and weaker recommendations. Recommendation-tuned embeddings do the reverse.

Example from the article: on a MovieLens-25M dataset, search-tuned Semantic IDs raised search Recall@30 but hurt recommendation, and recommendation-tuned IDs did the opposite.

Solution in brief

Fine-tune one text bi-encoder on both tasks with contrastive learning, using query-item pairs from search and co-occurring item pairs from recommendation. Quantize the item embeddings with RQ-KMeans to get Semantic IDs, and use them in the joint generative model. The trade-off is balanced, with no extra model per task.

Questions this case answers
  • How to build discrete item codes for a single generative retrieval model that must serve two tasks whose embedding spaces pull in opposite directions
  • How to combine information from two training signals into one item representation without a per-task model
  • How to represent items as discrete tokens so one generative model serves both search and recommendation?
  • How to build Semantic IDs that do not lose quality on one task when tuned for the other?

Tools and methods

  • Semantic IDs — discrete item tokens derived from item embeddings, so similar items share tokens
  • RQ-KMeans — residual k-means quantization that turns an embedding into a short token sequence
  • Multi-task bi-encoder — text encoder trained with contrastive loss on search pairs and item-item pairs
  • Sentence Transformers / MPNet — encoder base used in the paper (per the paper)
  • FAISS — residual quantization implementation used in the paper (per the paper)
  • T5 — generative backbone in the paper (per the paper)
Continue reading — it's free

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