RecSys & Search

Two-Tower Retrieval Models

Scaling candidate retrieval across millions of items in sub-10ms using dual deep neural networks.

🔴 advanced5 min readrecsysretrieval
Two-Tower Retrieval Models (DSSM - Huang et al., 2013; Covington et al., 2016 / YouTube DNN) power candidate generation in industrial RecSys. The architecture uses two independent neural networks: a User Tower projecting user context (demographics, history) into vector u, and an Item Tower projecting item metadata into vector v. At inference time, item embeddings are pre-computed offline, reducing candidate retrieval over millions of items to sub-10ms vector search (u · v) via ANN indexes (HNSW).

Two-Tower Architecture (YouTube DNN Pattern)

  USER CONTEXT FEATURES                                ITEM METADATA FEATURES
  (User ID, Age, Watch History, Device, Location)       (Video ID, Title Embeddings, Channel, Duration)
           │                                                     │
           ▼                                                     ▼
  [ USER TOWER (MLP + Embeddings) ]                     [ ITEM TOWER (MLP + Embeddings) ]
           │                                                     │
           ▼                                                     ▼
     User Vector u [1 × 128]                               Item Vector v [1 × 128]
           │                                                     │
           └──────────────────────────┬──────────────────────────┘
                                      ▼
                            Dot Product: Score(u, v) = u · v

Real-Time Production Serving Loop

  OFFLINE BATCH PHASE:
  Run Item Tower over 10,000,000 Catalog Items ──► Pre-compute Items Matrix V [10M × 128]
  Index V in Vector DB (HNSW / Qdrant)

  ONLINE REAL-TIME INFERENCE (< 10ms):
  User Requests Feed ──► Pass User Features through User Tower ──► Output Vector u [1 × 128]
  Execute Vector Search: Top 1000 = HNSW_Search(u, V) ──► Pass 1,000 Candidates to Ranking Stage!

Loss Formulation: In-Batch Sampled Softmax

Given a mini-batch of $B$ user-item interaction pairs ${(u_1, v_1), (u_2, v_2), \dots, (u_B, v_B)}$:

$$\mathcal{L} = -\frac{1}{B} \sum_{i=1}^B \log \frac{\exp(\mathbf{u}_i \cdot \mathbf{v}i / \tau)}{\sum{j=1}^B \exp(\mathbf{u}_i \cdot \mathbf{v}_j / \tau)}$$

Say this out loud

"Two-Tower models decouple user and item feature processing into independent neural networks, projecting both into a shared embedding space. Pre-computing item embeddings offline enables sub-10ms candidate retrieval over millions of items via ANN vector search (u · v). We train two-tower models using in-batch sampled softmax loss."

Follow-ups to expect

Check yourself

Question 1 of 3

Why does a Two-Tower Retrieval Model separate User feature processing from Item feature processing into two independent neural networks?

More in RecSys & Search

See all →
Collaborative Filtering5 minThe Cold Start Problem4 minTwo-Stage: Retrieval then Ranking5 min