EF Search (short for Entry Factor during Search) is a runtime parameter that defines the size of the dynamic candidate list maintained during the graph traversal phase of an HNSW query. A larger EF Search value expands the search frontier, evaluating more potential neighbor nodes, which increases the probability of finding the true nearest neighbors (recall) but also increases query latency and CPU cost. This parameter is distinct from the construction-time efConstruction parameter.
Glossary
EF Search (HNSW)

What is EF Search (HNSW)?
EF Search is a critical hyperparameter in the Hierarchical Navigable Small World (HNSW) algorithm that directly controls the trade-off between search accuracy and query speed.
Tuning EF Search is a primary method for managing the accuracy-latency trade-off in production. For high-recall scenarios like recommendation systems, a higher value (e.g., 200-500) is used. For low-latency applications like real-time retrieval, a lower value (e.g., 10-100) is sufficient. It operates in conjunction with the M parameter, which controls the graph's connectivity, and is central to the beam search heuristic that powers HNSW's efficiency.
Key Characteristics of EF Search
EF Search is the primary runtime parameter controlling the trade-off between search accuracy (recall) and query latency in the Hierarchical Navigable Small World (HNSW) algorithm.
Dynamic Candidate List Size
EF Search defines the size of the dynamic list (ef) maintained during graph traversal. At each layer of the HNSW graph, the algorithm keeps a priority queue (the 'dynamic candidate list') of the ef most promising neighbor nodes to explore next. A larger ef value allows the search to consider more candidates, increasing the probability of finding the true nearest neighbors but at the cost of more distance computations and longer latency.
- Core Mechanism: Governs the beam width of the search.
- Default Values: Often set between 10 and 200, depending on the required recall-latency profile.
Recall vs. Latency Trade-off
This parameter directly mediates the fundamental performance trade-off in approximate nearest neighbor (ANN) search.
- High EF Search (e.g., 200-500): Maximizes recall by exploring a wider neighborhood. This is critical for applications requiring high accuracy, such as legal document retrieval or diagnostic image matching, where missing a relevant result is costly.
- Low EF Search (e.g., 10-50): Minimizes query latency and CPU usage by performing a more greedy, narrow search. Ideal for real-time applications like recommendation systems or chat response retrieval, where sub-50ms latency is required.
Tuning involves running benchmarks to find the optimal point on the recall-latency curve for a specific dataset and performance SLA.
Runtime vs. Build-Time Parameter
A critical distinction is that EF Search is a query-time parameter, unlike the M parameter which is an index construction parameter. This means:
- Dynamic Adjustment:
efcan be changed on a per-query basis without rebuilding the index. An application can use a loweffor fast, exploratory searches and a higheffor final, precise retrieval. - Independent of Index: The HNSW graph structure, determined by
MandefConstructionduring build, remains fixed.efonly controls how thoroughly that pre-built graph is traversed. - System Flexibility: Allows for implementing multi-stage search pipelines, where a first-pass low-
efsearch retrieves candidates for a second-pass, high-efre-ranking.
Interaction with Graph Quality (M)
The effectiveness of ef is intrinsically linked to the quality of the underlying HNSW graph, which is built using the M parameter.
- Well-Connected Graph (Higher M): With more edges per node, even a low
efvalue can navigate the graph efficiently, as each step offers many high-quality paths. The recall gains from increasingefmay saturate quickly. - Sparse Graph (Lower M): The graph has fewer connections. A low
efsearch is more likely to follow a sub-optimal path into a local minimum. A higherefis necessary to maintain recall by exploring alternative routes.
Therefore, ef and M must be co-optimized: a higher M often allows the use of a lower ef to achieve the same recall, saving query-time compute.
Implementation in Libraries (Faiss, Weaviate)
EF Search is a standardized parameter across major vector database and ANN library implementations.
- Faiss: The
IndexHNSWsearch method accepts anefSearchargument. For example,index.search(query, k, params=faiss.SearchParametersHNSW(efSearch=128)). - Weaviate: Configured at query time via the GraphQL
nearVectorornearTextfilter:nearVector({vector: [...], distance: 0.8, ef: 200}). - Milvus/Pinecone: Similar runtime parameters are exposed through their respective SDKs and APIs for HNSW-based indexes.
The consistency of this parameter allows for portable tuning knowledge and performance expectations across different infrastructure platforms.
Tuning Methodology & Best Practices
Effective tuning of EF Search follows a data-driven, benchmark-oriented process:
- Establish a Baseline: Fix the HNSW index (
M,efConstruction) and measure Recall@K and P95/P99 Latency across a range ofefvalues (e.g., 16, 32, 64, 128, 256) using a held-out query set. - Plot the Trade-off Curve: Create a recall-latency plot. The 'knee' of the curve often represents a good operational point.
- Define SLAs: Determine the minimum acceptable recall (e.g., 0.95) and maximum allowable latency (e.g., 20ms) for your application.
- Select
ef: Choose the smallestefvalue that meets your recall SLA without breaching latency limits. - Validate in Production: Monitor real-world performance, as query distribution changes can affect optimal settings.
Best Practice: Implement adaptive EF Search, where the parameter is adjusted dynamically based on query load or result confidence scores.
EF Search: Performance Trade-Offs
Comparison of EF Search parameter settings and their impact on query performance, recall, and system resource utilization.
| Performance Dimension | Low EF Search (e.g., 10-32) | Medium EF Search (e.g., 64-128) | High EF Search (e.g., 256-512) |
|---|---|---|---|
Primary Trade-Off | Optimized for low query latency | Balanced latency and recall | Optimized for high recall (accuracy) |
Typical Query Latency | < 1 ms | 1-5 ms | 10-50 ms |
Recall@10 (Approximate) | 0.85 - 0.95 | 0.95 - 0.99 | 0.99 - 1.0 |
Dynamic Candidate List Size | Small | Medium | Large |
Graph Traversal Breadth | Narrow | Moderate | Wide |
CPU Utilization per Query | Low | Medium | High |
Memory Bandwidth Pressure | Low | Medium | High |
Use Case Fit | Real-time applications with strict latency SLOs | General-purpose semantic search | High-accuracy retrieval for evaluation or critical systems |
Practical Tuning Guidelines
EF Search is the primary hyperparameter for controlling the accuracy-latency trade-off during query execution in an HNSW index. These guidelines detail how to tune it for specific performance profiles.
Core Definition & Function
EF Search (short for 'search dynamic candidate list size') is the hyperparameter that defines the size of the dynamic priority queue maintained during the greedy graph traversal in the Hierarchical Navigable Small World (HNSW) algorithm. It directly controls the breadth of the search:
- A larger
ef_searchvalue expands the candidate list, allowing the algorithm to explore more neighbors at each layer. This increases the probability of finding the true nearest neighbors (higher recall) but requires more distance computations, increasing query latency. - A smaller
ef_searchvalue restricts exploration, making the search faster but more likely to miss optimal vectors, reducing recall. It is purely a query-time parameter and does not affect index build time or memory footprint.
Tuning for High Recall (Accuracy-First)
Use this profile for applications where result quality is paramount, such as final-stage retrieval in a Retrieval-Augmented Generation (RAG) pipeline or deduplication tasks.
- Set
ef_searchsignificantly higher thank. A common rule of thumb isef_search = 10 * kor more. For example, if returningk=10results, start withef_search=100. - Validate with Recall@K. Measure recall against ground truth results from an exhaustive (flat) search. Incrementally increase
ef_searchuntil recall plateaus at an acceptable level (e.g., 0.95-0.99). - Monitor Latency Impact. Be aware that latency increases approximately linearly with
ef_search. This trade-off is necessary for high-recall scenarios.
Tuning for Low Latency (Performance-First)
Use this profile for real-time applications like user-facing search or recommendation systems where speed is critical, and approximate results are acceptable.
- Set
ef_searchclose to, but slightly above,k. Start withef_search = k + 10tok + 50. Fork=10, tryef_search=20. - Accept Lower Recall. Understand that recall will drop. Use Recall@K to quantify the accuracy loss and ensure it remains within service-level agreement (SLA) bounds.
- Leverage Multi-Stage Search. In a high-throughput system, consider a two-stage pipeline: a very fast, low-
ef_searchHNSW search to generate a candidate set, followed by a more precise re-ranking step on a smaller subset.
Interaction with M (Construction Parameter)
EF Search and the construction parameter M (maximum connections per node) are deeply interrelated. Tuning one often requires reconsidering the other:
- A graph built with a higher M is denser and has more local shortcuts. This can allow you to use a lower
ef_searchto achieve the same recall, as each node offers more high-quality neighbor options to explore. - A graph built with a lower M is sparser. To achieve high recall, you will likely need a higher
ef_searchto compensate for the fewer connections and avoid search stagnation. - Tuning Order: First, choose
Mbased on desired index build time and memory constraints. Then, tuneef_searchto achieve your target query performance profile.
Monitoring & Dynamic Adjustment
EF Search can be adjusted dynamically without rebuilding the index, making it ideal for A/B testing and adaptive performance management.
- Benchmark with Real Query Logs. Use a sample of production query vectors to measure the recall-latency curve for your specific dataset and index.
- Set Service-Level Objectives (SLOs). Define target P99 Latency and minimum Recall@K for your service. Tune
ef_searchto the highest value that still meets your latency SLO. - Implement Canary Deployments. When changing
ef_searchin production, roll out the change gradually while monitoring key metrics: query latency, recall (if measurable), and downstream application performance (e.g., RAG answer quality).
Common Anti-Patterns & Pitfalls
Avoid these common mistakes when configuring EF Search:
- Setting
ef_searchlower thank. This is invalid and will cause search errors or severely degraded results. - Using Extremely High Values Unnecessarily. Setting
ef_searchto 1000+ for a small dataset (k=10) wastes compute and memory bandwidth with diminishing returns on recall. - Ignoring the Data Distribution. The optimal
ef_searchdepends on the 'hardness' of your vector space. Clustered, well-separated data may need a loweref_searchthan a uniform, dense distribution. - Forgetting to Re-tune After Index Updates. If you significantly expand your dataset and rebuild the HNSW index, the previous optimal
ef_searchmay no longer apply. Re-run your benchmarking process.
Frequently Asked Questions
EF Search is a critical hyperparameter in the Hierarchical Navigable Small World (HNSW) algorithm that directly governs the trade-off between search accuracy and query speed. These FAQs address its function, tuning, and impact on production vector search systems.
EF Search (short for ef or efSearch) is the hyperparameter in the HNSW algorithm that controls the size of the dynamic candidate list maintained during graph traversal. During a k-NN search, the algorithm uses a priority queue (often called the "dynamic list" or "candidate set") to explore the graph. The ef value sets the maximum capacity of this queue. A larger ef allows the search to consider more potential neighbor nodes at each layer, leading to a more exhaustive exploration of the graph and a higher probability of finding the true nearest neighbors, but at the cost of increased query latency and CPU usage. The search begins at the top layer of the HNSW graph with an entry point, greedily moving to the nearest neighbor. At each step, it explores the neighbors of the current best node, adding the most promising candidates to the priority queue, which is capped at ef elements. The process repeats until the queue is fully explored, and the top k results are extracted.
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
EF Search is a critical hyperparameter within the HNSW algorithm. To fully understand its role and impact, it's essential to grasp the related concepts that define its operational context.
Hierarchical Navigable Small World (HNSW)
HNSW is the underlying graph-based algorithm where EF Search operates. It constructs a multi-layered graph where higher layers contain fewer nodes with long-range connections, enabling fast, logarithmic-time traversal. Search begins at the top layer, moving to lower layers to refine results. Key hyperparameters include:
- M: Maximum connections per node, controlling graph density.
- efConstruction: Size of the dynamic candidate list during index building.
- efSearch: Size of the dynamic candidate list during query execution.
Beam Search
Beam Search is the heuristic graph traversal algorithm used by HNSW during queries. It maintains a dynamic list (the 'beam') of the most promising candidate nodes to visit next. The efSearch parameter directly controls the width of this beam. A larger beam (higher efSearch) explores more neighbors at each layer, increasing the probability of finding the true nearest neighbors but also increasing computational cost and query latency.
Recall & Precision
These are the primary accuracy metrics traded off against speed by tuning efSearch.
- Recall: The fraction of true nearest neighbors (from an exhaustive search) successfully retrieved. Increasing
efSearchtypically increases recall. - Precision: The fraction of retrieved items that are true nearest neighbors. In ANN search, high recall often correlates with high precision.
Engineers tune
efSearchto achieve a target Recall@K (e.g., 0.95) for their application's needs.
Query Latency
Query Latency is the elapsed time from query submission to result return, the primary cost of increasing efSearch. A larger efSearch value forces the beam search algorithm to evaluate more candidate nodes and calculate more distances, directly increasing latency. Performance is often measured by:
- Throughput (QPS): Queries per second, which falls as latency rises.
- P99 Latency: The worst-case latency for 99% of queries, critical for service-level agreements (SLAs).
Candidate Generation
Candidate Generation is the first stage in a multi-stage retrieval pipeline. In a pure HNSW search, the algorithm itself performs candidate generation and ranking. However, in complex systems, HNSW with a lower efSearch can act as a fast candidate generator, producing a broad set of results. These candidates are then passed to a more expensive re-ranking model for precise scoring, allowing a lower efSearch for initial high-throughput retrieval.
Dynamic Pruning
Dynamic Pruning is an optimization technique related to how beam search manages the candidate list. As the search progresses, nodes whose distance is worse than the current worst result in the priority queue can be pruned (ignored). The efSearch parameter indirectly controls the aggressiveness of pruning. A small efSearch leads to aggressive pruning, which speeds up search but risks eliminating a true nearest neighbor early in the traversal, reducing recall.

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