Overview

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.

FAQ

What is an embedding in recommender systems?An embedding is a dense, low-dimensional vector representation of an item or user that captures meaningful similarity. Instead of using sparse word counts or IDs, embeddings place similar entities close together in vector space.
Why are embeddings better than TF-IDF for recommendations?TF-IDF treats related words like “adventure” and “adventurous” as different and ignores user behavior. Embeddings can capture semantic meaning and, depending on how they are created, can also capture behavioral patterns from user interactions.
How does collaborative filtering create embeddings?Collaborative filtering learns embeddings from user-item interactions such as clicks, ratings, purchases, or watch time. Items that are liked by similar users get similar embeddings, even if their content descriptions are very different.
What is the cold start problem in collaborative filtering?The cold start problem occurs when a new item or new user has little or no interaction data. Since collaborative filtering depends on behavior, it cannot generate strong recommendations for completely new items or users without additional signals.
How are content-based embeddings created with BERT or Sentence Transformers?Content-based embeddings are generated from item content such as titles, genres, and descriptions using pre-trained language models like BERT or Sentence Transformers. These models convert text into dense vectors that reflect semantic similarity between items.
Why are cosine similarity and dot product commonly used with embeddings?They measure how close two embeddings are in vector space. Cosine similarity compares direction, while dot product also includes magnitude. If embeddings are normalized to unit length, dot product and cosine similarity become equivalent.
What makes ALS useful for collaborative filtering?Alternating Least Squares (ALS) is a matrix factorization method that learns user and item factors from observed ratings or interactions. It is efficient, works well with sparse data, and can scale to large recommenders in production.
How do you generate recommendations with an ALS model?You can either score items for a specific user using the learned user and item vectors, or find similar items using item embeddings alone. ALS supports both personalized recommendations and “more like this” item-based recommendations.
When do LLM embeddings add value over Sentence Transformer embeddings?LLM embeddings are most useful when metadata is sparse, when cultural or temporal context matters, or when franchise and sequel relationships are hard to infer from text alone. They can also be steered with instructions to emphasize different aspects of similarity.
How do hybrid recommender systems combine multiple embedding sources?Hybrid systems combine sources such as collaborative filtering, content embeddings, and LLM embeddings by retrieving candidates from each source and merging their scores. This improves robustness, cold-start coverage, quality, and diversity.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • AI Recommender Systems ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • AI Recommender Systems ebook for free