Inferensys

Glossary

Search Beam Width

Search Beam Width is a hyperparameter in graph-based approximate nearest neighbor (ANN) search algorithms that controls the size of the priority queue maintained during traversal, directly balancing search exploration, accuracy, and computational cost.
Stylish WeWork-like workspace with hot desks and document wall, professional searching through enterprise knowledge base on a mounted ultrawide display, warm industrial pendants overhead.
VECTOR INDEXING ALGORITHMS

What is Search Beam Width?

A core hyperparameter in graph-based approximate nearest neighbor (ANN) search that controls the trade-off between search speed, accuracy, and computational cost.

Search Beam Width is a hyperparameter that defines the maximum size of the priority queue (often called the candidate pool or beam) maintained during the greedy traversal of a graph-based index like HNSW. It directly controls how many neighboring nodes are explored at each step of the search, balancing exploration for higher recall against the computational cost of evaluating more candidates. A wider beam explores more of the graph's local connectivity, increasing the likelihood of finding the true nearest neighbors but requiring more distance calculations and memory.

In practice, tuning the beam width is critical for optimizing latency and throughput in production vector databases. A narrow beam accelerates search but risks lower accuracy by prematurely pruning promising paths, while an excessively wide beam diminishes the performance benefits of the approximate algorithm. It is intrinsically linked to other graph parameters like entry point selection and the efConstruction parameter used during index build time to establish robust connectivity.

VECTOR INDEXING ALGORITHMS

Key Characteristics of Beam Width

Beam width is a critical hyperparameter in graph-based search algorithms like HNSW. It controls the size of the priority queue maintained during traversal, directly influencing the trade-off between search accuracy, exploration, and computational cost.

01

Definition & Core Function

Search Beam Width defines the maximum number of candidate nodes (the 'beam') held in a priority queue during each step of a greedy graph traversal. The algorithm explores the neighbors of all nodes in the current beam, scores them, and keeps only the top beam width candidates for the next iteration. This mechanism prevents the search from degenerating into a simple, easily trapped greedy walk by maintaining a pool of promising paths.

  • Primary Role: Balances exploration (searching more paths) against exploitation (focusing on the current best path).
  • Analogy: Similar to how a chess engine evaluates multiple potential move sequences (the beam) before committing to a path.
02

Trade-off: Recall vs. Latency

Beam width creates a direct, tunable trade-off between search accuracy (recall) and query latency.

  • Larger Beam Width: The algorithm explores more candidate nodes per layer. This increases the probability of finding the true nearest neighbors, thereby improving recall. However, it also increases the number of distance computations and priority queue operations, increasing latency and CPU cost.
  • Smaller Beam Width: The search becomes more greedy and faster, reducing latency. However, with a narrower exploration scope, it is more likely to follow a sub-optimal path and miss the true nearest neighbors, potentially reducing recall.

Tuning this parameter is essential for matching application requirements, whether prioritizing millisecond responses or maximum accuracy.

03

Interaction with Graph Structure (HNSW)

In Hierarchical Navigable Small World (HNSW) graphs, beam width interacts with the graph's multi-layered structure. The search begins at the topmost, sparsest layer with a long 'zoom-out' view and proceeds downwards to denser layers.

  • Upper Layers: A smaller beam width is often sufficient because the long-range connections help navigate quickly to the correct region of the vector space.
  • Lower Layers: As the search nears the bottom (densest) layer where the final nearest neighbors reside, a larger beam width becomes more critical. It allows the algorithm to refine its search within a dense local neighborhood, ensuring high-precision results.

Some implementations use a dynamic or layer-dependent beam width to optimize this process.

04

Implementation & Priority Queue

Operationally, beam width is implemented using a min-heap or max-heap priority queue (often a 'candidate set' and a 'visited set').

Process per search layer:

  1. Pop the best node from the candidate min-heap (closest to the query).
  2. Explore its connections, computing distances to the query.
  3. Add promising new candidates to the heap.
  4. If the heap size exceeds the configured beam width, prune it by removing the worst (farthest) candidate.

This heap management is the core computational overhead. The cost scales with beam width * average node degree. Efficient heap implementations are crucial for performance.

05

Tuning Guidelines & Typical Values

Optimal beam width is dataset and index-dependent, but general guidelines exist:

  • Start Point: A common default is between 32 and 128. For HNSW, values like 64 or 100 are frequently used as baselines.
  • Tuning Method: Perform a sweep (e.g., 16, 32, 64, 128, 256) while measuring Recall@10 and Queries Per Second (QPS). Plot the trade-off curve to select a value that meets your accuracy/latency Service Level Objective (SLO).
  • High-Dimensional Data: Often requires a larger beam width for equivalent recall due to the 'curse of dimensionality' and less reliable distance metrics.
  • Production Consideration: A larger beam width also increases memory bandwidth pressure during search, as more vector data is fetched. This can become a bottleneck on large-scale systems.
06

Related Concept: Exact Re-ranking

