3 Embedding-based recommender systems
Embeddings are introduced as a compact, dense way to represent users and items so that similarity can be measured efficiently and meaningfully. Unlike TF-IDF, they can capture semantic relatedness rather than just shared words, and they can also encode user behavior, which makes them a better fit for modern recommender systems. The chapter frames embeddings as the backbone of the recommender pipeline, useful both for retrieving candidates and for scoring them.
The chapter then explains three main ways to create embeddings. Collaborative filtering learns user and item vectors from interaction data such as clicks, ratings, and purchases, uncovering behavior-based patterns but struggling with cold start. Content-based embeddings use pre-trained language models such as BERT and Sentence Transformers to represent item meaning from text and metadata, which works immediately for new items but does not model personal preference. LLM embeddings go further by bringing in broader world knowledge, enabling richer semantic connections and even instruction-based control over what aspects of similarity matter.
A substantial part of the chapter focuses on collaborative filtering with matrix factorization and ALS, showing how user-item matrices are decomposed into latent factor vectors and how dot products are used to predict preferences or find similar items. It also covers practical concerns such as sparse matrix storage, hyperparameter tuning, retraining cadence, and deployment choices. Finally, the chapter recommends combining multiple embedding sources in hybrid systems, since blending collaborative, content, and LLM signals improves robustness, coverage, quality, and diversity in production recommenders.
The four-stage recommender pipeline. Embeddings from this chapter feed into both the retrieval and scoring stages.
The movie matrix can have different types of representations; here, a TFIDF and an embedding representation.
Netflix shows what content is new, to make people engage with the new content.
Matrix factorization decomposes the user-item rating matrix (R) into two smaller matrices: user factors (U) and item factors (I). Each user and item is represented by k latent factors (typically 50-200 dimensions). The predicted rating for user u and item i is the dot product of their factor vectors.
shows the complete workflow for implementing ALS. Most models follow the same procedure. 3 overall steps: Batch job to train the model. At runtime, the trained model is loaded, and when a user request arrives, we use it to generate recommendations.
The ALS algorithm runs periodically as a batch job. It trains a model and pre-calculates recommendations for users and items. The recommendations are saved in a database, which is queried when a user requests recommendations.
Summary
- Embeddings are dense vector representations that capture similarity. What counts as "similar" depends entirely on how the embedding was created — different methods produce different notions of similarity.
- Collaborative filtering learns embeddings from user-item interactions using matrix factorization. ALS decomposes the user-item matrix into user and item factors, optimizing only on observed ratings. The result: two useful tools — predicting user preferences (user × item dot product) and finding similar items (item × item similarity).
- ALS hyperparameters matter: 50–200 factors for embedding dimensionality, 0.01 regularization as a starting point, and 15–20 iterations. Treat tuning as a model selection problem using validation data.
- CF handles mature items well, but suffers from a cold start — new items with no interaction data can't be recommended. Content-based embeddings solve this by using item metadata directly.
- Sentence Transformers (fine-tuned BERT models) generate content embeddings that capture semantic similarity from text. They're fast, lightweight, and work for new items immediately.
- LLM embeddings incorporate world knowledge and support instruction-based steering, in which different prompts emphasize different aspects of the same item. The trade-off is cost — significantly slower to generate and larger to store.
- Two aggregation strategies for multiple seeds: averaging creates a blended profile, max aggregation preserves each seed's individual signal. Neither is universally better — test both for your domain.
- Hybrid retrieval combines multiple embedding sources with weighted merging. Adaptive weighting shifts toward content for new items and toward collaborative filtering for mature items. Most production systems use 2–3 retrieval sources.
AI Recommender Systems ebook for free