Class KnnFloatVectorQuery

Direct Known Subclasses:
KnnVectorQuery

public class KnnFloatVectorQuery extends AbstractKnnVectorQuery
Uses KnnVectorsReader.search(String, float[], int, Bits, int) to perform nearest neighbour search.

This query also allows for performing a kNN search subject to a filter. In this case, it first executes the filter for each leaf, then chooses a strategy dynamically:

  • If the filter cost is less than k, just execute an exact search
  • Otherwise run a kNN search subject to the filter
  • If the kNN search visits too many vectors without completing, stop and run an exact search
  • Field Details

    • NO_RESULTS

      private static final TopDocs NO_RESULTS
    • target

      private final float[] target
  • Constructor Details

    • KnnFloatVectorQuery

      public KnnFloatVectorQuery(String field, float[] target, int k)
      Find the k nearest documents to the target vector according to the vectors in the given field. target vector.
      Parameters:
      field - a field that has been indexed as a KnnFloatVectorField.
      target - the target of the search
      k - the number of documents to find
      Throws:
      IllegalArgumentException - if k is less than 1
    • KnnFloatVectorQuery

      public KnnFloatVectorQuery(String field, float[] target, int k, Query filter)
      Find the k nearest documents to the target vector according to the vectors in the given field. target vector.
      Parameters:
      field - a field that has been indexed as a KnnFloatVectorField.
      target - the target of the search
      k - the number of documents to find
      filter - a filter applied before the vector search
      Throws:
      IllegalArgumentException - if k is less than 1
  • Method Details