liveBook · Manning

Similarity metric

As explained in AI Recommender Systems

Similarity is a quantitative or qualitative measure of how alike two items, user histories, or related representations are according to selected features or behavior.

A similarity metric measures how alike two items, user histories, or representations are according to selected features or behavior. In recommender systems, it turns relationships into scores used to retrieve related content, personalize candidates, or rank results. section 2.3 section 2.3.3

Similarity can be computed from several signals:

  • Content similarity compares item features such as genres, descriptions, actors, or directors; genre-only vectors provide a simple but limited representation. section 2.3 section 2.3.3
  • Behavioral similarity uses user interaction patterns to identify items related through collective behavior rather than shared metadata. section 2.3.3 section 1.6
  • Embedding similarity compares vector representations, commonly with cosine similarity, and can capture semantic relationships unavailable to explicitly defined features. section 3.4.3 section 3.5
  • Hybrid retrieval combines content and behavioral scores, then weights them with popularity or other ranking signals. section 2.3.3

A production pipeline usually retrieves candidates similar to recent user watches, merges duplicates, filters watched items, adds popularity scores, and ranks the survivors. Empty histories fall back to popular items, while multiple seeds can be averaged or aggregated before nearest-neighbor search. section 2.2.6 section 3.4.3

Toy Story recommendations

A hybrid recommender ranks Toy Story 2 first with strong content, behavioral, and popularity scores. Forrest Gump and Star Wars receive zero content similarity but rank because behavioral similarity and popularity compensate. Embedding search instead returns Toy Story sequels and other animated children's movies. section 2.3.3 section 3.4.3

Listing 3.14 looking at embeddings .
from sklearn.metrics.pairwise import cosine_similarity
def find_similar_movies(movie_idx, embeddings, k=10):
  query_emb = embeddings[movie_idx:movie_idx+1] #A
  similarities = cosine_similarity(query_emb, embeddings)[0] #B
  similarities[movie_idx] = -1 #C  
  top_indices = np.argsort(similarities)[-(k):][::-1] #D
  return top_indices, similarities[top_indices]

Inspect a compact implementation that computes cosine similarity, excludes the query item, and returns the highest-scoring neighbors. section 3.4.3

How AI Recommender Systems covers it

How deep it goes
Progresses from metadata comparisons to hybrid ranking and embedding search, while deferring richer learned representations and production deduplication details.
Examples
Demonstrates genre overlap, Toy Story hybrid rankings, and cosine-nearest movies such as Toy Story 2 and Toy Story 3.
What it assumes
Assumes item metadata or interaction data, then builds from genre features toward descriptions, embeddings, and learned semantic representations.
What you can do after
Apply via scikit-learn cosine similarity and a multi-stage recommender pipeline to retrieve, filter, and rank related items.
How it connects
Connects content-based recommendations, collaborative filtering, embeddings, cosine similarity, cold-start problems, and popularity bias.

Also explained in

Compare how 14 books explain similarity metric →

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.