Lucene99HnswVectorsWriter (Lucene 10.5.1 core API)
Description: declaration: package: org.apache.lucene.codecs.lucene99, class: Lucene99HnswVectorsWriter

Package org.apache.lucene.codecs.lucene99

# Class Lucene99HnswVectorsWriter

java.lang.Object
org.apache.lucene.codecs.KnnVectorsWriter
org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsWriter

All Implemented Interfaces:
  `Closeable`, `AutoCloseable`, `Accountable`

public final class Lucene99HnswVectorsWriter extends KnnVectorsWriter
Writes vector values and knn graphs to index segments.

WARNING: This API is experimental and might change in incompatible ways in the next release.

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from class org.apache.lucene.codecs.KnnVectorsWriter

  `KnnVectorsWriter.MergedVectorValues`

- ## Field Summary

  ### Fields inherited from interface org.apache.lucene.util.Accountable

  `NULL_ACCOUNTABLE`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Lucene99HnswVectorsWriter(SegmentWriteState state, int M, int beamWidth, FlatVectorsFormat flatVectorsFormat, FlatVectorsWriter flatVectorWriter, int numMergeWorkers, TaskExecutor mergeExec)`
  `Lucene99HnswVectorsWriter(SegmentWriteState state, int M, int beamWidth, FlatVectorsFormat flatVectorsFormat, FlatVectorsWriter flatVectorWriter, int numMergeWorkers, TaskExecutor mergeExec, int tinySegmentsThreshold)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `KnnFieldVectorsWriter<?>`
  `addField(FieldInfo fieldInfo)`
  Add new field for indexing
  `void`
  `close()`
  `void`
  `finish()`
  Called once at the end before close
  `void`
  `flush(int maxDoc, Sorter.DocMap sortMap)`
  Flush all buffered data on disk *
  `IORunnable`
  `mergeOneField(FieldInfo fieldInfo, MergeState mergeState)`
  Merges vectors for a single field, returning a runnable for any deferred work (e.g., HNSW graph construction).
  `long`
  `ramBytesUsed()`
  Returns an estimate of the JVM heap memory used by this object in bytes.

  ### Methods inherited from class org.apache.lucene.codecs.KnnVectorsWriter

  `mapOldOrdToNewOrd, merge`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface org.apache.lucene.util.Accountable

  `getChildResources`

- ## Constructor Details

  - ### Lucene99HnswVectorsWriter

    public Lucene99HnswVectorsWriter(SegmentWriteState state, int M, int beamWidth, FlatVectorsFormat flatVectorsFormat, FlatVectorsWriter flatVectorWriter, int numMergeWorkers, TaskExecutor mergeExec) throws IOException
    Throws:
      `IOException`

  - ### Lucene99HnswVectorsWriter

    public Lucene99HnswVectorsWriter(SegmentWriteState state, int M, int beamWidth, FlatVectorsFormat flatVectorsFormat, FlatVectorsWriter flatVectorWriter, int numMergeWorkers, TaskExecutor mergeExec, int tinySegmentsThreshold) throws IOException
    Throws:
      `IOException`

- ## Method Details

  - ### addField

    public KnnFieldVectorsWriter<?> addField(FieldInfo fieldInfo) throws IOException
    Description copied from class: `KnnVectorsWriter`
    Add new field for indexing
    Specified by:
      `addField` in class `KnnVectorsWriter`
    Throws:
      `IOException`

  - ### flush

    public void flush(int maxDoc, Sorter.DocMap sortMap) throws IOException
    Description copied from class: `KnnVectorsWriter`
    Flush all buffered data on disk *
    Specified by:
      `flush` in class `KnnVectorsWriter`
    Throws:
      `IOException`

  - ### finish

    public void finish() throws IOException
    Description copied from class: `KnnVectorsWriter`
    Called once at the end before close
    Specified by:
      `finish` in class `KnnVectorsWriter`
    Throws:
      `IOException`

  - ### ramBytesUsed

    public long ramBytesUsed()
    Description copied from interface: `Accountable`
    Returns an estimate of the JVM heap memory used by this object in bytes. The method name uses "ram" for historical reasons; only JVM heap memory should be reported. Off-heap resources such as memory-mapped files or native direct buffers should not be included. Negative values are illegal.

  - ### mergeOneField

    public IORunnable mergeOneField(FieldInfo fieldInfo, MergeState mergeState) throws IOException
    Description copied from class: `KnnVectorsWriter`
    Merges vectors for a single field, returning a runnable for any deferred work (e.g., HNSW graph construction). The default implementation merges naively the vectors and returns `null` (no deferred work).

    Subclasses should override this method may implement a two-phase merge strategy where flat vectors are written in the first phase and additional indexing structures (like HNSW graphs) are built in the second phase using the already-written flat vector data.

    Overrides:
      `mergeOneField` in class `KnnVectorsWriter`
    Parameters:
      `fieldInfo` - the field to merge
      `mergeState` - the merge state
    Returns:
      a runnable to execute in phase 2, or `null` if there is no deferred work
    Throws:
      `IOException` - if an I/O error occurs

  - ### close

    public void close() throws IOException
    Throws:
      `IOException`