Beam width is closely related to the strategy of Exact Re-ranking. In a common two-stage search pipeline:

  1. Approximate Search: A graph-based index (e.g., HNSW) with a moderate beam width retrieves a broad candidate set (e.g., top 200 vectors). This stage is fast but approximate.
  2. Exact Re-ranking: The candidate set is then re-scored using exact, full-precision distance calculations (e.g., full float32 Euclidean distance) to produce the final, accurate top-k results.

Here, the beam width in the first stage determines the size and quality of the candidate pool for re-ranking. A wider beam provides a better candidate pool for the second stage to work with, often yielding higher final accuracy than simply using a massive beam width in the first stage alone.

GRAPH-BASED SEARCH HYPERPARAMETER

Beam Width Tuning: Trade-offs and Impact

This table compares the performance characteristics, resource consumption, and application suitability for different settings of the beam width parameter in graph-based approximate nearest neighbor search algorithms like HNSW.

Metric / CharacteristicNarrow Beam (e.g., 10-32)Moderate Beam (e.g., 64-128)Wide Beam (e.g., 256-512)

Primary Search Behavior

Greedy, highly exploitative

Balanced exploration/exploitation

Exhaustive, highly exploratory

Typical Query Latency

< 1 ms

1-5 ms

10 ms

Memory Overhead (Priority Queue)

Low

Moderate

High

Recall@10 (Typical)

85-92%

95-98%

99%+

Index Build Time Impact

Minimal

Slight increase

Significant increase

Dynamic Insertion Speed

Fastest

Moderate

Slowest

Ideal Use Case

Ultra-low latency applications, high-throughput filtering

General-purpose semantic search, RAG systems

High-recall applications, offline batch jobs, evaluation

CPU Utilization per Query

Lowest

Medium

Highest

SEARCH BEAM WIDTH

Implementation in Libraries & Databases

The Search Beam Width parameter is a critical tuning knob within graph-based search algorithms. Its implementation varies across popular libraries and databases, directly influencing the trade-off between search accuracy (recall), latency, and computational resource consumption.

02

HNSWlib

The standalone HNSWlib implements beam width identically to the core HNSW paper via the ef parameter.

  • Direct Control: The ef parameter passed during search (knnQuery) explicitly sets the size of the dynamic candidate list.
  • Resource Management: Larger ef values consume more temporary memory per query and increase latency linearly.
  • Precision Tuning: It is the primary parameter for trading between search speed (low ef) and high recall (high ef), independent of the M parameter which controls graph connectivity.
03

Weaviate & Qdrant (HNSW)

Vector databases like Weaviate and Qdrant expose HNSW beam width as a configurable index setting, often named ef or ef_search.

  • Per-Collection Configuration: Set at the collection/schema level during index configuration.
  • Query-Time Overrides: Some databases allow temporary ef overrides via query parameters for dynamic tuning.
  • Impact on SLA: This parameter is crucial for database operators to meet specific latency and recall Service Level Agreements (SLAs) in production.
04

Pinecone & Managed Services

Managed vector database services like Pinecone abstract low-level parameters but still allow control over the accuracy-speed trade-off.

  • Abstraction Layer: Beam width may be managed internally or exposed via high-level concepts like "search precision" or "pod type."
  • Automatic Optimization: Some services may dynamically adjust internal beam width based on query load and performance targets.
  • User Control: Configuration is typically through API parameters or console settings that map to underlying ef values.
05

DiskANN

DiskANN uses beam search in its Vamana graph algorithm, controlled by the search_list_size (often labeled L).

  • Persistent Caching: Designed for large datasets on disk, a larger search_list_size (beam width) increases I/O by fetching more candidate nodes from SSD but improves recall.
  • Two-Phase Search: The algorithm often uses an expanded beam during the search phase compared to the prune phase during construction.
  • Memory-Disk Trade-off: Tuning this parameter is critical for balancing SSD bandwidth usage with search accuracy.
06

SCANN (Tree-AH)

Google's SCANN uses a different paradigm but employs an analogous concept in its Tree-AH (Tree Asymmetric Hashing) index.

  • Leaves Searched: The leaves_to_search parameter acts as the beam width equivalent, controlling how many partitions (tree leaves) are probed.
  • Anisotropic Quantization: The candidate set within a leaf is generated using anisotropic quantization, not graph traversal.
  • Throughput Optimization: Increasing leaves_to_search improves recall but directly impacts throughput, as each leaf search is independent and can be parallelized.
SEARCH BEAM WIDTH

Frequently Asked Questions

Search Beam Width is a critical hyperparameter in graph-based vector search algorithms. These FAQs address its definition, function, and practical impact on search performance and system cost.

Search Beam Width is a hyperparameter in graph-based approximate nearest neighbor (ANN) search algorithms that controls the size of the priority queue (or candidate pool) maintained during graph traversal. It determines how many potential neighbor nodes are explored at each step of the search, directly balancing exploration, accuracy, and computational cost.

Think of it as the "search breadth." A wider beam explores more paths simultaneously, increasing the chance of finding the true nearest neighbors (higher recall) but requiring more distance calculations and memory. A narrower beam is faster and more memory-efficient but risks getting trapped in a local optimum, potentially missing better results.

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.