Hierarchical navigable small world graph. The usual first choice: high
recall at low query latency. Raise ef_search for recall at query time,
ef_construction for a better graph at build time.
Nodes are inserted in parallel, so two builds with the same seed give
slightly different graphs. Need bit-identical results? Build with
ann_set_threads(1L).
References
Malkov YA, Yashunin DA (2020). Efficient and robust approximate nearest neighbor search using hierarchical navigable small world graphs. IEEE Transactions on Pattern Analysis and Machine Intelligence, 42, 824-836. doi:10.1109/TPAMI.2018.2889473
Super class
AnnIndex -> HnswIndex
Methods
Inherited methods
HnswIndex$new()
Build the index.
Arguments
dataNumeric matrix or data.frame. Samples x features. An index pointer is also accepted;
load_ann_index()uses that path.metricString. One of
c("euclidean", "sqeuclidean", "cosine", "manhattan").mInteger. Edges per node on the upper layers,
2 * mon layer 0. 16 suits most data; 32 to 48 helps in high dimensions.ef_constructionInteger. Candidate list width during the build. Better graph, slower build, no cost at query time.
ef_searchInteger. Beam width at query time. Raised to
kinternally if smaller. Can be changed after the build.seedInteger. Fixes the layer assignment.
precisionString.
"float"stores the data as f32,"double"as f64..verboseBoolean. Print build progress from Rust.
Examples
x <- generate_clustered_data(1000L, 16L)$data
idx <- HnswIndex$new(x, metric = "cosine")
idx$ef_search <- 100L
res <- idx$predict(x[1:5, ], k = 10L)
