Generative retrieval replaces embeddings with semantic barcodes
A PyTorch implementation that compresses catalog items into discrete semantic ID tuples so a decoder-only transformer can predict the next item without ever running a vector search.

What it does
This repo implements the two-stage generative retrieval approach from Recommender Systems with Generative Retrieval. First, an RQ-VAE tokenizes every item in the corpus into a short tuple of discrete semantic IDs. Then a decoder-only transformer is trained on user interaction histories—represented as sequences of those frozen semantic IDs—to predict the next item directly, bypassing conventional embedding-based nearest-neighbor retrieval.
The interesting bit
The model sidesteps vector databases entirely by treating items as structured barcodes rather than dense vectors. Retrieval becomes pure autoregressive generation over a compact vocabulary of semantic tokens, collapsing the usual search problem into next-token prediction.
Key highlights
- Supports Amazon Reviews (Beauty, Sports, Toys) and MovieLens (1M and 32M) out of the box with no manual dataset downloads.
- Two separate training pipelines:
train_rqvae.pylearns the item tokenizer, whiletrain_decoder.pyfits the retrieval model using a frozen RQ-VAE. - Hyperparameters are managed via
gin-config, with sample.ginfiles provided for each supported dataset. - A pretrained RQ-VAE checkpoint for Amazon Beauty is hosted on Hugging Face.
Caveats
- Only one pretrained checkpoint (Amazon Beauty) is currently available on Hugging Face.
- The README does not report retrieval metrics or benchmark comparisons against standard baselines.
- The tokenizer and retrieval model are trained separately; the README does not describe a joint end-to-end training mode.
Verdict
Worth cloning if you are researching generative retrieval or semantic-ID alternatives to ANN-based recommenders. Pass if you need a production-hardened stack with published offline metrics.
Frequently asked
- What is EdoardoBotta/RQ-VAE-Recommender?
- A PyTorch implementation that compresses catalog items into discrete semantic ID tuples so a decoder-only transformer can predict the next item without ever running a vector search.
- Is RQ-VAE-Recommender open source?
- Yes — EdoardoBotta/RQ-VAE-Recommender is open source, released under the MIT license.
- What language is RQ-VAE-Recommender written in?
- EdoardoBotta/RQ-VAE-Recommender is primarily written in Python.
- How popular is RQ-VAE-Recommender?
- EdoardoBotta/RQ-VAE-Recommender has 831 stars on GitHub.
- Where can I find RQ-VAE-Recommender?
- EdoardoBotta/RQ-VAE-Recommender is on GitHub at https://github.com/EdoardoBotta/RQ-VAE-Recommender.