java.lang.Object
org.apache.lucene.util.hnsw.HnswGraph
org.apache.lucene.util.hnsw.OnHeapHnswGraph
- All Implemented Interfaces:
Accountable
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.-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.lucene.util.hnsw.HnswGraph
HnswGraph.NodesIterator -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate NeighborArrayprivate intprivate final List<List<NeighborArray>>private final List<int[]>private final intprivate final intprivate intprivate intFields inherited from interface org.apache.lucene.util.Accountable
NULL_ACCOUNTABLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddNode(int level, int node) Add node on the given levelintReturns the graph's current entry node on the top level shown as ordinals of the nodes on 0th levelgetNeighbors(int level, int node) Returns theNeighborQueueconnected to the given node.getNodesOnLevel(int level) Get all nodes on a given level as node 0th ordinalsintIterates over the neighbor list.intReturns the current number of levels in the graphlongReturn the memory usage of this object in bytes.voidseek(int level, int targetNode) Move the pointer to exactly the givenlevel'starget.intsize()Returns the number of nodes in the graphMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.lucene.util.Accountable
getChildResources
-
Field Details
-
numLevels
private int numLevels -
entryNode
private int entryNode -
nodesByLevel
-
graph
-
nsize
private final int nsize -
nsize0
private final int nsize0 -
upto
private int upto -
cur
-
-
Constructor Details
-
OnHeapHnswGraph
OnHeapHnswGraph(int M, int levelOfFirstNode)
-
-
Method Details
-
getNeighbors
Returns theNeighborQueueconnected to the given node.- Parameters:
level- level of the graphnode- the node whose neighbors are returned, represented as an ordinal on the level 0.
-
size
public int size()Description copied from class:HnswGraphReturns the number of nodes in the graph -
addNode
public void addNode(int level, int node) Add node on the given level- Parameters:
level- level to add a node onnode- the node to add, represented as an ordinal on the level 0.
-
seek
public void seek(int level, int targetNode) Description copied from class:HnswGraphMove the pointer to exactly the givenlevel'starget. After this method returns, callHnswGraph.nextNeighbor()to return successive (ordered) connected node ordinals.- Specified by:
seekin classHnswGraph- Parameters:
level- level of the graphtargetNode- ordinal of a node in the graph, must be ≥ 0 and <FloatVectorValues.size().
-
nextNeighbor
public int nextNeighbor()Description copied from class:HnswGraphIterates over the neighbor list. It is illegal to call this method after it returns NO_MORE_DOCS without callingHnswGraph.seek(int, int), which resets the iterator.- Specified by:
nextNeighborin classHnswGraph- Returns:
- a node ordinal in the graph, or NO_MORE_DOCS if the iteration is complete.
-
numLevels
public int numLevels()Returns the current number of levels in the graph -
entryNode
public int entryNode()Returns the graph's current entry node on the top level shown as ordinals of the nodes on 0th level -
getNodesOnLevel
Description copied from class:HnswGraphGet all nodes on a given level as node 0th ordinals- Specified by:
getNodesOnLevelin classHnswGraph- Parameters:
level- level for which to get all nodes- Returns:
- an iterator over nodes where
nextIntreturns a next node on the level
-
ramBytesUsed
public long ramBytesUsed()Description copied from interface:AccountableReturn the memory usage of this object in bytes. Negative values are illegal.- Specified by:
ramBytesUsedin interfaceAccountable
-