liveBook · Manning

Filtering

As explained in AI Recommender Systems

A recommendation-stage technique that removes candidate items that should not be shown because they violate eligibility, quality, or other constraints.

Filtering removes candidates that should not be recommended, regardless of how relevant they might be. In a four-stage recommender, retrieval gathers candidates, filtering applies eligibility rules, scoring estimates relevance, and ordering produces the final list. Keeping rules separate from scoring lets teams change them without retraining a model. section 1.4.1 section 1.4.2

Choose rules according to the domain:

  • Remove unavailable or prohibited items, such as out-of-stock products, regionally unavailable titles, or age-restricted content. section 1.4.1 section 2.2.3
  • Remove previously consumed items when repetition is unwanted, such as watched movies or read news articles. Do not apply that rule blindly: listeners replay favorite songs, and shoppers repurchase groceries. section 2.2.3
  • For document retrieval in retrieval-augmented generation, remove outdated or low-quality sources before relevance scoring. section 1.4.2

Filtering watched movies

Retrieve 100 movies similar to a seed movie. Build a set of movie IDs from the user's ratings history, then retain only candidates whose IDs are absent from that set. In one test, 28 of the 100 candidates were removed, leaving 72 to score and rank. section 2.2.3

Listing 2.5 Filtering watched movies
def get_user_history(user_id): #A
    user_movies = ratings[ratings['userId'] == user_id]['movieId'].values
    return set(int(mid) for mid in user_movies) 
 
def filter_watched(candidates, user_id): #B
    user_history = get_user_history(user_id)
    
    filtered = [
        item for item in candidates
        if item['movie_id'] not in user_history
    ]
    
    return filtered
 

The listing shows the history lookup and candidate-membership check used by the watched-movie filter. section 2.2.3

Evaluate filtering as a correctness requirement, not primarily with ranking metrics. Spot-check results and automate tests for consumed items, regional availability, and age restrictions. A rule failure may barely change aggregate precision while being immediately visible to affected users. Test the filter independently by supplying candidates and checking which ones survive. section 4.6.5 section 2.2.8

How AI Recommender Systems covers it

How deep it goes
Implements a watched-item filter and its test, then identifies domain-dependent rules without implementing every rule.
Examples
Uses watched movies, out-of-stock products, age restrictions, and a 100-candidate movie-filter test.
What it assumes
Assumes retrieved candidates and user-item interaction history; teaches the history-based filtering step directly.
What you can do after
Build it from scratch as a watched-item filter and diagnose rule failures with spot checks and automated tests.
How it connects
Connects candidate retrieval, scoring, ordering, business rules, and automated testing.

Also explained in

Compare how 35 books explain filtering →

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.