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

Package org.apache.lucene.codecs.hnsw

# Class PrefetchableFlatVectorScorer

java.lang.Object
org.apache.lucene.codecs.hnsw.PrefetchableFlatVectorScorer

All Implemented Interfaces:
  `FlatVectorsScorer`

public class PrefetchableFlatVectorScorer extends Object implements FlatVectorsScorer
A `FlatVectorsScorer` wrapper that enables prefetching of vector data before scoring.

This implementation demonstrates how to use prefetch operations with KNN search to preload vectors into memory before distance computations, potentially improving performance by reducing memory access latency during bulk scoring operations.

The prefetching occurs in `RandomVectorScorer.bulkScore(int[], float[], int)` before delegating to the underlying scorer.

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

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PrefetchableFlatVectorScorer(FlatVectorsScorer flatVectorsScorer)`
  Constructs a new prefetchable scorer wrapper.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `RandomVectorScorer`
  `getRandomVectorScorer(VectorSimilarityFunction similarityFunction, KnnVectorValues vectorValues, byte[] target)`
  Returns a `RandomVectorScorer` for the given set of vectors and target vector.
  `RandomVectorScorer`
  `getRandomVectorScorer(VectorSimilarityFunction similarityFunction, KnnVectorValues vectorValues, float[] target)`
  Returns a `RandomVectorScorer` for the given set of vectors and target vector.
  `RandomVectorScorerSupplier`
  `getRandomVectorScorerSupplier(VectorSimilarityFunction similarityFunction, KnnVectorValues vectorValues)`
  Returns a `RandomVectorScorerSupplier` that can be used to score vectors
  `String`
  `toString()`

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

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

- ## Constructor Details

  - ### PrefetchableFlatVectorScorer

    public PrefetchableFlatVectorScorer(FlatVectorsScorer flatVectorsScorer)
    Constructs a new prefetchable scorer wrapper.
    Parameters:
      `flatVectorsScorer` - the underlying scorer to delegate to

- ## Method Details

  - ### getRandomVectorScorerSupplier

    public RandomVectorScorerSupplier getRandomVectorScorerSupplier(VectorSimilarityFunction similarityFunction, KnnVectorValues vectorValues) throws IOException
    Description copied from interface: `FlatVectorsScorer`
    Returns a `RandomVectorScorerSupplier` that can be used to score vectors
    Specified by:
      `getRandomVectorScorerSupplier` in interface `FlatVectorsScorer`
    Parameters:
      `similarityFunction` - the similarity function to use
      `vectorValues` - the vector values to score
    Returns:
      a `RandomVectorScorerSupplier` that can be used to score vectors
    Throws:
      `IOException` - if an I/O error occurs

  - ### getRandomVectorScorer

    public RandomVectorScorer getRandomVectorScorer(VectorSimilarityFunction similarityFunction, KnnVectorValues vectorValues, float[] target) throws IOException
    Description copied from interface: `FlatVectorsScorer`
    Returns a `RandomVectorScorer` for the given set of vectors and target vector.
    Specified by:
      `getRandomVectorScorer` in interface `FlatVectorsScorer`
    Parameters:
      `similarityFunction` - the similarity function to use
      `vectorValues` - the vector values to score
      `target` - the target vector
    Returns:
      a `RandomVectorScorer` for the given field and target vector.
    Throws:
      `IOException` - if an I/O error occurs when reading from the index.

  - ### getRandomVectorScorer

    public RandomVectorScorer getRandomVectorScorer(VectorSimilarityFunction similarityFunction, KnnVectorValues vectorValues, byte[] target) throws IOException
    Description copied from interface: `FlatVectorsScorer`
    Returns a `RandomVectorScorer` for the given set of vectors and target vector.
    Specified by:
      `getRandomVectorScorer` in interface `FlatVectorsScorer`
    Parameters:
      `similarityFunction` - the similarity function to use
      `vectorValues` - the vector values to score
      `target` - the target vector
    Returns:
      a `RandomVectorScorer` for the given field and target vector.
    Throws:
      `IOException` - if an I/O error occurs when reading from the index.

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`