Class IncrementalHnswGraphMerger

java.lang.Object
org.apache.lucene.util.hnsw.IncrementalHnswGraphMerger
All Implemented Interfaces:
HnswGraphMerger
Direct Known Subclasses:
ConcurrentHnswMerger

public class IncrementalHnswGraphMerger extends Object implements HnswGraphMerger
This selects the biggest Hnsw graph from the provided merge state and initializes a new HnswGraphBuilder with that graph as a starting point.
WARNING: This API is experimental and might change in incompatible ways in the next release.
  • Field Details

  • Constructor Details

    • IncrementalHnswGraphMerger

      public IncrementalHnswGraphMerger(FieldInfo fieldInfo, RandomVectorScorerSupplier scorerSupplier, int M, int beamWidth)
      Parameters:
      fieldInfo - FieldInfo for the field being merged
  • Method Details

    • addReader

      public IncrementalHnswGraphMerger addReader(KnnVectorsReader reader, MergeState.DocMap docMap, Bits liveDocs) throws IOException
      Adds a reader to the graph merger if it meets the following criteria: 1. Does not contain any deleted docs 2. Is a HnswGraphProvider/PerFieldKnnVectorReader 3. Has the most docs of any previous reader that met the above criteria
      Specified by:
      addReader in interface HnswGraphMerger
      Parameters:
      reader - KnnVectorsReader to add to the merger
      docMap - MergeState.DocMap for the reader
      liveDocs - Bits representing live docs, can be null
      Returns:
      this
      Throws:
      IOException - If an error occurs while reading from the merge state
    • createBuilder

      protected HnswBuilder createBuilder(DocIdSetIterator mergedVectorIterator, int maxOrd) throws IOException
      Builds a new HnswGraphBuilder using the biggest graph from the merge state as a starting point. If no valid readers were added to the merge state, a new graph is created.
      Parameters:
      mergedVectorIterator - iterator over the vectors in the merged segment
      maxOrd - max num of vectors that will be merged into the graph
      Returns:
      HnswGraphBuilder
      Throws:
      IOException - If an error occurs while reading from the merge state
    • merge

      public OnHeapHnswGraph merge(DocIdSetIterator mergedVectorIterator, InfoStream infoStream, int maxOrd) throws IOException
      Description copied from interface: HnswGraphMerger
      Merge and produce the on heap graph
      Specified by:
      merge in interface HnswGraphMerger
      Parameters:
      mergedVectorIterator - iterator over the vectors in the merged segment
      infoStream - optional info stream to set to builder
      maxOrd - max number of vectors that will be added to the graph
      Returns:
      merged graph
      Throws:
      IOException - during merge
    • getNewOrdMapping

      protected final int[] getNewOrdMapping(DocIdSetIterator mergedVectorIterator, BitSet initializedNodes) throws IOException
      Creates a new mapping from old ordinals to new ordinals and returns the total number of vectors in the newly merged segment.
      Parameters:
      mergedVectorIterator - iterator over the vectors in the merged segment
      initializedNodes - track what nodes have been initialized
      Returns:
      the mapping from old ordinals to new ordinals
      Throws:
      IOException - If an error occurs while reading from the merge state