Skip to main content

Candidate Generation

Candidate generation reduces an eligible catalog to a tractable pool. Its job is recall under a latency and capacity budget. A downstream scorer cannot rescue an item that retrieval omitted.

Prerequisites​

Review the content, neighborhood, factor, cold-start, and session-based sources. Keep the frozen candidate and relevance definitions from ticket 49.

Learning goals​

  • Union multiple retrieval sources without comparing unlike source scores.
  • Compute retrieval recall against the full eligible candidate set.
  • Record source attribution, caps, deduplication, and latency budgets.
  • Separate exact model scoring from approximate nearest-neighbor retrieval.

Model contract​

PartThis lesson's contract
ObjectivePlace every later-relevant eligible item into a small candidate pool often enough for downstream ranking.
Input representationUser/session query state, item/content indexes, popularity state, eligibility filters, and per-source caps.
Learned stateSource models and indexes plus versioned source weights/caps; source scores retain their own scales.
Inference pathApply hard eligibility, query sources in parallel, union and deduplicate IDs, attach provenance, then enforce a pool cap.
Evaluation boundaryRetrieval recall uses the full frozen eligible catalog as denominator; latency is measured separately at declared percentiles.
Principal failure modesMissed relevant items, stale indexes, filter/index disagreement, source domination, tail starvation, and latency timeouts.

Worked example: audit pool coverage​

For u2, later relevance is i4 and i7. The source lists are fixed illustrative outputs from models trained before the cutoff. Their raw scores are intentionally absent because content similarity, neighborhood support, and popularity counts are not calibrated to one scale.

sources = {
"content": ["i7", "i1"],
"neighborhood": ["i4", "i6"],
"popular": ["i4", "i5", "i1"],
}
relevant = {"i4", "i7"}
union = sorted({item for items in sources.values() for item in items})
recall = len(set(union) & relevant) / len(relevant)
source_counts = {name: len(items) for name, items in sources.items()}
print(f"u2_union={union} source_counts={source_counts}")
print(f"retrieval_recall@{len(union)}={recall:.3f} relevant={sorted(relevant)}")

Output:

u2_union=['i1', 'i4', 'i5', 'i6', 'i7'] source_counts={'content': 2, 'neighborhood': 2, 'popular': 3}
retrieval_recall@5=1.000 relevant=['i4', 'i7']

Retrieval recall@5 is one on this one-user case; that is a contract test, not a performance estimate. Report it over eligible test decisions, by warm/cold cohort and source-ablation. Approximate indexes add another measurement: compare their returned top-k with exact retrieval on a representative query sample before accepting their speed/recall trade-off.

Retrieval quality is not ranking quality​

Retrieval recall asks whether a relevant item reached the pool. Ranking quality asks where the scorer placed relevant items within that pool. Preserve both. Also record candidate-pool size, index freshness, timeout rate, source coverage, and end-to-end latency budget. “Fast” requires measured hardware, traffic, percentile, and load; this example contains no benchmark.

Limitations and common mistakes​

  • Merging source scores directly assumes calibration that usually does not exist.
  • Evaluating only retrieved items makes a weak retriever invisible.
  • Filtering after retrieval can empty a pool; eligibility and index freshness need joint monitoring.
  • Larger pools may improve recall while violating the scoring latency budget.
  • No universal model ranking or architecture follows from tiny-fixture retrieval recall.

Practice​

Remove the content source and recompute recall. Then design a per-source cap that preserves i7 without assuming access to future relevance.

Next steps​

Scoring and multi-stage ranking maps the union to a common score, preserves retrieval evidence, and applies final constraints.

Primary sources​

Checked 2026-10-17: Google, candidate generation and retrieval; TensorFlow Recommenders, top-k retrieval interface.