Class RescoreTopNQuery
DoubleValuesSource function and cut-off the
results at top N. Unlike Rescorer which does rescoring at post-collection phase, this
Query does the rescoring at rewrite() phase. The reason it operates in rewrite phase is to be
compatible with KNN vector query, where the results are collected upfront, but it can work with
any type of Query. Unlike or FunctionScoreQuery, this Query will work even with the
no-scoring ScoreMode.- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
Constructor Summary
ConstructorsConstructorDescriptionRescoreTopNQuery(Query query, DoubleValuesSource valuesSource, int n) Execute the inner Query, re-score using a customizable DoubleValueSource and trim down the result to k -
Method Summary
Modifier and TypeMethodDescriptionstatic QuerycreateFullPrecisionRescorerQuery(Query in, float[] targetVector, String field, int n) Utility method to create a new RescoreTopNQuery which uses full-precision vectors for rescoring.static QuerycreateLateInteractionQuery(Query in, int n, String fieldName, float[][] queryVector, VectorSimilarityFunction vectorSimilarityFunction) Creates aRescoreTopNQuerythat computes top N results using multi-vector similarity comparisons against a late interaction field.booleanOverride and implement query instance equivalence properly in a subclass.inthashCode()Override and implement query hash code properly in a subclass.rewrite(IndexSearcher indexSearcher) Expert: called to re-write queries into primitive queries.Prints a query to a string, withfieldassumed to be the default field and omitted.voidvisit(QueryVisitor visitor) Recurse through the query tree, visiting any child queries.Methods inherited from class org.apache.lucene.search.Query
classHash, createWeight, sameClassAs, toString
-
Constructor Details
-
RescoreTopNQuery
Execute the inner Query, re-score using a customizable DoubleValueSource and trim down the result to k- Parameters:
query- the query to execute as initial phasevaluesSource- the double value source to re-scoren- the number of documents to find- Throws:
IllegalArgumentException- ifnis less than 1
-
-
Method Details
-
rewrite
Description copied from class:QueryExpert: called to re-write queries into primitive queries. For example, a PrefixQuery will be rewritten into a BooleanQuery that consists of TermQuerys.Callers are expected to call
rewritemultiple times if necessary, until the rewritten query is the same as the original query.The rewrite process may be able to make use of IndexSearcher's executor and be executed in parallel if the executor is provided.
- Overrides:
rewritein classQuery- Throws:
IOException- See Also:
-
hashCode
public int hashCode()Description copied from class:QueryOverride and implement query hash code properly in a subclass. This is required so thatQueryCacheworks properly. -
equals
Description copied from class:QueryOverride and implement query instance equivalence properly in a subclass. This is required so thatQueryCacheworks properly.Typically a query will be equal to another only if it's an instance of the same class and its document-filtering properties are identical to those of the other instance. Utility methods are provided for certain repetitive code.
-
visit
Description copied from class:QueryRecurse through the query tree, visiting any child queries. -
toString
Description copied from class:QueryPrints a query to a string, withfieldassumed to be the default field and omitted. -
createFullPrecisionRescorerQuery
public static Query createFullPrecisionRescorerQuery(Query in, float[] targetVector, String field, int n) Utility method to create a new RescoreTopNQuery which uses full-precision vectors for rescoring.- Parameters:
in- the inner Query to rescoretargetVector- the target vector to compute scorefield- the vector field to compute scoren- the number of results to keep- Returns:
- the RescoreTopNQuery
-
createLateInteractionQuery
public static Query createLateInteractionQuery(Query in, int n, String fieldName, float[][] queryVector, VectorSimilarityFunction vectorSimilarityFunction) Creates aRescoreTopNQuerythat computes top N results using multi-vector similarity comparisons against a late interaction field.Note: This query computes late interaction field similarity for the entire match-set of wrapped query, and returns a new query with only top-N hits in the match-set. This is typically useful in combining a query's results with other queries for hybrid search. To simply rerank the top N hits without scoring entire match-set, see
LateInteractionRescorer.- Parameters:
in- the inner Query to rescoren- number of results to keepfieldName- theLateInteractionFieldfor recomputing top N hitsqueryVector- query multi-vector to use for similarity comparisonsvectorSimilarityFunction- function to use for vector similarity comparisons.
-