Skip to content
BENIBIX Learn

Hierarchical Navigable Small World (HNSW)

AI🔎 Retrieval & SearchVector Databases

Also known as HNSW, HNSW Index

A fast vector index made of layers of linked points.

Think of it like

Think of it like a trip. First a plane, then a train, then a walk to the door.

Example

Lucy's vector database uses HNSW. A search across 2 million vectors makes a few hundred hops and returns in under 10 milliseconds.

Why it matters

Many vector databases use it by default. So its settings often decide how fast it is, how much memory it needs and how well it finds.

Definition

Hierarchical navigable small world, or HNSW, is the most used kind of vector index. It links each vector to a few close neighbors, in layers. The top layer has a few vectors with long links, and each lower layer has more. A search starts at the top, hops toward the query, then drops down a layer at a time. It is fast and accurate, but the whole graph has to fit in memory.
The search makes big jumps on the top layer. Lower down, the jumps get smaller, until it lands on the closest point.

Common mistake

Ignoring its memory use. The graph has to fit in RAM, and it can be larger than the vectors themselves.

Key takeaways

  1. 1
    Layers of links. Few at the top, all at the bottom.
  2. 2
    Hop, then drop. Top layer down.
  3. 3
    Lives in memory. Plan for the RAM.