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.
Glossary
Candidate Generation

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.
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.
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.
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.
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.
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.
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
nprobenearest 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.
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.
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'sef_constructionandef_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.
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 / Metric | Candidate Generation | Full 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 |
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.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Candidate Generation is the first, fast-retrieval stage in a multi-stage search pipeline. These related concepts define the algorithms, metrics, and optimizations that power it.
Approximate Nearest Neighbor (ANN) Search
The foundational algorithmic class for candidate generation. ANN search trades perfect accuracy for sub-linear query time, enabling fast retrieval from massive vector datasets. It is the core engine behind candidate generation, using indexes like HNSW or IVF to avoid comparing the query against every vector in the database.
- Purpose: Enable real-time similarity search at scale.
- Trade-off: Configurable balance between recall and query latency.
- Example: Finding 100 similar product images from a catalog of 100 million in <10ms.
Inverted File Index (IVF)
A prevalent index structure for candidate generation. IVF partitions the vector space into clusters (Voronoi cells) via k-means. At query time, the system finds the nearest centroids and searches only the vectors within those corresponding cells.
- Mechanism: Uses an inverted index mapping centroids to member vectors.
- Performance: Search complexity is O(n_probe * cluster_size), where
n_probeis the number of cells searched. - Use Case: Ideal for balanced speed/recall when combined with a secondary quantization step like Product Quantization (PQ).
Recall@K
The primary metric for evaluating candidate generation quality. Recall@K measures the fraction of the true top-K nearest neighbors (from an exhaustive search) that are present in the approximate top-K results returned by the candidate generator.
- Formula: (True positives in retrieved K) / K.
- Interpretation: A Recall@100 of 0.95 means 95 of the true top 100 neighbors were in the candidate set.
- Engineering Impact: Directly trades off with query latency; higher recall typically requires searching more of the index.
Filtered Search
A critical hybrid query pattern that constrains candidate generation by metadata. It combines a vector similarity search with conditional filters (e.g., status = 'in_stock' AND price < 50).
- Challenge: Applying filters naively can break the index's proximity assumptions.
- Strategies:
- Pre-filtering: Apply metadata filters first, then search the subset. Risks missing relevant vectors filtered out early.
- Post-filtering: Generate vector candidates first, then apply filters. Can reduce result count below K if filters are strict.
- Advanced Solution: Native integrated filtering where the index is aware of metadata partitions.
Query Planning
The optimizer process that determines how to execute a search request. For a candidate generation query with filters and parameters, the query planner selects the most efficient index access path and execution strategy.
- Inputs: Query vector, k, filters, distance metric, and index types available.
- Decisions: Chooses between pre-filtering, post-filtering, or using a specialized filtered index. Adjusts internal parameters like
n_probefor IVF oref_searchfor HNSW. - Goal: Minimize P99 latency while meeting the target Recall@K for the given workload.
Beam Search
The core traversal algorithm used in graph-based ANN indexes like HNSW. Beam search maintains a fixed-width priority queue (the 'beam') of the most promising candidate nodes during graph exploration.
- Function: Balances exploration (finding global neighbors) and efficiency (limiting visited nodes).
- Parameter: Beam width is often controlled by the ef_search parameter in HNSW.
- Analogy: Like searching a friendship network by only tracking your top N most promising leads at each step.
- Optimization: Enables dynamic pruning, where unpromising paths are abandoned early.

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.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us