Two-Tower Retrieval Models
Scaling candidate retrieval across millions of items in sub-10ms using dual deep neural networks.
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 user-item interaction pairs :
- Positive Pair: (User clicked Item ).
- Negative Pairs: Items () clicked by OTHER users in the mini-batch (In-Batch Negatives).
- : Temperature scaling hyperparameter (typically ).
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
- What is Sampling Bias in In-Batch Negatives? Popular items appear more frequently in mini-batches, causing them to be sampled as negative items more often. Correct using Log Q Correction: .
- What is Mixed Negative Sampling? Combining In-Batch Negatives with explicit Random Uniform Negatives to ensure the model learns both popular item discrimination and hard tail item retrieval.
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?