Recommender systems
Embeddings and Two-Tower Retrieval
Understand user and item towers, embedding objectives, precomputation, retrieval recall, and the gap between geometric proximity and final utility.
By the end you can
- Explain the two-tower architecture and why item embeddings can be precomputed
- Distinguish retrieval-stage and ranking-stage objectives and features
- Identify architectural, sampling, norm, and freshness failure modes
- Design candidate-recall and index-quality evaluation
Two-tower models separate query encoding from corpus encoding
A user or context tower produces a query embedding. An item tower produces item embeddings on its own. Similarity between the two is what makes large-scale retrieval possible, because item vectors can be precomputed and indexed.
The funnel has exact dimensions. Candidate generation reduces a corpus of millions of videos to hundreds. Ranking scores those hundreds down to dozens. Google published the design of YouTube's recommender in 2016. Retrieval itself is served as an approximate nearest-neighbour lookup in dot-product space, and it has to finish under a strict serving latency of tens of milliseconds.
Two orders of magnitude separate the stages, and that gap decides what each one is allowed to see. The paper puts it in one sentence: “During ranking, we have access to many more features describing the video and the user's relationship to the video because only a few hundred videos are being scored rather than the millions scored in candidate generation.”
Keeping the towers apart is what buys the scale. It is also what limits them. Cross-features between a specific user and a specific item cannot be computed inside either tower. Retrieval trades detailed pairwise reasoning for broad matching a machine can finish in milliseconds across millions of candidates. The scale is bought with a blind spot.
Whatever the separated towers cannot see about a specific user-item pairing never reaches the ranker, so cheap retrieval is paid for further down the stack.
Case
The item tower exists so the index can be built in advance
Two towers exist so the item side can be computed before any request arrives. Google's 2019 retrieval paper states the split in its own words: “in this paper, we consider a modeling framework with two-tower neural networks where one network called item tower is used to encode a wide variety of item features”.
That is not a diagram in a paper. The Neural Deep Retrieval system built on it was deployed to serve YouTube recommendations over a corpus of tens of millions of videos. The same paper's sampling-bias correction is motivated explicitly by the power-law item distribution in in-batch negatives. An item side that size does not train itself evenly.
Facebook's search team published the serving half in 2020. Embedding retrieval runs there on top of a typical search system's inverted index. Tuning the approximate-nearest-neighbour parameters is treated as part of the system, not as a detail left to the index.
Tens of millions of item vectors on one side. A request waiting on the other. That is the constraint the architecture was built to satisfy.
Example
The retriever never surfaced the best item
A learning app ran a powerful ranker behind a two-tower retriever. Offline, the ranker looked excellent on the candidates it was handed. The advanced course the user needed was not among them, because the item tower encoded only title and category. No amount of ordering recovers an item that candidate generation never passed on. The ranker scores the hundreds it receives, not the corpus.
- User tower: Combined recent history, profile, and context into a query vector.
- Item tower: Precomputed vectors from item ID, metadata, and content features.
- Similarity score: Dot product enabled fast maximum-inner-product search.
- Information bottleneck: The retriever could use only features available in the separate towers, so what the item tower omitted was unreachable at any K.
- Pipeline effect: Ranking quality was bounded by candidate recall — exactly what a millions → hundreds → dozens funnel implies.
Visual
The two-tower serving path
Two towers, computed at different times. The item tower runs offline or nearline across the whole corpus — tens of millions of videos, in the Neural Deep Retrieval deployment. The query tower runs from user and context features while the request is waiting. It works inside the budget the YouTube paper records for retrieval: an approximate nearest-neighbour lookup in dot-product space, under a strict latency of tens of milliseconds.
They meet in the vector index. What comes back is not a recommendation. It is a candidate handoff — identifiers, scores, source labels, freshness. Everything downstream is an ordering of that handoff.
User/context features
Encode history, session, surface, locale, and request-time state.
Query tower
Produce a fixed-dimensional embedding for the current request.
Item tower
Encode item identity, metadata, content, and freshness offline or nearline.
Vector index
Search the item corpus by dot product or distance.
Candidate handoff
Return IDs, scores, source labels, and freshness metadata to ranking.
Steps
Fix the retrieval target, then the handoff
The retrieval target is a separate decision from the ranking target, and it gets written down first. Feature partition, similarity choice and index lifecycle follow. Source recall is the number that says whether retrieval did its job.
Step 3, choosing the similarity, has a published answer rather than a preference. In 2020 Rendle's group at Google re-ran the neural-collaborative-filtering experiments. The data was binarised MovieLens 1M and a Pinterest dataset. Each user's held-out item was ranked against 100 random items and scored by HR@10 and NDCG@10, at embedding dimensions of 16, 32, 64, 96, 128 and 192. The dot product beat the learned MLP similarity on every dataset, every metric, every dimension.
Their serving argument is separate from the accuracy one: “MLPs are too costly to use for item recommendation in production environments while dot products allow to apply very efficient retrieval algorithms”. Efficient sublinear-time retrieval exists for dot products and, to those authors' knowledge, not for MLP similarities. Validate norms in the same step, because dot product and cosine coincide only under the equal-norm condition.
Step 4, the index lifecycle, has a published operating curve too. ANN-Benchmarks fixes the datasets. GLOVE: 1,183,514 points and 10,000 queries in 100 dimensions, under angular/cosine distance. SIFT: 1,000,000 points and 10,000 queries in 128 dimensions, under Euclidean distance. Recall is defined against the true k nearest neighbours and plotted against queries per second. On SIFT with 10-NN in batched mode, the price of the last stretch of recall is explicit: “FAISS' inverted file index on the GPU is by far the fastest index, answering around 655 000 queries per second for .7 recall, and 61 000 queries per second for recall .99.”
Same index, same data, two very different machines. Index quality is a point you choose on that curve, not a property an index either has or lacks.
1. Define retrieval target
Choose relevant positives, horizon, and eligible corpus.
2. Partition features
Use only features computable in the appropriate tower at serving time.
3. Choose similarity
Validate dot product, cosine, normalization, and vector norms.
4. Build index lifecycle
Version embeddings, index, filters, and freshness guarantees.
5. Measure source recall
Track whether downstream positives enter candidates across key slices.
Example
Two-tower failure modes
Tower feature omission is structural. The architecture cannot represent a user-item interaction that matters, and the loss is taken before any ranker is consulted. Facebook Search measured what the tower's feature set alone is worth: “For example, there are +18% recall improvement when switching from text to unified embeddings for events search, and +16% recall improvement for groups search.” The ranker was not touched. Only what the retrieval model was permitted to encode changed.
Ranker illusion is the procedural twin of that structural fault. The team measures the stage it can see while recall in the stage it cannot quietly falls away.
- Tower feature omission: A decision-relevant user-item interaction cannot be represented in either tower separately. The missing pieces are individually priceable. For the groups model the same paper itemises the incremental absolute recall gains: +2.20% from location features and +1.77% from social-embedding features, both on top of a text-feature baseline.
- Embedding staleness: Item or user state changes faster than the index refresh, so the vectors being searched describe a corpus that has already moved.
- Norm exploitation: Large embedding norms dominate inner-product retrieval. Google's 2020 paper on anisotropic vector quantization states the exact condition under which that stops being a hazard: “MIPS is equivalent to cosine similarity search when all datapoints are equal-norm, so we adopt our technique to cosine similarity search by unit-normalizing all datapoints at training time.”
- Head-item collapse: Training and sampling make popular items occupy too much retrieval space. Google's 2019 retrieval paper motivates its sampling-bias correction on precisely this, the power-law item distribution in in-batch negatives.
- Ranker illusion: Teams optimize ranking while candidate recall silently deteriorates. The ranker's own numbers cannot report it, because it only ever scores the few hundred items candidate generation passed on.
Retrieval evaluation must precede ranking evaluation
Measure recall@K against mature outcomes, source overlap, tail coverage, new-item recall, user-state slices and index freshness. Then compare exact search on samples with approximate search, to separate model loss from index loss.
Facebook Search names that second comparison and runs it. The metric is stated plainly: “We measured ANN accuracy using 1-recall@10, which is averaged recall of getting top result from exact KNN search in top 10 results of ANN search.” The paper reports it for eight quantization configurations of one 128-dimension embedding, all at comparable scan cost — 0.48% to 0.60% of the index. The worst, PCA,PQ16, scores 51.62%. The best, PQ64 and Flat, score 74.81%. Roughly 23 points of 1-recall@10, with the embedding model held fixed. That is how much recall the index alone can take from a retriever whose vectors never changed.
Geometric proximity is also not final utility, and that gap has been measured across a whole benchmark rather than argued. BEIR evaluated 10 retrieval systems across 18 public datasets: “Dense retrieval models (esp. ANCE and TAS-B), that map queries and documents independently to vector spaces, perform strongly on certain datasets, while on many other datasets perform significantly worse than BM25.” BM25 uses no embeddings at all and remained the robust baseline. DPR was the worst overall, −47.7% on average against it. The cross-attention re-ranker BM25+CE beat BM25 on 16 of the 18 datasets.
In-domain strength predicted none of it. On MS MARCO, in domain, BM25 trailed the neural approaches by 7 to 18 points.
Watch the handoff for the same reason when retriever and ranker are trained on different objectives. A retriever optimized for clicks can omit candidates a long-term-value ranker would have preferred.
Ranking metrics can only grade the candidates retrieval already handed over, so an item lost at recall is lost quietly and for good.
Key idea
The retrieval gate
Slate failure belongs to ranking only once the relevant item has had a fair chance to enter the candidate set. That means shown to have been among the hundreds handed over, not merely present in the corpus of millions.
Send a bad slate back to retrieval first; tuning the ranker for an item that never entered the candidate set spends effort where the loss did not happen.
Key takeaways
- The dot product is not a stylistic choice. When Rendle's group re-ran the neural-collaborative-filtering experiments, it beat the learned MLP similarity on every dataset, metric and dimension. Unlike MLP similarities, it also admits efficient sublinear-time retrieval.
- A user or context tower produces a query embedding; an item tower encodes a wide variety of item features independently. That split is what let the Neural Deep Retrieval system serve YouTube recommendations from a corpus of tens of millions of videos.
- Two-tower retrieval is a candidate-generation contract: high recall under latency, not the final definition of recommendation quality. YouTube's funnel gives the contract its scale — millions of videos to hundreds at candidate generation, hundreds to dozens at ranking.
- The query tower encodes history, session, surface, locale and request-time state. It has to do all of that inside the strict serving latency of tens of milliseconds that retrieval is given.
- Tower feature omission has a measured size. When Facebook's retrieval model moved from text to unified embeddings, recall improved +18% for events search and +16% for groups search, with the ranker untouched.
- Retrieval earns its place only if downstream positives reach the candidate set at all. Track source recall slice by slice and read index loss separately — eight quantization configurations of one 128-dimension embedding spanned 51.62% to 74.81% on 1-recall@10 at comparable scan cost.