liveBook · Manning

Content-based recommender

As explained in AI Recommender Systems

Content-based filtering is a recommendation technique that uses item metadata or content features to recommend items similar to those relevant to a user.

A content-based recommender finds catalog items similar to an item a user is viewing or has consumed. It represents items through metadata such as tags, genres, descriptions, images, or sound, then ranks candidates by feature similarity. Unlike collaborative filtering, it does not need other users’ interactions to find a match. section 1.3.1 section 1.6

A simple implementation has three parts:

  • Represent each catalog item with features. A comic can have a set of theme tags; a movie can have a vector built from its title and genres. section 1.3.1 section 2.3.1
  • Measure similarity. For tag sets, Jaccard similarity divides the number of shared tags by the number of distinct tags across both items. For TF-IDF vectors, cosine similarity provides a score. section 1.3.1 section 2.3.1
  • Retrieve the highest-scoring items other than the seed. For a user-seeded feed, retrieve from recent history, merge candidates, filter watched items, and rank the remainder. section 1.3.1 section 2.3.2

When metadata helps—and when it does not

A new drama with only one rating gives collaborative filtering little evidence, but its genre can immediately retrieve other dramas. That result may still be weak: several unrelated films can receive identical similarity scores when “Drama” is their only useful feature. Richer descriptions can distinguish them; incomplete or coarse metadata cannot. section 2.2.9 section 2.3.1

Content similarity is usually one component of a larger recommender. Retrieval produces candidates; filtering applies exclusions; scoring and ordering prepare what the user sees. If a user has no history, a popularity-based fallback can supply recommendations. Collaborative filtering may uncover connections absent from metadata, so a hybrid can use both signals rather than treating either as universally better. section 2.3.2 section 2.6

Richer content representations can replace sparse tags or genre vectors. Embeddings derived from text, images, and metadata can match items by semantic content without waiting for interaction data. Multiple seed embeddings can be averaged into one query or kept as separate signals; near-duplicate results still need filtering. Check recommendation quality and metadata completeness before adding complexity. section 3.4 section 3.4.3 section 2.4

Listing 2.19 Content-based recommender using the framework
def recommend_content_based(user_id, k=10, content_weight=0.7):
  user_history = get_user_history(user_id)
 
  if len(user_history) == 0:    #A
    popular_movies = movie_counts.head(k).index.tolist()
    return [{'movie_id': int(mid)} for mid in popular_movies]
 
  all_candidates = {}
  recent_movies = list(user_history)[-20:]
 
  for movie_id in recent_movies:
    candidates = retrieve_similar_by_content(movie_id, k=50)    #B
 
    for item in candidates:    #C
      mid = item['movie_id']
      score = item['content_similarity']
      if mid in all_candidates:
        all_candidates[mid] = max(all_candidates[mid], score)
      else:
        all_candidates[mid] = score
 
  candidates = [
    {'movie_id': mid, 'content_similarity': score}
    for mid, score in all_candidates.items()
  ]
  candidates = filter_watched(candidates, user_id)    #D
 
  candidates = add_popularity_scores(candidates)    #E
 
  for item in candidates:
    item['final_score'] = (
      content_weight * item['content_similarity'] +
      (1 - content_weight) * item['popularity']
      )
 
  ranked = sorted(candidates,
    key=lambda x: x['final_score'], reverse=True)    #F
 
  return ranked[:k]

The implementation shows how content-similarity retrieval plugs into a user-history recommendation pipeline, including its no-history fallback. section 2.3.2

How AI Recommender Systems covers it

How deep it goes
Works through tag-set similarity, TF-IDF vector retrieval, and pipeline integration; defers richer representations and rigorous evaluation.
Examples
Uses tagged comics, a sparsely rated drama, and movie recommendations compared against collaborative filtering.
What it assumes
Assumes a catalog with item metadata; introduces similarity calculations and shows how user history supplies recommendation seeds.
What you can do after
Build it from scratch with item features and similarity retrieval, then integrate it into filtering and ranking.
How it connects
Connects item metadata, cosine similarity, collaborative filtering, hybrid recommendation, cold start, and content embeddings.

Also explained in

Compare how 4 books explain content-based recommender →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI Recommender Systems. The section links point to the parts of the book it draws on.