new HNSW(metricopt, heuristicopt, mopt, efopt, m0opt, mLopt, seedopt)
Hierarchical navigable small world graph. Efficient and robust approximate nearest neighbor search.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
metric | function | <optional> | euclidean | metric to use: (a, b) => distance. |
heuristic | Boolean | <optional> | true | use heuristics or naive selection. |
m | Number | <optional> | 5 | max number of connections. |
ef | Number | <optional> | 200 | size of candidate list. |
m0 | Number | <optional> | 2 * m | max number of connections for ground layer. |
mL | Number | <optional> | 1 / Math.log2(m) | normalization factor for level generation. |
seed | Number | <optional> | 1987 | seed for random number generator. |
- Source
Methods
add(elements) → {HNSW}
Parameters:
Name | Type | Description |
---|---|---|
elements | Array.<*> | new elements. |
- Source
Returns:
- Type:
- HNSW
search(q, K, ef) → {Array}
Parameters:
Name | Type | Default | Description |
---|---|---|---|
q | * | query element. | |
K | * | number of nearest neighbors to return. | |
ef | * | 1 | size of the dynamic cnadidate list. |
- Source
Returns:
K nearest elements to q.
- Type:
- Array
(generator) search_iter(q, K, ef) → {Array}
Iterator for searching the HNSW graphs
Parameters:
Name | Type | Default | Description |
---|---|---|---|
q | * | query element. | |
K | * | number of nearest neighbors to return. | |
ef | * | 1 | size of the dynamic cnadidate list. |
- Source
Yields:
K nearest elements to q.
- Type:
- Array