What is the base layer (level zero) in HNSW?
The base layer, also called level zero, is the bottommost and largest layer of an HNSW hierarchy, containing every single vector in the entire dataset, with no exceptions — where every layer above it holds only a randomly selected subset of the data, the base layer is the one place in the whole structure where the full dataset actually lives and where the search’s final answer is always produced. Understanding what makes the base layer different from every layer above it clarifies why HNSW‘s tuning parameters so often treat it as a special case deserving its own separate settings.
Why does every vector, without exception, belong to the base layer?
Recall how layer assignment works: each vector gets assigned a maximum layer through a random process, and it’s then placed in every layer from zero up to that maximum. Because zero is the minimum possible value that assignment can produce, every single vector, regardless of how the random process happened to treat it, is guaranteed to be included in the base layer at minimum — a vector might get lucky and reach layer five, or it might simply stay at layer zero and never appear anywhere else, but there’s no outcome of the random assignment process that excludes a vector from the base layer entirely. This is exactly why the base layer holds the full dataset while every layer above it holds only a fraction of it, shrinking further with each additional layer up the hierarchy.
This universality is precisely why the base layer, and only the base layer, is capable of producing a search’s final answer. A query’s true nearest neighbors could, in principle, be any vector in the dataset, and since the upper layers only contain a scattered subset of vectors, they simply don’t have access to every candidate that might actually matter — only the base layer, with its complete coverage of the dataset, can guarantee that the true nearest neighbors are even present to be found in the first place.
How does the actual search behavior at the base layer differ from the search behavior in the layers above it?
The layers above the base one are searched with a comparatively lightweight strategy, generally tracking only a single current-best candidate and greedily moving toward whatever looks closest, since their only job is to hand off a good starting position to the layer below rather than to produce final results. The base layer is where this changes: rather than a simple greedy descent tracking one best point, the base-layer search uses the full dual-queue structure covered elsewhere in this documentation, maintaining a genuine ranked set of the k best candidates found so far and exploring a meaningfully wider beam of the graph before its stopping criterion is satisfied. This shift in search strategy reflects the base layer’s different job: rather than quickly narrowing down a rough direction, it needs to carefully and thoroughly identify the actual best k candidates, since whatever it returns here is the search’s final, complete answer.
This is also exactly why the efSearch parameter, which controls how wide that base-layer beam search is allowed to grow, matters so much for overall recall — it’s specifically the base layer’s search width that efSearch governs, since the upper layers’ simpler greedy descent doesn’t have an equivalent beam-width setting to tune in the same way.
Why does the base layer get its own separate degree cap, distinct from the one used in every other layer?
HNSW conventionally uses two different degree-cap parameters: M, which sets the target connection count for every layer above the base one, and a separate, typically larger cap, often called Mmax0, specifically for the base layer. This distinction exists because the base layer carries by far the heaviest search traffic of any layer in the hierarchy — every single query passes through it, and it’s where the actual, careful nearest-neighbor determination happens — which makes it worth allowing more generous connectivity there than the sparser upper layers need, even though a higher degree cap also means more memory spent on base-layer connections. The base layer’s outsized importance to overall search quality is exactly why this specific parameter gets tuned somewhat independently from the general M setting used everywhere else in the hierarchy, a distinction covered in more depth on the Mmax0 glossary page.
Having covered what makes the base layer structurally and functionally distinct from every layer above it, the Mmax0 and efSearch glossary pages are the natural next stop, since they cover the two parameters most directly tied to the base layer’s special role. From there, the upper-layer glossary page is worth reading as a direct point of contrast, laying out exactly how the layers above the base one behave differently in both structure and search strategy.