KatInterview

Dynamic Retrieval Depth Selection in a Recommender Pipeline

Machine LearningModel answer
HardModel answerMachine Learningrecommender systemsretrieval-rankingcompute optimization

Last updated

Design a system that decides, per request, how many candidates to pass from the recall stage to the heavy ranker in a recommender system.

Background

A large-scale recommender system is typically split into two stages:

  1. Recall / retrieval: a fast, lightweight stage that pulls K candidate items from a corpus of millions using approximate nearest-neighbor search, item-to-item signals, trending queues, and similar channels. A cheap pre-ranker scores and merges these into a single ordered list.
  2. Heavy ranking: a deep neural network that rescores only those K candidates. This is the most expensive step in the pipeline — it dominates GPU serving cost and is the main latency bottleneck.

Today, K is a fixed constant (say, 1,000) applied to every request. That is wasteful: a casual user browsing trending content probably needs far fewer candidates to produce a great feed, while a cold-start user with a noisy interest profile might benefit from a larger pool.

The Problem

Design a system — including a model, training procedure, inference integration, and feedback mechanism — that selects K dynamically, per request, rather than using a static value.

Your answer should address:

  1. Framing: what is the right objective, and why is "proportion of retrieved candidates that survive ranking" not a good standalone metric?
  2. What the model predicts: justify the choice of output representation. Why is directly regressing an "optimal K" label harder than it sounds?
  3. Features: what signals are available after the recall stage and before the heavy ranker fires, and which are most predictive?
  4. Training data: how do you generate labels without running a separate A/B test for every possible value of K?
  5. Decision rule: how do you turn a model output into a concrete integer K under a fleet-wide compute budget, and how does the system adapt to real-time load spikes?
  6. Safety and fairness guardrails: what can go wrong when you start truncating the candidate list, and how do you mitigate it?

A strong answer connects the model design choices back to latency, cost, and engagement trade-offs, and names at least one concrete failure mode.

Hints

Hint 1

Think about what you are actually optimizing across the whole fleet of requests — it is a resource allocation problem, not a per-request classification problem. What does the objective look like when you write it out mathematically?

Hint 2

Instead of predicting a single number K, consider predicting a quality-versus-K curve for each request. That representation is easier to label and lets you separate the model from the budget decision.

Hint 3

The global compute budget introduces a shadow price on ranking compute. Look up Lagrangian relaxation for knapsack-style problems — it reduces the fleet-wide allocation to a simple per-request rule with one shared scalar parameter.