SS
Diagram of a two-stage recommendation pipeline architecture

Building a 2-Stage Anime Recommender: From Naive TF-IDF to Industry-Grade Architecture

·10 min read·
Recommender SystemsLightGBMSentence TransformersCollaborative FilteringPython

The Origin Story & The Problem

As an avid anime fan, my first recommendation engine used a basic TF-IDF vectorization and cosine similarity filter.

It quickly hit a massive accuracy wall:

  • - Semantic blindness: Only matching exact keyword overlaps.
  • - Popularity bias: Missing latent user preferences by defaulting to mainstream hits.
  • - Scalability bottlenecks: Struggling with the single-stage problem of scaling catalog comparisons.

This failure pushed me to build a production-grade two-stage recommendation architecture (inspired by YouTube’s landmark research) that blends fast candidate retrieval with deep personalization to help fellow fans discover true hidden gems.


The Approach

To solve the scale and accuracy trade-off, I split the recommendation engine into a two-stage pipeline:

  • 1. Candidate Generation (Retrieval):
    • - Content Filtering: Generated dense semantic embeddings of synopses and metadata using sentence-transformers/all-MiniLM-L6-v2 to capture deep thematic relationships.
    • - Collaborative Filtering: Leveraged user-item interaction matrices processed via Alternating Least Squares (implicit/ALS) to extract latent user preferences and peer behavior.
  • 2. Re-Ranking:
    • Combined and filtered candidates passed into a LightGBM model (complete with hyperparameter tuning).
    • The ranker evaluates user history, metadata features, and cross-interaction scores to output a finely tuned top-10 list.

The Results

  • 3.2x training speedup and efficiency boost through sparse-matrix optimizations and LightGBM.
  • 45ms end-to-end inference latency via FastAPI, ensuring real-time responsiveness.
  • Significantly higher recommendation relevance and diversity compared to the legacy TF-IDF approach.

Key Architectural Decisions

  • Decoupled Retrieval from Ranking: While candidate generation casts a wide net to pull hundreds of relevant items instantly using vector search and matrix factorization, the heavy lifting is reserved for the gradient-boosting re-ranker.
  • Feature-Rich Interactions: Allowing LightGBM to evaluate complex feature interactions without blowing past runtime latency limits.