case study 8 min read

Inside Kuaishou's OneRec: Collapsing the 3-Stage RecSys Funnel

Ludovico Bessi

By Ludovico Bessi

Senior Machine Learning Engineer at Google · Zurich

How Kuaishou's OneRec replaces retrieval, pre-ranking, and ranking with a single sparse MoE generative recommender using Balanced K-Means IDs and iterative DPO.

Kuaishou OneRec generative recommendation MoE DPO RecSys
Kuaishou OneRec End-to-End Generative Recommendation Architecture: Balanced Semantic IDs, Sparse MoE Decoder, and Iterative DPO
Kuaishou's OneRec collapses the classic 3-stage RecSys cascade into one 1B-parameter sparse MoE encoder-decoder trained with Balanced K-Means semantic IDs and Iterative DPO.

TL;DR

  • Kuaishou's OneRec replaces the traditional 3-stage RecSys funnel (retrieval, pre-ranking, ranking) with a single 1B-parameter sparse MoE encoder-decoder (~13% active parameters per pass).
  • It prevents RQ-VAE codebook collapse via 3-layer Balanced K-Means quantization (K=8,192) and generates full 5–10 item sessions rather than isolated next items.
  • Iterative Preference Alignment (DPO with beam-128 self-hard negatives scored by an offline reward model) drove +1.68% total watch time and +6.56% average view duration on Kuaishou main traffic.

Direct answer: OneRec is Kuaishou's end-to-end generative recommendation architecture that replaces the traditional three-stage funnel (retrieval → pre-ranking → ranking) with a single sparse Mixture-of-Experts encoder-decoder (~1B parameters, 24 experts, top-2 active = ~13% active per pass). It maps a billion-item corpus into hierarchical tokens via Balanced K-Means quantization, autoregressively generates full 5–10 item sessions instead of isolated single items, and aligns list quality via Iterative Preference Alignment (DPO) using beam-search self-hard negatives — achieving +1.68% total watch time and +6.56% average view duration on Kuaishou's main traffic.

This is a public engineering overview of Kuaishou's OneRec paper — read the full Substack edition for P99 serving optimizations and production latency trade-offs at Collapsing the Recommendation Funnel: Inside Kuaishou's OneRec.

Why Cascaded RecSys Funnels Hit an Architectural Ceiling

Nearly every web-scale recommender system runs a multi-stage funnel: fast two-tower ANN retrieval over millions of items, a lightweight pre-ranker over thousands, and a heavy cross-feature ranker over dozens.

That cascade keeps latency tractable, but it creates two structural caps:

  1. Recall bottlenecks everything downstream: If retrieval drops a great item because a dot product misses fine-grained interactions, the heavy ranker never sees it.
  2. Pointwise scoring ignores session coherence: Ranking items independently forces teams to bolt on brittle re-ranking heuristics for intra-list diversity and pacing.

Earlier generative recommenders (like TIGER) proved models could generate item IDs directly, yet in production they were typically deployed as just another retrieval source. Kuaishou's OneRec goes all the way: one generative model serving full sessions from a billion-item catalog.

The Three Technical Pillars of OneRec

1. Balanced Semantic Quantization (Fixing Codebook Collapse)

Autoregressive generation requires mapping continuous multimodal item embeddings into discrete token sequences. Standard Residual Quantized VAEs (RQ-VAE) suffer from codebook collapse — an "hourglass" distribution where a small handful of code words absorb most items.

OneRec replaces RQ-VAE with multi-level Balanced K-Means quantization (L = 3 layers, K = 8,192 clusters per layer), strictly partitioning the item pool so every centroid receives an equal number of vectors. Each video becomes a balanced hierarchical semantic ID like <a_9><b_1><c_5>, progressively narrowing from coarse themes to a specific item.

2. Session-Wise List Generation on a Sparse MoE Backbone

Instead of predicting one next item at a time, OneRec takes 256 historical user interactions as encoder input and autoregressively generates an entire high-value session (5–10 items) in one shot, conditioned on session dwell time and engagement quality.

To keep P99 serving latency viable at a 1-billion-parameter scale, OneRec uses a T5-style encoder-decoder whose decoder feed-forward layers are replaced with a sparse Mixture-of-Experts (MoE) layer (24 experts, top-2 routed), activating only ~13% of total parameters per forward pass.

3. Iterative Preference Alignment (IPA) with Self-Hard Negatives

Standard Next-Token Prediction (NTP) teaches valid session syntax, not subtle ranking margins between two plausible playlists. Because you cannot show two exploratory sessions to the same user simultaneously, Kuaishou bridges preference data with an offline multi-head attention Reward Model (RM) predicting watch time, view-through rate, and likes:

  1. Run beam search (beam size 128) to generate candidate sessions.
  2. Score all 128 sessions with the offline Reward Model.
  3. Pair the highest-scoring session (chosen) against the lowest-scoring session (rejected) as self-hard negatives.
  4. Fine-tune OneRec iteratively with Direct Preference Optimization (DPO) on a rolling snapshot.

Live Production Impact on Kuaishou Main Traffic

  • +1.68% lift in total watch time
  • +6.56% increase in average view duration
  • Replaced a complex multi-stage retrieval/pre-ranking/ranking cascade with a single unified generative architecture

Read the full breakdown — including Kuaishou's P99 serving realities and infrastructure trade-offs — in the complete Substack edition: Collapsing the Recommendation Funnel: Inside Kuaishou's OneRec.

Go deeper: Recommendation Systems at Scale (Free 21-Chapter Book) · Two-Tower Models in Production · How Meta Broke the Fat Row Scaling Wall.

Frequently Asked Questions

How does Kuaishou OneRec differ from traditional two-tower + ranker recommenders?

Instead of running separate ANN retrieval, pre-ranking, and pointwise ranking models, OneRec uses a single sparse Mixture-of-Experts encoder-decoder to autoregressively generate an entire 5–10 item session directly from a billion-item catalog using semantic IDs.

Why did OneRec use Balanced K-Means instead of RQ-VAE for semantic IDs?

Standard RQ-VAE quantization often suffers from codebook collapse where a small subset of tokens absorb most catalog items. Balanced K-Means enforces equal vector counts per cluster across all three codebook layers (K=8,192 each), producing uniform hierarchical item tokens.

How does OneRec train with DPO without showing multiple sessions to the same user?

OneRec uses beam search (beam size 128) to generate candidate sessions, scores them with an offline multi-head attention Reward Model predicting watch time and engagement, and pairs the highest- and lowest-scoring candidates as chosen/rejected pairs for iterative DPO updates.

Get the Machine Learning at Scale newsletter

Join 13k+ ML engineers reading weekly deep dives on production ML systems and growing your ML career to Senior and beyond. Free on Substack.

Subscribe Free on Substack
Ludovico Bessi, Senior ML Engineer at Google

Ludovico Bessi

Senior Machine Learning Engineer at Google in Zurich. Previously worked on large-scale abuse ML systems, end-to-end YouTube Ads, YouTube Shopping recommendations, CERN, and Volvo. Writes the weekly Machine Learning at Scale newsletter.

Related Articles