A Semantic ID is a short sequence of discrete codewords that identifies an item in a catalog, built from the item’s content embedding so that similar items share similar codes. Recommender systems use Semantic IDs mainly in generative recommendation, where a sequence model predicts the next item by generating its code tokens one by one instead of scoring every item in the catalog.
Semantic IDs, also called semantic item IDs, replace the conventional random atomic ID, such as a database key, which carries no meaning and needs its own learned embedding row. Because the codes are hierarchical and shared across items, new and rarely seen items inherit knowledge from related items, which helps with the cold start problem and the long tail.
How a Semantic ID is constructed
A Semantic ID is produced by quantizing a content embedding into a small number of discrete tokens. The pipeline usually has three stages: encode the item, quantize the vector, and resolve collisions.
- Content encoding: a pretrained encoder, such as a sentence embedding model for titles and descriptions or a multimodal model for images, maps each item to a dense vector.
- Hierarchical quantization: a method such as a residual-quantized variational autoencoder (RQ-VAE) or residual k-means assigns the vector to a codeword at level one, subtracts that codeword, and quantizes the remaining residual at level two, and so on.
- Collision handling: when two items receive the same code tuple, an extra disambiguation token is appended so that every item maps to a unique identifier.
The result is a tuple such as (17, 203, 88, 2), where early positions capture coarse semantics like product category and later positions capture finer distinctions. With three levels of 256 codewords, the code space already contains about 16.7 million combinations, enough for large catalogs.
Key design parameters
The quality of a Semantic ID scheme depends on a few design parameters that trade expressiveness against learnability. The table summarizes typical values and their effects.
| Parameter | Typical range | Effect of increasing it |
|---|---|---|
| Number of levels | 3 to 4 codewords | Finer distinctions, longer decoding |
| Codebook size per level | 64 to 1,024 entries | More capacity, sparser training signal per token |
| Collision rate | Below a few percent of items | More disambiguation tokens needed |
| Embedding source | Text, image or multimodal | Determines which kind of similarity the codes express |
| Codebook utilization | Ideally near 100 percent | Unused codewords waste capacity |
A frequent failure is codebook collapse, in which a few codewords absorb most items. Practitioners counter it with k-means initialization of codebooks, commitment losses and monitoring of per-level utilization during training.
Semantic IDs compared with other item identifiers
Semantic IDs sit between atomic IDs and raw text identifiers, and each option suits a different modeling approach. The comparison below shows the main differences.
| Identifier type | Meaning carried | Parameter cost | Cold start behavior |
|---|---|---|---|
| Atomic ID | None, arbitrary key | One embedding row per item | Poor until interactions accumulate |
| Semantic ID | Hierarchical content similarity | Small shared codebooks | Good through shared prefixes |
| Text title as ID | Full natural language | Uses language model vocabulary | Good, but titles may be ambiguous |
| Hashed ID | None, with deliberate collisions | Fixed hash table | Poor, collisions are random |
Unlike an item embedding used in embedding-based retrieval, a Semantic ID is discrete, so a Transformer can generate it with the same next-token machinery used for language. Unlike a hashed ID, its collisions are semantically meaningful, which makes them less harmful.
Using Semantic IDs in generative retrieval
In generative retrieval, a sequence model reads a user’s history as Semantic ID tokens and autoregressively decodes the code of the next item. Beam search produces several candidate code sequences, and each valid sequence maps back to an item.
Most systems apply constrained decoding with a prefix tree of valid codes, so that the model never emits a tuple that matches no item. Semantic IDs also appear in ranking models, where their prefixes serve as shared embedding features that let popular and niche items exchange information.
| Stage | Role of Semantic IDs | Main benefit |
|---|---|---|
| Candidate generation | Decoded directly by a generative model | No approximate nearest neighbor index required |
| Ranking | Prefix embeddings as features | Better generalization to sparse items |
| LLM-based recommendation | Added as new tokens to a language model | Joint reasoning over text and items |
Limitations and common mistakes
Semantic IDs bring real gains, but they also introduce new engineering burdens that atomic IDs avoid. Teams should weigh these before replacing a mature retrieval stack.
- Content is not behavior: items with similar descriptions may attract different users, so purely content-based codes can miss collaborative signals.
- Re-indexing cost: retraining the quantizer changes codes, which invalidates trained models and cached features.
- Inference latency: beam search over several levels is slower than a single dot-product lookup.
- Popularity bias in decoding: generative models may still favor codes of frequently seen items.
- Poor encoders: weak or noisy content embeddings produce meaningless hierarchies.
A common remedy is to train the quantizer on embeddings that blend content and collaborative signals, and to freeze the code assignment for a full model cycle so that downstream models remain consistent.
A non-technical view
Think of a library call number. Books on the same topic sit on the same shelf, and their numbers start the same way. A Semantic ID works like a call number for products, songs or videos.
A random ID number tells a computer nothing. A Semantic ID tells it what kind of item this is. So a brand new item can be recommended right away, because the system already knows its neighbors. The main idea is that the name of an item now carries its meaning.
A concrete example
An online bookstore with about two million titles wanted to recommend newly released books, which received almost no clicks under its old atomic ID model. The team encoded every title and description with a text embedding model and trained an RQ-VAE with three levels of 256 codewords, plus one disambiguation token.
A new crime novel received a code whose first two levels matched established Nordic crime titles. A generative model trained on reading histories could therefore suggest the new book from its first day, without waiting for interaction data to accumulate.
In an offline evaluation on held-out sessions, the Semantic ID model raised recall for books less than 30 days old noticeably over the atomic ID baseline, while overall accuracy stayed similar. The team kept its existing ranker and used the generative model as an additional candidate source for fresh and long-tail titles.