OnHeapHnswGraph

An HnswGraph where all nodes and connections are held in memory. This class is used to construct the HNSW graph before it's written to the index.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Returns nested resources of this class. The result should be a point-in-time snapshot (to avoid race conditions).

Functions

Link copied to clipboard
fun addNode(level: Int, node: Int)

Add node on the given level. Nodes can be inserted out of order, but it requires that the nodes preceded by the node inserted out of order are eventually added.

Link copied to clipboard
open override fun entryNode(): Int

Returns the graph's current entry node on the top level shown as ordinals of the nodes on 0th level

Link copied to clipboard
fun getNeighbors(level: Int, node: Int): NeighborArray

Returns the NeighborQueue connected to the given node.

Link copied to clipboard
open override fun getNodesOnLevel(level: Int): HnswGraph.NodesIterator

WARN: calling this method will essentially iterate through all nodes at level 0 (even if you're not getting node at level 0), we have built some caching mechanism such that if graph is not changed only the first non-zero level call will pay the cost. So it is highly NOT recommended to call this method while the graph is still building.

Link copied to clipboard
open override fun maxConn(): Int

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

Link copied to clipboard
open override fun maxNodeId(): Int

When we initialize from another graph, the max node id is different from .size, because we will add nodes out of order, such that we need two method for each

Link copied to clipboard
open override fun neighborCount(): Int
Link copied to clipboard
open override 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
open override fun numLevels(): Int

Returns the current number of levels in the graph

Link copied to clipboard
open override fun ramBytesUsed(): Long

Return the memory usage of this object in bytes. Negative values are illegal.

Link copied to clipboard
open override fun seek(level: Int, targetNode: 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
open override fun size(): Int

Returns the number of nodes in the graph

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun tryPromoteNewEntryNode(node: Int, level: Int, expectOldLevel: Int): Boolean

Try to promote the provided node to the entry node

Link copied to clipboard
fun trySetNewEntryNode(node: Int, level: Int): Boolean

Try to set the entry node if the graph does not have one