Inferensys

Glossary

Candidate Generation

Candidate generation is the initial, high-recall stage in a multi-stage retrieval pipeline, where a fast approximate search algorithm produces a broad set of potentially relevant vectors for subsequent precise scoring or re-ranking.
Engineer reviewing vector database search results on laptop, embeddings visualization on screen, home office coding session.
VECTOR QUERY OPTIMIZATION

What is Candidate Generation?

Candidate Generation is the initial, high-recall stage in a multi-stage retrieval pipeline, designed to quickly produce a broad set of potentially relevant items for subsequent precise ranking.

Candidate Generation is the first stage in a multi-stage retrieval pipeline where a fast, approximate search algorithm produces a broad set of potentially relevant vectors for subsequent, more precise scoring or re-ranking. This stage prioritizes high recall over perfect precision, using efficient Approximate Nearest Neighbor (ANN) indexes like Inverted File (IVF) or Hierarchical Navigable Small World (HNSW) to scan billions of vectors with sub-linear time complexity. Its goal is to reduce the search space from the entire database to a manageable shortlist of candidates.

The generated candidate set is then passed to a more computationally expensive re-ranker or scorer—such as a cross-encoder model or exact distance calculation—which performs the final precision-optimized ranking. This two-stage architecture is fundamental to scalable semantic search and recommendation systems, balancing the need for speed at scale with the requirement for accurate final results. Parameters like the number of candidates (nprobe in IVF, ef in HNSW) directly control the trade-off between recall and query latency.

VECTOR QUERY OPTIMIZATION

Key Characteristics of Candidate Generation

Candidate Generation is the initial, high-speed retrieval stage in a multi-stage search pipeline. Its primary objective is to efficiently produce a broad, approximate set of relevant items for subsequent, more precise re-ranking.

01

Speed Over Perfect Accuracy

The core trade-off of candidate generation is sub-linear query time for approximate results. Instead of an exhaustive (linear) scan comparing the query to every vector, it uses specialized indices like Inverted File (IVF) or Hierarchical Navigable Small World (HNSW) graphs to search only a promising subset of the data. This reduces latency from O(N) to O(log N) or better, enabling real-time search over billion-scale datasets, albeit with a controlled loss in recall.

02

Recall-Oriented Design

This stage is optimized for high recall@K, aiming to retrieve as many of the true nearest neighbors as possible within its candidate set. The philosophy is 'cast a wide net'—it's acceptable to include some irrelevant candidates, as long as most relevant items are captured. The subsequent re-ranking stage is responsible for culling false positives and perfecting the final ranking order. Parameters like nprobe in IVF or ef_search in HNSW directly control this recall/latency trade-off.

03

Integration with Multi-Stage Pipelines

Candidate generation is rarely the final step. It feeds into a multi-stage retrieval and ranking architecture:

  • Stage 1 (Candidate Gen): Fast, approximate search returns 100-10k candidates.
  • Stage 2 (Re-ranking): A more computationally expensive, precise model (e.g., a cross-encoder, refined distance calculation, or business logic) scores and re-orders the candidate subset.
  • Stage 3 (Final Ranking): May incorporate personalized features, diversity filters, or policy rules. This separation allows the system to combine the scale of approximate search with the precision of complex models.
04

Core Indexing Methods

Performance hinges on the underlying Approximate Nearest Neighbor (ANN) index. Key algorithms include:

  • Inverted File Index (IVF): Partitions data into clusters (Voronoi cells). Search is limited to the nprobe nearest clusters.
  • Hierarchical Navigable Small World (HNSW): A multi-layer graph where search begins at a top-layer entry point and navigates to the nearest neighbors, layer by layer.
  • Locality-Sensitive Hashing (LSH): Hashes similar vectors into the same 'bucket' with high probability, searching only within the query's bucket. Each method makes different trade-offs between index build time, memory footprint, query speed, and accuracy.
05

Support for Hybrid Filtering

Real-world queries often require combining semantic vector search with structured metadata filters (e.g., date > 2024 and category = 'news'). Candidate generation systems implement strategies to execute these filtered searches efficiently:

  • Pre-filtering: Apply metadata filters first, then perform vector search on the filtered subset. Risk: can eliminate all relevant vectors if the filter is too restrictive.
  • Post-filtering: Perform vector search first, then filter the resulting candidates. Risk: may return fewer than K results if filters are strict.
  • Single-Stage Filtered Search: Advanced indexes (e.g., Milvus's scalar-field indexes) evaluate filters during the graph traversal or IVF probe, providing a more integrated optimization.
06

Systemic Impact on Architecture

The choice of candidate generation strategy influences overall system design:

  • Memory vs. Disk: IVF-PQ indices can operate largely on compressed vectors in RAM, while some graph indices have larger memory footprints.
  • Update Friendliness: IVF indices can be updated relatively easily by adding vectors to existing clusters, while HNSW graph modifications are more complex, often requiring partial rebuilds.
  • Parameter Tuning: Production deployment requires tuning parameters (e.g., IVF's nprobe, HNSW's ef_construction and ef_search) against benchmark datasets to hit target latency Service-Level Objectives (SLOs) and recall thresholds. This is a key task for ML and performance engineers.
RETRIEVAL PIPELINE STAGES

Candidate Generation vs. Full Retrieval

A comparison of the initial, approximate retrieval stage (Candidate Generation) with the final, precise retrieval stage (Full Retrieval) in a multi-stage vector search pipeline.

Feature / MetricCandidate GenerationFull Retrieval

Primary Objective

Maximize recall of potential matches

Maximize precision of final ranking

Algorithm Type

Approximate Nearest Neighbor (ANN)

Exact Nearest Neighbor or Re-ranking

Typical Index Used

IVF, HNSW, LSH

Flat (Brute-force) or specialized re-ranker

Search Scope

Subset of database (e.g., nprobe cells in IVF)

Entire candidate set or full database

Query Latency Target

< 10 milliseconds

10-100 milliseconds

Recall Target

95-99% of true top-K

100% of true top-K (exact)

Memory/Compute Trade-off

High compression (e.g., PQ, SQ) acceptable

Often requires full-precision vectors

Result Set Size

Large (e.g., 1000 candidates)

Small (e.g., 10-100 final results)

Common Distance Computation

Approximate (ADC, lookup tables)

Exact (e.g., FP32 L2, cosine)

Pipeline Role

First-stage retriever

Second-stage scorer or re-ranker

CANDIDATE GENERATION

Frequently Asked Questions

Candidate Generation is the critical first stage in a multi-stage retrieval pipeline, designed for speed and recall. It uses fast, approximate algorithms to sift through millions of vectors and produce a manageable shortlist for more precise, computationally expensive downstream stages.

Candidate Generation is the initial, high-recall retrieval stage in a multi-stage search pipeline that uses fast, approximate algorithms to produce a broad set of potentially relevant items from a massive corpus. It works by leveraging specialized vector indexes like Inverted File (IVF) or Hierarchical Navigable Small World (HNSW) graphs to perform a sub-linear time search, retrieving hundreds or thousands of candidates from a pool of millions. This stage prioritizes recall—ensuring most true relevant items are in the candidate set—over perfect precision, trading exact accuracy for the speed required in real-time systems like recommendation engines or search. The output candidate set is then passed to more precise, often slower, re-ranking or scoring models for final result ordering.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.