Guide

Collaborative filtering (CF) recommends items because of patterns in who interacted with what. If people with similar histories liked an item, you might like it too. CF needs no description of the items, only the interactions.

The data is a big user-item matrix R, where R[u, i] is a rating or a "watched" flag. Most cells are empty, since no user has touched most items.

The factorization

Matrix factorization approximates the matrix with two smaller ones:

R ≈ U × Vᵀ

U has one row per user, and V has one row per item. Each has k columns, so every user and every item gets a short latent vector of k numbers. Training adjusts those numbers so that the dot product of a user's vector and an item's vector matches the observed interactions. Common solvers are alternating least squares and stochastic gradient descent.

Walking through a small example

Let k = 2. After training, the vectors are:

  • Alice: (0.9, 0.1), which means mostly "sci-fi."
  • Interstellar: (0.8, 0.2)
  • A romantic comedy: (0.1, 0.9)

The predicted affinity is the dot product:

Alice · Interstellar = 0.9 × 0.8 + 0.1 × 0.2 = 0.72 + 0.02 = 0.74
Alice · romcom       = 0.9 × 0.1 + 0.1 × 0.9 = 0.09 + 0.09 = 0.18

Interstellar scores higher, so it is the better recommendation. Nobody labeled the two dimensions "sci-fi" and "romance." Training found them because they explain the pattern of interactions.

With 100,000 movies, you would score each one for Alice and keep the top N she has not seen. That is where the cost starts to bite.

Content-based and hybrid

Content-based methods use item features, such as genre, text embeddings and tags. They recommend items similar to ones the user liked. Pure CF fails for brand-new items, and pure content misses taste that is social and hard to describe. Production systems usually mix the two.

Limits at scale

  • Scoring every item for every request is O(number of items), which is too slow for millions of items.
  • Cold-start users and items have weak or empty vectors.
  • Popular items dominate the co-occurrence patterns, which drowns out the long tail.

These limits are why the industry moved to two-tower retrieval with approximate nearest neighbors, covered in two-tower retrieval.

Common mistakes

  • Expecting CF to handle new items. An item with no interactions has no vector to learn.
  • Treating all unobserved cells as zeros without thought. Missing means unseen, not disliked. See implicit feedback.
  • Scoring the whole catalog per request. Precompute item vectors and use an approximate nearest-neighbor index.

Check yourself

  1. In the example, why is the dot product a good score? Answer: the vectors put Alice and Interstellar on the same "sci-fi" axis, so their product is large.
  2. Why does CF struggle with a brand-new movie? Answer: nobody has interacted with it, so its vector is never trained.

Key takeaways

  • CF predicts from interaction patterns. It needs no item content.
  • Matrix factorization gives each user and item a short vector, and a dot product predicts the interaction.
  • Pure CF fails on cold start and on huge catalogs.
  • Two-tower models and approximate nearest neighbors solve the scale problem.

Further learning

Next, see how the modern retrieval model replaces the full matrix with two towers in two-tower retrieval.