Class Lucene90OnHeapHnswGraph


  • public final class Lucene90OnHeapHnswGraph
    extends HnswGraph
    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.
    • Constructor Detail

      • Lucene90OnHeapHnswGraph

        Lucene90OnHeapHnswGraph​(int maxConn)
    • Method Detail

      • search

        public static NeighborQueue search​(float[] query,
                                           int topK,
                                           int numSeed,
                                           RandomAccessVectorValues vectors,
                                           VectorSimilarityFunction similarityFunction,
                                           HnswGraph graphValues,
                                           Bits acceptOrds,
                                           int visitedLimit,
                                           java.util.SplittableRandom random)
                                    throws java.io.IOException
        Searches for the nearest neighbors of a query vector.
        Parameters:
        query - search query vector
        topK - the number of nodes to be returned
        numSeed - the size of the queue maintained while searching, and controls the number of random entry points to sample
        vectors - vector values
        graphValues - the graph values. May represent the entire graph, or a level in a hierarchical graph.
        acceptOrds - Bits that represents the allowed document ordinals to match, or null if they are all allowed to match.
        random - a source of randomness, used for generating entry points to the graph
        Returns:
        a priority queue holding the closest neighbors found
        Throws:
        java.io.IOException
      • getNeighbors

        public Lucene90NeighborArray getNeighbors​(int node)
        Returns the NeighborQueue connected to the given node.
        Parameters:
        node - the node whose neighbors are returned
      • size

        public int size()
        Description copied from class: HnswGraph
        Returns the number of nodes in the graph
        Specified by:
        size in class HnswGraph
      • addNode

        int addNode()
      • seek

        public void seek​(int level,
                         int targetNode)
        Description copied from class: HnswGraph
        Move the pointer to exactly the given level's target. After this method returns, call HnswGraph.nextNeighbor() to return successive (ordered) connected node ordinals.
        Specified by:
        seek in class HnswGraph
        Parameters:
        level - level of the graph
        targetNode - ordinal of a node in the graph, must be ≥ 0 and < VectorValues.size().
      • nextNeighbor

        public int nextNeighbor()
        Description copied from class: HnswGraph
        Iterates over the neighbor list. It is illegal to call this method after it returns NO_MORE_DOCS without calling HnswGraph.seek(int, int), which resets the iterator.
        Specified by:
        nextNeighbor in class HnswGraph
        Returns:
        a node ordinal in the graph, or NO_MORE_DOCS if the iteration is complete.
      • numLevels

        public int numLevels()
        Description copied from class: HnswGraph
        Returns the number of levels of the graph
        Specified by:
        numLevels in class HnswGraph
      • entryNode

        public int entryNode()
        Description copied from class: HnswGraph
        Returns graph's entry point on the top level *
        Specified by:
        entryNode in class HnswGraph
      • getNodesOnLevel

        public HnswGraph.NodesIterator getNodesOnLevel​(int level)
        Description copied from class: HnswGraph
        Get all nodes on a given level as node 0th ordinals
        Specified by:
        getNodesOnLevel in class HnswGraph
        Parameters:
        level - level for which to get all nodes
        Returns:
        an iterator over nodes where nextInt returns a next node on the level