HnswGraph

abstract class HnswGraph

Hierarchical Navigable Small World graph. Provides efficient approximate nearest neighbor search for high dimensional vectors. See Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs 2018 paper for details.

The nomenclature is a bit different here from what's used in the paper:

Hyperparameters

  • beamWidth in HnswGraphBuilder has the same meaning as efConst * in the paper. It is the number of nearest neighbor candidates to track while searching the graph for each newly inserted node.

  • maxConn has the same meaning as M in the paper; it controls how many of the efConst neighbors are connected to the new node

Note: The graph may be searched by multiple threads concurrently, but updates are not thread-safe. The search method optionally takes a set of "accepted nodes", which can be used to exclude deleted documents.

Inheritors

Types

Link copied to clipboard

NodesIterator that accepts nodes as an integer array.

Link copied to clipboard

Nodes iterator based on set representation of nodes.

Link copied to clipboard
object Companion
Link copied to clipboard
abstract class NodesIterator(size: Int) : PrimitiveIterator.OfInt

Iterator over the graph nodes on a certain level. Iterator also provides the size – the total number of nodes to be iterated over. The nodes are NOT guaranteed to be presented in any particular order.

Functions

Link copied to clipboard
abstract fun entryNode(): Int

Returns graph's entry point on the top level *

Link copied to clipboard

Get all nodes on a given level as node 0th ordinals. The nodes are NOT guaranteed to be presented in any particular order.

Link copied to clipboard
abstract fun maxConn(): Int

returns M, the maximum number of connections for a node.

Link copied to clipboard
open fun maxNodeId(): Int

Returns max node id, inclusive. Normally this value will be size - 1.

Link copied to clipboard
abstract fun neighborCount(): Int
Link copied to clipboard
abstract fun nextNeighbor(): Int

Iterates over the neighbor list. It is illegal to call this method after it returns NO_MORE_DOCS without calling .seek, which resets the iterator.

Link copied to clipboard
abstract fun numLevels(): Int

Returns the number of levels of the graph

Link copied to clipboard
abstract fun seek(level: Int, target: Int)

Move the pointer to exactly the given level's target. After this method returns, call .nextNeighbor to return successive (ordered) connected node ordinals.

Link copied to clipboard
abstract fun size(): Int

Returns the number of nodes in the graph