KnnVectorsFormat (Lucene 10.5.0 core API)
Description: declaration: package: org.apache.lucene.codecs, class: KnnVectorsFormat

Package org.apache.lucene.codecs

# Class KnnVectorsFormat

java.lang.Object
org.apache.lucene.codecs.KnnVectorsFormat

All Implemented Interfaces:
  `NamedSPILoader.NamedSPI`

Direct Known Subclasses:
  `FlatVectorsFormat`, `Lucene104HnswScalarQuantizedVectorsFormat`, `Lucene99HnswVectorsFormat`, `PerFieldKnnVectorsFormat`

public abstract class KnnVectorsFormat extends Object implements NamedSPILoader.NamedSPI
Encodes/decodes per-document vector and any associated indexing structures required to support nearest-neighbor search

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `DEFAULT_MAX_DIMENSIONS`
  The maximum number of vector dimensions
  `static final KnnVectorsFormat`
  `EMPTY`
  EMPTY throws an exception when written.

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `KnnVectorsFormat(String name)`
  Sole constructor

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static Set<String>`
  `availableKnnVectorsFormats()`
  returns a list of all available format names
  `abstract KnnVectorsReader`
  `fieldsReader(SegmentReadState state)`
  Returns a `KnnVectorsReader` to read the vectors from the index.
  `abstract KnnVectorsWriter`
  `fieldsWriter(SegmentWriteState state)`
  Returns a `KnnVectorsWriter` to write the vectors to the index.
  `static KnnVectorsFormat`
  `forName(String name)`
  looks up a format by name
  `abstract int`
  `getMaxDimensions(String fieldName)`
  Returns the maximum number of vector dimensions supported by this codec for the given field name
  `String`
  `getName()`
  `static void`
  `reloadKnnVectorsFormat(ClassLoader classloader)`
  Reloads the KnnVectorsFormat list from the given `ClassLoader`.

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

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

- ## Field Details

  - ### DEFAULT_MAX_DIMENSIONS

    public static final int DEFAULT_MAX_DIMENSIONS
    The maximum number of vector dimensions
    See Also:
      - Constant Field Values

  - ### EMPTY

    public static final KnnVectorsFormat EMPTY
    EMPTY throws an exception when written. It acts as a sentinel indicating a Codec that does not support vectors.

- ## Constructor Details

  - ### KnnVectorsFormat

    protected KnnVectorsFormat(String name)
    Sole constructor

- ## Method Details

  - ### getName

    public String getName()
    Specified by:
      `getName` in interface `NamedSPILoader.NamedSPI`

  - ### reloadKnnVectorsFormat

    public static void reloadKnnVectorsFormat(ClassLoader classloader)
    Reloads the KnnVectorsFormat list from the given `ClassLoader`.

    NOTE: Only new KnnVectorsFormat are added, existing ones are never removed or replaced.

    This method is expensive and should only be called for discovery of new KnnVectorsFormat on the given classpath/classloader!

  - ### forName

    public static KnnVectorsFormat forName(String name)
    looks up a format by name

  - ### availableKnnVectorsFormats

    public static Set<String> availableKnnVectorsFormats()
    returns a list of all available format names

  - ### fieldsWriter

    public abstract KnnVectorsWriter fieldsWriter(SegmentWriteState state) throws IOException
    Returns a `KnnVectorsWriter` to write the vectors to the index.
    Throws:
      `IOException`

  - ### fieldsReader

    public abstract KnnVectorsReader fieldsReader(SegmentReadState state) throws IOException
    Returns a `KnnVectorsReader` to read the vectors from the index.
    Throws:
      `IOException`

  - ### getMaxDimensions

    public abstract int getMaxDimensions(String fieldName)
    Returns the maximum number of vector dimensions supported by this codec for the given field name

    Codecs implement this method to specify the maximum number of dimensions they support.

    Parameters:
      `fieldName` - the field name
    Returns:
      the maximum number of vector dimensions.