Module org.elasticsearch.server
Package org.elasticsearch.search.vectors
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
rescoreKresults. The vector similarity is applied inline using aFunctionScoreQuerywithout an additional filtering pass. - Late rescoring: Used when the inner query is not a top-N vector query or does not return
rescoreKresults. The toprescoreKdocuments are first collected, and then rescoring is applied separately to select the final topk.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Stringprotected final float[]protected final org.apache.lucene.search.Queryprotected final intprotected longprotected final org.apache.lucene.index.VectorSimilarityFunction -
Method Summary
Modifier and TypeMethodDescriptionbooleanstatic RescoreKnnVectorQueryfromInnerQuery(String fieldName, float[] floatTarget, org.apache.lucene.index.VectorSimilarityFunction vectorSimilarityFunction, int k, int rescoreK, org.apache.lucene.search.Query innerQuery) Selects and returns the appropriateRescoreKnnVectorQuerystrategy based on the nature of theinnerQuery.inthashCode()org.apache.lucene.search.Queryintk()voidprofile(QueryProfiler queryProfiler) Store the profiling information in theQueryProfilervoidvisit(org.apache.lucene.search.QueryVisitor visitor) Methods inherited from class org.apache.lucene.search.Query
classHash, createWeight, rewrite, sameClassAs, toString
-
Field Details
-
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 appropriateRescoreKnnVectorQuerystrategy based on the nature of theinnerQuery.- Parameters:
fieldName- the name of the field containing the vectorfloatTarget- the target vector to compare againstvectorSimilarityFunction- the similarity function to applyk- the number of top documents to return after rescoringrescoreK- the number of top documents to consider for rescoringinnerQuery- the original Lucene query to rescore
-
innerQuery
public org.apache.lucene.search.Query innerQuery() -
k
public int k() -
profile
Description copied from interface:QueryProfilerProviderStore the profiling information in theQueryProfiler- Specified by:
profilein interfaceQueryProfilerProvider- Parameters:
queryProfiler- an instance ofKnnFloatVectorField.
-
visit
public void visit(org.apache.lucene.search.QueryVisitor visitor) - Specified by:
visitin classorg.apache.lucene.search.Query
-
equals
- Specified by:
equalsin classorg.apache.lucene.search.Query
-
hashCode
public int hashCode()- Specified by:
hashCodein classorg.apache.lucene.search.Query
-
toString
- Specified by:
toStringin classorg.apache.lucene.search.Query
-