Class AbstractHnswVectorsFormat

java.lang.Object
org.apache.lucene.codecs.KnnVectorsFormat
org.elasticsearch.index.codec.vectors.AbstractHnswVectorsFormat
All Implemented Interfaces:
org.apache.lucene.util.NamedSPILoader.NamedSPI
Direct Known Subclasses:
ES814HnswScalarQuantizedVectorsFormat, ES815HnswBitVectorsFormat, ES816HnswBinaryQuantizedVectorsFormat, ES818HnswBinaryQuantizedVectorsFormat, ES93HnswBinaryQuantizedVectorsFormat, ES93HnswScalarQuantizedVectorsFormat, ES93HnswVectorsFormat, ES94HnswScalarQuantizedVectorsFormat

public abstract class AbstractHnswVectorsFormat extends org.apache.lucene.codecs.KnnVectorsFormat
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final int
    The number of candidate neighbors to track while searching the graph for each newly inserted node.
    static final int
    Always build HNSW graph regardless of segment size
    protected final int
    The minimum expected search cost before building an HNSW graph becomes worthwhile.
    protected final int
    Controls how many of the nearest neighbor candidates are connected to the new node.
    protected final org.apache.lucene.search.TaskExecutor
     
    protected final int
     

    Fields inherited from class org.apache.lucene.codecs.KnnVectorsFormat

    DEFAULT_MAX_DIMENSIONS, EMPTY
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractHnswVectorsFormat(String name, int maxConn, int beamWidth, int numMergeWorkers, ExecutorService mergeExec, int hnswGraphThreshold)
    Constructs a format using the given graph construction parameters, merge settings, and HNSW graph threshold.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract org.apache.lucene.codecs.hnsw.FlatVectorsFormat
     
    int
     
    protected static int
    resolveThreshold(int threshold, int defaultThreshold)
    Resolves the HNSW graph threshold.
     

    Methods inherited from class org.apache.lucene.codecs.KnnVectorsFormat

    availableKnnVectorsFormats, fieldsReader, fieldsWriter, forName, getName, reloadKnnVectorsFormat

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • maxConn

      protected final int maxConn
      Controls how many of the nearest neighbor candidates are connected to the new node. Defaults to Lucene99HnswVectorsFormat.DEFAULT_MAX_CONN. See HnswGraph for more details.
    • beamWidth

      protected final int beamWidth
      The number of candidate neighbors to track while searching the graph for each newly inserted node. Defaults to Lucene99HnswVectorsFormat.DEFAULT_BEAM_WIDTH. See HnswGraph for details.
    • numMergeWorkers

      protected final int numMergeWorkers
    • mergeExec

      protected final org.apache.lucene.search.TaskExecutor mergeExec
    • DEFAULT_HNSW_GRAPH_THRESHOLD

      public static final int DEFAULT_HNSW_GRAPH_THRESHOLD
      Always build HNSW graph regardless of segment size
      See Also:
    • hnswGraphThreshold

      protected final int hnswGraphThreshold
      The minimum expected search cost before building an HNSW graph becomes worthwhile. Below this threshold, brute-force search is efficient enough that graph construction overhead isn't worthwhile.
  • Constructor Details

    • AbstractHnswVectorsFormat

      protected AbstractHnswVectorsFormat(String name, int maxConn, int beamWidth, int numMergeWorkers, ExecutorService mergeExec, int hnswGraphThreshold)
      Constructs a format using the given graph construction parameters, merge settings, and HNSW graph threshold.
      Parameters:
      maxConn - the maximum number of connections to a node in the HNSW graph
      beamWidth - the size of the queue maintained during graph construction.
      numMergeWorkers - number of workers (threads) that will be used when doing merge. If larger than 1, a non-null ExecutorService must be passed as mergeExec
      mergeExec - the ExecutorService that will be used by ALL vector writers that are generated by this format to do the merge
      hnswGraphThreshold - the minimum expected search cost before building an HNSW graph; if negative, use format default
  • Method Details

    • resolveThreshold

      protected static int resolveThreshold(int threshold, int defaultThreshold)
      Resolves the HNSW graph threshold. If the given threshold is negative (not set), returns the provided default.
    • flatVectorsFormat

      protected abstract org.apache.lucene.codecs.hnsw.FlatVectorsFormat flatVectorsFormat()
    • getMaxDimensions

      public int getMaxDimensions(String fieldName)
      Specified by:
      getMaxDimensions in class org.apache.lucene.codecs.KnnVectorsFormat
    • toString

      public String toString()
      Overrides:
      toString in class Object