SampleReader (Lucene 10.5.1 sandbox API)
Description: declaration: package: org.apache.lucene.sandbox.codecs.quantization, class: SampleReader

Package org.apache.lucene.sandbox.codecs.quantization

# Class SampleReader

java.lang.Object
org.apache.lucene.index.KnnVectorValues
org.apache.lucene.index.FloatVectorValues
org.apache.lucene.sandbox.codecs.quantization.SampleReader

All Implemented Interfaces:
  `HasIndexSlice`

public class SampleReader extends FloatVectorValues implements HasIndexSlice
A reader of vector values that samples a subset of the vectors.

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from class org.apache.lucene.index.KnnVectorValues

  `KnnVectorValues.DocIndexIterator`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `FloatVectorValues`
  `copy()`
  `static SampleReader`
  `createSampleReader(FloatVectorValues origin, int k, long seed)`
  `int`
  `dimension()`
  `Bits`
  `getAcceptOrds(Bits acceptDocs)`
  `IndexInput`
  `getSlice()`
  `int`
  `getVectorByteLength()`
  `int`
  `ordToDoc(int ord)`
  `static int[]`
  `reservoirSample(int n, int k, long seed)`
  Sample k elements from n elements according to reservoir sampling algorithm.
  `static int[]`
  `reservoirSampleFromArray(int[] origin, int k, long seed)`
  Sample k elements from the origin array using reservoir sampling algorithm.
  `int`
  `size()`
  `float[]`
  `vectorValue(int targetOrd)`

  ### Methods inherited from class org.apache.lucene.index.FloatVectorValues

  `checkField, fromFloats, getEncoding, rescorer, scorer`

  ### Methods inherited from class org.apache.lucene.index.KnnVectorValues

  `createDenseIterator, createSparseIterator, fromDISI, iterator, prefetch`

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

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

- ## Method Details

  - ### size

    public int size()
    Specified by:
      `size` in class `KnnVectorValues`

  - ### dimension

    public int dimension()
    Specified by:
      `dimension` in class `KnnVectorValues`

  - ### copy

    public FloatVectorValues copy() throws IOException
    Specified by:
      `copy` in class `FloatVectorValues`
    Throws:
      `IOException`

  - ### getSlice

    public IndexInput getSlice()
    Specified by:
      `getSlice` in interface `HasIndexSlice`

  - ### vectorValue

    public float[] vectorValue(int targetOrd) throws IOException
    Specified by:
      `vectorValue` in class `FloatVectorValues`
    Throws:
      `IOException`

  - ### getVectorByteLength

    public int getVectorByteLength()
    Overrides:
      `getVectorByteLength` in class `KnnVectorValues`

  - ### ordToDoc

    public int ordToDoc(int ord)
    Overrides:
      `ordToDoc` in class `KnnVectorValues`

  - ### getAcceptOrds

    public Bits getAcceptOrds(Bits acceptDocs)
    Overrides:
      `getAcceptOrds` in class `KnnVectorValues`

  - ### createSampleReader

    public static SampleReader createSampleReader(FloatVectorValues origin, int k, long seed)

  - ### reservoirSample

    public static int[] reservoirSample(int n, int k, long seed)
    Sample k elements from n elements according to reservoir sampling algorithm.
    Parameters:
      `n` - number of elements
      `k` - number of samples
      `seed` - random seed
    Returns:
      array of k samples

  - ### reservoirSampleFromArray

    public static int[] reservoirSampleFromArray(int[] origin, int k, long seed)
    Sample k elements from the origin array using reservoir sampling algorithm.
    Parameters:
      `origin` - original array
      `k` - number of samples
      `seed` - random seed
    Returns:
      array of k samples