Walk me through two-tower models for retrieval — architecture, tradeoffs, and limits
Written by the mlprep team · Updated
Walk me through a two-tower model for candidate retrieval. What are its limitations versus a single cross-attention model, and why do we use it anyway at scale?
The retrieval problem#
In a recommendation system, you have N items (N = 10M to 1B). For each user request, you need to score candidates and return the top k. Scoring all N items with a heavy ranking model (deep cross networks, feature interactions, attention) at query time is O(N) and infeasible at millisecond latency.
Retrieval (candidate generation) narrows N items to a few hundred or thousand that a heavier ranker can then score. The retrieval stage must be both fast and high recall — if it misses the best item, the ranker never sees it.
Two-tower architecture#
Two separate neural networks (towers) encode the query and item independently into a shared embedding space:
query_embedding = f(user_features, context) # query tower
item_embedding = g(item_features, item_content) # item tower
score(query, item) = dot_product(query_embedding, item_embedding)
Item embeddings are precomputed and indexed offline. At serving time, only the query tower runs (fast). Retrieval becomes a nearest-neighbor search in embedding space — find top-k items whose embeddings are closest to the query embedding.
Why this enables scale#
Precomputed item embeddings + approximate nearest neighbor (ANN) search (FAISS, ScaNN, Annoy) reduces retrieval from O(N·model_cost) to O(query_tower_cost + ANN_search_cost). ANN search with 1B items runs in milliseconds using HNSW or product quantization indexes.
The fundamental limitation: no cross-attention#
Because the towers are independent, query and item cannot interact during encoding. Features like "does this item's title contain the user's searched keyword?" or "how similar is this item to the last item the user liked?" require joint encoding — the towers can't capture these.
A single model with cross-attention between query and all items would be far more expressive:
score(query, item) = CrossAttention(query_features, item_features)
But this requires running the full model for every query-item pair — O(N) per request, infeasible at scale.
What gets lost#
- Query-conditional item representations: "this video is highly relevant specifically because the user just searched for 'cooking pasta'"
- Fine-grained semantic matching between query text and item content
- Interaction features (query × item crosses) that are powerful for ranking
Practical mitigations#
Hard negatives in training: train the two towers with in-batch negatives plus mined hard negatives (items that are semantically close but shouldn't be retrieved for this query). Pushes the model to use the shared embedding space more discriminatively.
Late interaction models (ColBERT): encode query and item independently but compute interaction at retrieval time using MaxSim over per-token embeddings rather than a single pooled vector. More expressive than dot product on pooled embeddings, still cheaper than full cross-attention.
Two-stage: two-tower retrieval → cross-attention ranker. The ranker sees full query-item interaction for the top-k candidates. Most production recommendation systems (YouTube, TikTok, LinkedIn) use this multi-stage architecture.
Training the towers#
Trained with contrastive loss (e.g., in-batch softmax, noise-contrastive estimation). Positive pairs: (user, item they interacted with). Negatives: all other items in the batch plus mined hard negatives. The objective: push positive pair embeddings close, negative pair embeddings apart.
Senior/staff considerations#
A strong answer should frame two-tower models as a recall-and-latency system, not just an architecture. The retrieval model is allowed to be less expressive than the ranker because its job is to avoid false negatives at candidate generation time. A strong ranker cannot recover an item the retriever never surfaced.
Key production questions:
- Recall@k against what? Measure retrieval recall against high-quality labels, downstream ranker positives, or human judgments. Do not rely only on training loss.
- How diverse are the candidates? A two-tower can collapse to popular items and still look good on aggregate recall. Track source diversity, catalog coverage, freshness, and segment recall.
- What is the negative sampling distribution? Random negatives are too easy. Use in-batch negatives, popularity-corrected negatives, and ANN-mined hard negatives. But avoid false negatives: items the user would have liked but did not see.
- How is the ANN index operated? Version the query tower, item tower, embeddings, and index together. Mixing query embeddings from v12 with item embeddings from v11 silently destroys retrieval quality.
- What is the fallback? New users, new items, index rebuild failures, and cold-start content need heuristic or content-based fallback retrievers.
Interview red flags#
- Saying two-tower "solves recommendations" without mentioning reranking.
- Ignoring selection bias in interaction labels.
- Optimizing top-1 accuracy instead of high-recall candidate generation.
- Forgetting that index rebuilds, embedding versioning, and latency budgets are part of the model design.
The key takeaway unlocks after you reveal an expert answer.
Key Takeaway
Two-tower: query tower and item tower encode independently, score = dot product in shared space. Key win: item embeddings precomputed, retrieval = ANN search (milliseconds for 1B items). Key loss: no query-item interaction during encoding — can't capture cross features. Used because it's the only architecture that scales to O(1B) candidates. Pair with a heavy cross-attention ranker on the top-k retrieved candidates.
Follow-up Questions to Test Yourself
Interviewers often pivot here once you cover the core concept.
- How do you mine hard negatives for training a two-tower model, and why are in-batch negatives alone insufficient?
- What is ColBERT's late interaction approach and how does it trade off expressiveness vs. retrieval cost compared to two-tower?
- How do you handle the cold start problem for new items in a two-tower retrieval system?
How confident do you feel explaining this?
Track your understanding or flag it to revisit before your next loop.
Related Questions
Design a multi-stage ranking funnel — retrieval, pre-rank, rank, re-rank
How does multi-task learning work for ranking — and what are the failure modes?
When do you use a cross-encoder reranker instead of a bi-encoder?
How would you design a recommendation system for Reddit?