Large-Scale Learned Retrieval System with Two-Tower Architecture

pinterest · Tech · 2024 · source Agentic: no · promotional bias: low · source-backed · extracted with prompt 0.5.6 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Large-scale learned retrieval for recommendations

Pinterest needed to modernize candidate generation for homefeed and notifications by moving from heuristic retrieval to learned embedding-based retrieval over billions of pins. The system had to serve more than 500 million monthly active users, compute fresh user embeddings online, precompute item embeddings offline, support periodic retraining, avoid mismatched embedding spaces across separately deployed services, and improve engagement enough to consolidate existing candidate generators.

Constraints:

Architecture

Pinterest built a two-tower learned retrieval system trained from logged user engagement events. The user tower encodes long-term engagement, profile, context, and real-time sequence features, while the item tower computes Pin embeddings. Training uses sampled softmax with in-batch negatives and logit correction for item popularity bias. Serving splits online user-embedding computation from offline item-embedding indexing: the homefeed backend computes the user embedding at request time, then queries Pinterest's Manas ANN serving system over precomputed item embeddings. Auto-retraining periodically refreshes the model and validates performance before deployment. Each ANN host carries model-version metadata generated with the index so the backend computes user embeddings using the matching model version, including during rolling index deployments and rollback.

Diagram confidence: reconstructed (reconstructed from prose).

flowchart LR
  events["Logged engagement events"] --> model["Two-tower retrieval model"]
  model --> user["User tower"]
  model --> item["Item tower"]
  item --> index["Offline indexing pipeline"]
  index --> manas["Manas ANN serving system"]
  index --> metadata["Model version metadata"]
  metadata --> manas
  backend["Homefeed backend"] --> metadata
  backend --> user
  backend --> manas
  backend --> funnel["Recommendation funnel"]
  funnel --> generator["Learned retrieval candidate generator"]
  retrain["Auto-retraining workflow"] --> model
  retrain --> index
  retrain --> generator
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Logged engagement events Training signal for the learned retrieval system. Two-tower retrieval model
Two-tower retrieval model Model architecture with separate user and item towers trained for candidate retrieval. Logged engagement events, User tower, Item tower, Auto-retraining workflow
User tower Encodes long-term engagement, user profile, context, and real-time sequence features into query embeddings. Two-tower retrieval model, Homefeed backend, Model version metadata
Item tower Computes Pin/item embeddings in the same embedding space as user embeddings. Two-tower retrieval model, Offline indexing pipeline
Offline indexing pipeline Precomputes item embeddings, builds ANN indexes, and generates model-version metadata with each index. Item tower, Manas ANN serving system, Model version metadata, Auto-retraining workflow
Manas ANN serving system Pinterest's in-house approximate-nearest-neighbor serving system for item embeddings. Offline indexing pipeline, Homefeed backend, Model version metadata
Model version metadata Per-ANN-host mapping from model name to latest matching model version, generated with the index. Manas ANN serving system, Homefeed backend, User tower
Homefeed backend Request-time service that obtains ANN-host metadata, computes matching user embeddings, and retrieves personalized candidates. User tower, Manas ANN serving system, Model version metadata, Recommendation funnel
Recommendation funnel Pinterest multi-stage funnel that retrieves billions of candidates, narrows them to thousands, scores them, and generates feeds. Homefeed backend, Learned retrieval candidate generator
Learned retrieval candidate generator Production candidate generator using the two-tower retrieval system for homefeed and notifications. Recommendation funnel, Auto-retraining workflow
Auto-retraining workflow Periodic refresh process that retrains models, validates performance, deploys model and index artifacts, and supports rollback. Two-tower retrieval model, Offline indexing pipeline, Learned retrieval candidate generator

Data flow

Logged engagement events train a two-tower retrieval model. The item tower precomputes millions of item embeddings and pushes them into Manas for ANN search. At request time, the backend computes a user embedding from long-term engagement, profile, context, and real-time sequence signals, asks the assigned ANN host for its model-version metadata, loads the corresponding user tower, and retrieves candidates from the matching item-embedding index. Retrieved candidates flow into Pinterest's multi-stage recommendation funnel, where lightweight scoring and ranking narrow billions of candidate pins into personalized feeds.

