Skip to content

Understanding HNSW Parameters

Marqo uses the Hierarchical Navigable Small Worlds algorithm under the hood. This algorithms behaviour is goverened by three key parameters which influence, latency, memory usage, and recall. For almost all use cases our defaults will offer great performance - a significant amount of testing has been done to determine these values. However, for advanced users or those with specific requirements, these parameters can be tuned.

Parameters

The efConstruction and m parameters are configurable in parameters field of the annParameters object when creating an index. Please see the documentation for this object here.

The efSearch parameter is configured at query time. Please see the documentation for this parameter here.

efConstruction

This parameter controls the size of the dynamic list of nearest neighbors used during the construction of the index. A larger value will result in a more accurate index, but will also consume more memory during indexing and take longer to construct. The default value is 512.

m

This parameter controls the maximum number of neighbors to keep for each node in the graph. A larger value will result in a more accurate index, but will also consume more memory and take longer to construct. The default value is 16. The bottom layer of the graph will have 2 * m neighbours.

efSearch

This parameter controls the size of the dynamic list of nearest neighbors used during the search process. A larger value will result in a more accurate search, but will also consume more memory during the search and take longer to complete. The default value is 2000. This parameter is set at query time and can be adjusted for each query. For example:

curl -XPOST 'http://localhost:8882/indexes/my-first-index/search' -H 'Content-type:application/json' -d '
{
    "q": "what is the best outfit to wear on the moon?",
    "efSearch": 1000
}'
mq.index("my-first-index").search(
    q="What is the best outfit to wear on the moon?",
    ef_search=1000
)