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

Package org.apache.lucene.codecs.hnsw

# Class FlatVectorsWriter

java.lang.Object
org.apache.lucene.codecs.KnnVectorsWriter
org.apache.lucene.codecs.hnsw.FlatVectorsWriter

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

Direct Known Subclasses:
  `Lucene104ScalarQuantizedVectorsWriter`, `Lucene99FlatVectorsWriter`

public abstract class FlatVectorsWriter extends KnnVectorsWriter
Vectors' writer for a field that allows additional indexing logic to be implemented by the caller

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
  Modifier and Type
  Field
  Description
  `protected final FlatVectorsScorer`
  `vectorsScorer`
  Scorer for flat vectors

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

  `NULL_ACCOUNTABLE`

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `FlatVectorsWriter(FlatVectorsScorer vectorsScorer)`
  Sole constructor

- ## Method Summary

  Modifier and Type
  Method
  Description
  `abstract FlatFieldVectorsWriter<?>`
  `addField(FieldInfo fieldInfo)`
  Add a new field for indexing
  `FlatVectorsScorer`
  `getFlatVectorScorer()`
  `final IORunnable`
  `mergeOneField(FieldInfo fieldInfo, MergeState mergeState)`
  Merges vectors for a single field, returning a runnable for any deferred work (e.g., HNSW graph construction).
  `abstract void`
  `mergeOneFlatVectorField(FieldInfo fieldInfo, MergeState mergeState)`

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

  `finish, flush, 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, ramBytesUsed`

  ### Methods inherited from interface java.io.Closeable

  `close`

- ## Field Details

  - ### vectorsScorer

    protected final FlatVectorsScorer vectorsScorer
    Scorer for flat vectors

- ## Constructor Details

  - ### FlatVectorsWriter

    protected FlatVectorsWriter(FlatVectorsScorer vectorsScorer)
    Sole constructor

- ## Method Details

  - ### getFlatVectorScorer

    public FlatVectorsScorer getFlatVectorScorer()
    Returns:
      the `FlatVectorsScorer` for this reader.

  - ### addField

    public abstract FlatFieldVectorsWriter<?> addField(FieldInfo fieldInfo) throws IOException
    Add a new field for indexing
    Specified by:
      `addField` in class `KnnVectorsWriter`
    Parameters:
      `fieldInfo` - fieldInfo of the field to add
    Returns:
      a writer for the field
    Throws:
      `IOException` - if an I/O error occurs when adding the field

  - ### mergeOneField

    public final 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

  - ### mergeOneFlatVectorField

    public abstract void mergeOneFlatVectorField(FieldInfo fieldInfo, MergeState mergeState) throws IOException
    Throws:
      `IOException`