4 supporting quotes
“learned purely from logged user engagement events and serves in production.”article, stated
“user embedding is computed during request time so it can leverage the most up-to-date features”article, stated
“millions of item embeddings are computed and pushed to our in-house Manas serving system for online serving.”article, stated
“homefeed backend will first get the version metadata from its assigned ANN service host”article, stated

Why this architecture

Pinterest uses two towers because independent user and item embeddings make nearest-neighbor retrieval cheap enough for online serving while still allowing personalized request-time user features. Offline item indexing avoids recomputing millions of item embeddings per request. The model-version metadata exists because two-tower systems create separate user-model and item-index artifacts; without synchronization, partial rollouts or rollback would make the user embedding and item embedding spaces incompatible.

4 supporting quotes
“The online serving will be cheap with nearest neighbor search with query embedding and item embeddings.”article, stated
“we break it down into two pieces: online serving and offline indexing.”article, stated
“two-tower models are split into two model artifacts and deployed to separate services.”article, stated
“candidate quality will drastically drop if the embedding space is mismatched.”article, stated

Models used: two-tower retrieval model · user tower · item tower · PinnerSage · sequence transformer · transformer-based ranking model · Manas ANN serving system · HNSW

Scale

Alternatives considered (roads not taken)

Continue heuristic retrieval based on Pin-Board graphs or followed interests

Rejected because: Pinterest built an embedding-based system learned from logged user engagement events to improve candidate generation.

“many of them are based on heuristic approaches such as those based on Pin-Board graphs or user-followed interests.”article, stated
“building Pinterest an internal embedding-based retrieval system for organic content learned purely from logged user engagement events”article, stated

Compute softmax over the entire item corpus

Rejected because: The full corpus contains billions of items, so Pinterest used sampled softmax with in-batch negatives.

“we can not do softmax over all item corpus”article, stated
“we can easily leverage in batch negative, which provides a memory efficient way of sampling negative.”article, stated

Deploy user-tower and item-index artifacts independently without synchronization

Rejected because: Mismatched embedding spaces drastically reduce candidate quality, especially during index rollout or rollback.

“If we do not consider version synchronization”article, stated
“candidate quality will drastically drop if the embedding space is mismatched.”article, stated

Refresh models manually or infrequently

Rejected because: Pinterest says real-world recommendation systems need frequent retraining to capture recent user preferences and content trends.

“it’s a necessity to frequently retrain the models to refresh the learned knowledge of users and capture recent trends.”article, stated

Patterns

retrieval-ranking (retrieval)

Pinterest uses a learned embedding-based candidate generator before lightweight scoring and ranking in a multi-stage recommendation funnel.

“retrieval aims at retrieving candidates from billions of candidate pools, and ranking predicts which item a user tends to engage”article, stated
“the learned retrieval candidate generator aims for driving user engagement.”article, stated

latency-optimization (serving)

Pinterest splits serving into request-time user embeddings and offline item indexing so online retrieval can use nearest-neighbor search efficiently.

“The online serving will be cheap with nearest neighbor search with query embedding and item embeddings.”article, stated
“we break it down into two pieces: online serving and offline indexing.”article, stated

eval-driven-development (model-operations)

The auto-retraining workflow validates model performance before deploying refreshed model and index artifacts.

“We established an auto retraining workflow to retrain the models periodically and validate the model performance before deploying them”article, stated

fallback-degradation (reliability)

Pinterest keeps the latest N user-tower versions so rollback of the ANN service can still compute embeddings in the matching space.

“to ensure rollback capability, we keep the latest N versions of the viewer model”article, stated
“compute the user embeddings from the right model even if the ANN service is rolled back to its last build.”article, stated

canary-rollout (deployment)

The version metadata supports partial ANN-host rollouts where some hosts run version N while others run N+1 without embedding-space mismatch.

“this ensures that during the rollout period, a certain percentage of the traffic won’t suffer from model version mismatch.”article, stated
“even if some ANN hosts have model versions N and others have versions N+1 during the index rollout period”article, stated

Tradeoffs

Retrieval representation

Chose Embedding-based learned retrieval over Heuristic graph or interest-based retrieval.

Rationale: Pinterest wanted organic-content retrieval learned from logged engagement events and deployable across homefeed and notifications.

