ef
- the size of the dynamic list for the nearest neighbors (used during the search). Higheref
leads to more accurate but slower search.ef
cannot be set lower than the number of queried nearest neighborsk
. The valueef
of can be anything betweenk
and the size of the dataset.k
number of nearest neighbors to be returned as the result. Theknn_query
function returns two numpy arrays, containing labels and distances to the k found nearest elements for the queries. Note that in case the algorithm is not be able to findk
neighbors to all of the queries, (this can be due to problems with graph ork
>size of the dataset) an exception is thrown.
An example of tuning the parameters can be found in TESTING_RECALL.md
-
M
- the number of bi-directional links created for every new element during construction. Reasonable range forM
is 2-100. HigherM
work better on datasets with high intrinsic dimensionality and/or high recall, while lowM
work better for datasets with low intrinsic dimensionality and/or low recalls. The parameter also determines the algorithm's memory consumption, which is roughlyM * 8-10
bytes per stored element.
As an example fordim
=4 random vectors optimalM
for search is somewhere around 6, while for high dimensional datasets (word embeddings, good face descriptors), higherM
are required (e.g.M
=48-64) for optimal performance at high recall. The rangeM
=12-48 is ok for the most of the use cases. WhenM
is changed one has to update the other parameters. Nonetheless, ef and ef_construction parameters can be roughly estimated by assuming thatM
*ef_{construction}
is a constant. -
ef_construction
- the parameter has the same meaning asef
, but controls the index_time/index_accuracy. Bigger ef_construction leads to longer construction, but better index quality. At some point, increasing ef_construction does not improve the quality of the index. One way to check if the selection of ef_construction was ok is to measure a recall for M nearest neighbor search whenef
=ef_construction
: if the recall is lower than 0.9, than there is room for improvement. -
num_elements
- defines the maximum number of elements in the index. The index can be extended by saving/loading (load_index function has a parameter which defines the new maximum number of elements).