Data & ML · Advanced

Two-Tower Recommender Engine

Build a production recommender with two-tower retrieval and a ranking model, serve nearest-neighbor candidates from an ANN index, and run an offline-to-online A/B eval loop.

Advanced20-35 hoursPythonAI

You build a full two-tower retrieval plus reranking pipeline on a public interaction dataset (MovieLens or Amazon Reviews), then serve it behind a FAISS approximate-nearest-neighbor index with a BentoML HTTP endpoint. The project covers the full MLOps loop: offline training tracked in MLflow, online candidate retrieval, a pointwise ranking model that rescores the top-K candidates, and an A/B evaluation harness that compares ranking strategies using recall, NDCG, and online click-through proxies. It is worth building because two-tower retrieval is the production architecture behind YouTube, Pinterest, and TikTok recommendations, and most tutorials stop before the serving and eval layers.

What you build

  • Train separate user and item embedding towers in PyTorch and export them independently
  • Build and persist a FAISS IVF-PQ index over all item embeddings for sub-millisecond ANN retrieval
  • Implement a pointwise ranking model that rescores the top-K FAISS candidates using dense features
  • Track every experiment run (embeddings, hyperparameters, retrieval metrics) in MLflow
  • Serve the retrieval and ranking stack as a single BentoML service with a /recommend endpoint
  • Run an offline A/B eval loop comparing random, popularity, retrieval-only, and full pipeline strategies on held-out data
  • Export quantized ONNX towers so the index can be rebuilt incrementally as new items arrive

What it teaches

  • Two-tower architecture design: separate encoding of query and item spaces with in-batch negative sampling
  • Approximate nearest neighbor indexing with FAISS: index types (Flat, IVF, PQ), trade-offs between recall and latency
  • MLOps experiment tracking with MLflow: logging metrics, artifacts, and model registry promotion
  • Reranking as a second-stage model: pointwise scoring over a small candidate set vs. full corpus
  • Offline evaluation methodology: train/val/test splits by time, ranking metrics (NDCG, MRR, recall@K)
  • Production model serving with BentoML: packaging multi-model pipelines into a single versioned service

How it works

  1. 1

    Raw Interactions

    • MovieLens events
    • user/item features

    preprocess

  2. 2

    Two-Tower Training

    • user MLP tower
    • item MLP tower
    • MLflow tracking

    embed

  3. 3

    ANN Index Build

    • item embeddings
    • FAISS IVF-PQ

    retrieve

  4. 4

    Online Retrieval

    • user query vector
    • top-K candidates

    rescore

  5. 5

    Ranking Model

    • dense features
    • pointwise scorer

    serve

  6. 6

    BentoML Service

    • /recommend endpoint
    • A/B eval logger
fig. 01 — data flows from raw interactions through dual tower training into a faiss index, then through online retrieval and reranking to a served http response.

Sign in to open the build guide

Free account. Get the step-by-step build and every resource link.

Sign in to continue

Take it further

  • Add a real-time feature store layer using Redis so user interaction counts update without full retraining
  • Implement hard-negative mining to improve tower training quality and measure the lift in recall@10
  • Deploy the BentoML service to a cloud instance and add a lightweight feedback loop that logs impressions and clicks to retrigger nightly retraining

More like this

All projects