“heuristic approaches such as those based on Pin-Board graphs or user-followed interests.”article, stated
“internal embedding-based retrieval system for organic content learned purely from logged user engagement events”article, stated

Training objective approximation

Chose In-batch negative sampled softmax over Softmax over the full item corpus.

Rationale: The full corpus is too large, so sampled negatives provide a memory-efficient training approximation.

“we can not do softmax over all item corpus”article, stated
“in batch negative, which provides a memory efficient way of sampling negative.”article, stated

Serving split

Chose Online user embeddings plus offline item indexing over Compute both sides online or precompute both sides only offline.

Rationale: Request-time user embeddings incorporate fresh user features, while offline item indexing keeps item retrieval scalable.

“user embedding is computed during request time so it can leverage the most up-to-date features”article, stated
“millions of item embeddings are computed and pushed to our in-house Manas serving system”article, stated

Version synchronization mechanism

Chose ANN-host metadata mapped to model versions over Assume the latest user model and latest item index are always compatible.

Rationale: Per-host metadata handles partial rollouts, different deployment speeds, and rollback without mismatched embedding spaces.

“we attach a piece of model version metadata to each ANN search service host”article, stated
“even if some ANN hosts have model versions N and others have versions N+1 during the index rollout period”article, stated

Gotchas (what bit them)

Two-tower retrieval creates a hidden version-coupling problem.

Root cause: The user tower and item tower become separate artifacts deployed to separate services, and the item index often takes longer to build than the viewer model.

Resolution: Generate per-ANN-host model-version metadata with the index and have the backend compute user embeddings with the corresponding model version.

“two-tower models are split into two model artifacts and deployed to separate services.”article, stated
“The metadata is generated together with the index.”article, stated

Embedding-space mismatch can cause candidate quality to collapse.

Root cause: A user embedding from one model version may be searched against an item embedding index from another version.

Resolution: Use anytime synchronization so the user model version always matches the assigned ANN host's index version.

“candidate quality will drastically drop if the embedding space is mismatched.”article, stated
“This ensures “anytime” model version synchronization”article, stated

Training examples can teach popularity instead of relevance.

Root cause: Sampled training items reflect natural popularity bias in the training set.

Resolution: Apply logit correction based on estimated item probability.

“As we sample items from our training set that might have popularity bias, it is important for us to correct the sample probability”article, stated
“We use simple logic tuning based on the estimated probability for each item.”article, stated

Fresh recommendations require frequent retraining but frequent retraining increases deployment risk.

Root cause: User preferences and content trends change, while retrained model artifacts and indexes roll out at different speeds.

Resolution: Retrain periodically, validate performance before deployment, and coordinate model/index versions through metadata.

“frequently retrain the models to refresh the learned knowledge of users and capture recent trends.”article, stated
“validate the model performance before deploying them to the model and indexing services.”article, stated

Evaluation

Pinterest evaluates the learned retrieval system through model-performance validation before deployment, production homefeed candidate-generator metrics, user coverage, save rate, site engagement impact, and infrastructure behavior during rollouts and rollback.

Metrics: model performance validation before deployment · top user coverage · top three save rates · overall site engagement wins · candidate quality during rollout · ability to deprecate two other candidate generators · rollback compatibility through latest N viewer model versions

4 supporting quotes
“validate the model performance before deploying them to the model and indexing services.”article, stated
“Currently the learned retrieval candidate generator aims for driving user engagement. It has the top user coverage and top three save rates.”article, stated
“it has helped deprecate two other candidate generators with huge overall site engagement wins.”article, stated
“candidate quality will drastically drop if the embedding space is mismatched.”article, stated

Outcomes

The system operates in Pinterest's recommendation funnel for over 500 million MAUs, retrieves from billions of Pin candidates, narrows to thousands before ranking, computes millions of item embeddings for Manas ANN serving, and participates in a homefeed system with over 20 production candidate generators.

4 supporting quotes
“We have deployed our system for homefeed as well as notification.”article, stated
“It has the top user coverage and top three save rates.”article, stated
“it has helped deprecate two other candidate generators with huge overall site engagement wins.”article, stated
“This ensures “anytime” model version synchronization”article, stated