Graph-structured index for approximate vector search in RediSearch and pgvector. Compared with IVFFlat, recall versus speed is better, though building takes longer and memory use is higher.
Also called Hierarchical Navigable Small World.
Read more: Microsoft Learn
In the Ultra Transcenders books
Each book explains HNSW in context, with comparison tables and the common traps.
Terms in this definition
- Index
Speeds up queries that filter on certain columns by keeping those columns sorted, with pointers back to each row; the price is more storage and slower writes.
- Vector search
Searching embeddings for similar meaning, so paraphrases are found via nearest-neighbour algorithms like HNSW; exact identifiers, however, may be missed.
- RediSearch
A Redis module for Azure Managed Redis that provides secondary indexes plus full-text and vector search. It can only be turned on when the cache is created and needs Enterprise clustering with the NoEviction policy.
- IVFFlat
An approximate nearest-neighbour index in pgvector that groups vectors into lists. Compared with HNSW it builds faster and takes less space but balances speed and recall less well, and data must be loaded before it is created.
- Recall
A measure of approximate (ANN) vector search accuracy: what fraction of the true nearest neighbours, as found by an exact kNN search, the approximate search returned. A value of 1 means nothing was approximated.
Related terms
- ANN
Short for approximate nearest neighbour: a vector search that finds most of the closest matches rather than guaranteeing every one, trading completeness for speed and lower cost. DiskANN and HNSW indexes work this way, whereas flat search is exact.
- FLAT
A RediSearch vector index that compares every vector exactly, by brute force. It fits smaller data sets or cases needing complete results, whereas HNSW is approximate.