Class RescoreKnnVectorQuery

java.lang.Object
org.apache.lucene.search.Query
org.elasticsearch.search.vectors.RescoreKnnVectorQuery
All Implemented Interfaces:
QueryProfilerProvider

public abstract class RescoreKnnVectorQuery extends org.apache.lucene.search.Query implements QueryProfilerProvider
A Lucene Query that applies vector-based rescoring to an inner query's results.

Depending on the nature of the innerQuery, this class dynamically selects between two rescoring strategies:

  • Inline rescoring: Used when the inner query is already a top-N vector query with rescoreK results. The vector similarity is applied inline using a FunctionScoreQuery without an additional filtering pass.
  • Late rescoring: Used when the inner query is not a top-N vector query or does not return rescoreK results. The top rescoreK documents are first collected, and then rescoring is applied separately to select the final top k.
  • Field Details

    • fieldName

      protected final String fieldName
    • floatTarget

      protected final float[] floatTarget
    • vectorSimilarityFunction

      protected final org.apache.lucene.index.VectorSimilarityFunction vectorSimilarityFunction
    • k

      protected final int k
    • innerQuery

      protected final org.apache.lucene.search.Query innerQuery
    • vectorOperations

      protected long vectorOperations
  • Method Details

    • fromInnerQuery

      public static RescoreKnnVectorQuery fromInnerQuery(String fieldName, float[] floatTarget, org.apache.lucene.index.VectorSimilarityFunction vectorSimilarityFunction, int k, int rescoreK, org.apache.lucene.search.Query innerQuery)
      Selects and returns the appropriate RescoreKnnVectorQuery strategy based on the nature of the innerQuery.
      Parameters:
      fieldName - the name of the field containing the vector
      floatTarget - the target vector to compare against
      vectorSimilarityFunction - the similarity function to apply
      k - the number of top documents to return after rescoring
      rescoreK - the number of top documents to consider for rescoring
      innerQuery - the original Lucene query to rescore
    • innerQuery

      public org.apache.lucene.search.Query innerQuery()
    • k

      public int k()
    • profile

      public void profile(QueryProfiler queryProfiler)
      Description copied from interface: QueryProfilerProvider
      Store the profiling information in the QueryProfiler
      Specified by:
      profile in interface QueryProfilerProvider
      Parameters:
      queryProfiler - an instance of KnnFloatVectorField.
    • visit

      public void visit(org.apache.lucene.search.QueryVisitor visitor)
      Specified by:
      visit in class org.apache.lucene.search.Query
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in class org.apache.lucene.search.Query
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in class org.apache.lucene.search.Query
    • toString

      public String toString(String field)
      Specified by:
      toString in class org.apache.lucene.search.Query