LateInteractionRescorer (Lucene 10.5.1 core API)
Description: declaration: package: org.apache.lucene.search, class: LateInteractionRescorer

Package org.apache.lucene.search

# Class LateInteractionRescorer

java.lang.Object
org.apache.lucene.search.Rescorer
org.apache.lucene.search.DoubleValuesSourceRescorer
org.apache.lucene.search.LateInteractionRescorer

public class LateInteractionRescorer extends DoubleValuesSourceRescorer
Rescores top N results from a first pass query using a `LateInteractionFloatValuesSource`

Typically, you run a low-cost first pass query to collect results from across the index, then use this rescorer to rerank top N hits using multi-vectors, usually from a late interaction model. Multi-vectors should be indexed in the `LateInteractionField` provided to rescorer.

WARNING: This API is experimental and might change in incompatible ways in the next release.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `LateInteractionRescorer(LateInteractionFloatValuesSource valuesSource)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected float`
  `combine(float firstPassScore, boolean valuePresent, double sourceValue)`
  Implement this in a subclass to combine the first pass scores with values from the DoubleValuesSource
  `static LateInteractionRescorer`
  `create(String fieldName, float[][] queryVector)`
  Creates a LateInteractionRescorer for provided query vector.
  `static LateInteractionRescorer`
  `create(String fieldName, float[][] queryVector, VectorSimilarityFunction vectorSimilarityFunction)`
  Creates a LateInteractionRescorer for provided query vector.
  `static LateInteractionRescorer`
  `withFallbackToFirstPassScore(String fieldName, float[][] queryVector, VectorSimilarityFunction vectorSimilarityFunction)`
  Creates a LateInteractionRescorer for provided query vector.

  ### Methods inherited from class org.apache.lucene.search.DoubleValuesSourceRescorer

  `explain, rescore`

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

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

- ## Constructor Details

  - ### LateInteractionRescorer

    public LateInteractionRescorer(LateInteractionFloatValuesSource valuesSource)

- ## Method Details

  - ### create

    public static LateInteractionRescorer create(String fieldName, float[][] queryVector)
    Creates a LateInteractionRescorer for provided query vector.

  - ### create

    public static LateInteractionRescorer create(String fieldName, float[][] queryVector, VectorSimilarityFunction vectorSimilarityFunction)
    Creates a LateInteractionRescorer for provided query vector.

    Top N results from a first pass query are rescored based on the similarity between `queryVector` and the multi-vector indexed in `fieldName`. If document does not have a value indexed in `fieldName`, a 0f score is assigned.

    Parameters:
      `fieldName` - the `LateInteractionField` used for reranking.
      `queryVector` - query multi-vector to use for similarity comparison
      `vectorSimilarityFunction` - function used for vector similarity comparisons

  - ### combine

    protected float combine(float firstPassScore, boolean valuePresent, double sourceValue)
    Description copied from class: `DoubleValuesSourceRescorer`
    Implement this in a subclass to combine the first pass scores with values from the DoubleValuesSource
    Specified by:
      `combine` in class `DoubleValuesSourceRescorer`
    Parameters:
      `firstPassScore` - Score from firstPassTopDocs
      `valuePresent` - true if DoubleValuesSource has a value for the hit from first pass
      `sourceValue` - Value returned from DoubleValuesSource

  - ### withFallbackToFirstPassScore

    public static LateInteractionRescorer withFallbackToFirstPassScore(String fieldName, float[][] queryVector, VectorSimilarityFunction vectorSimilarityFunction)
    Creates a LateInteractionRescorer for provided query vector.

    Top N results from a first pass query are rescored based on the similarity between `queryVector` and the multi-vector indexed in `fieldName`. Falls back to score from the first pass query if a document does not have a value indexed in `fieldName`.

    Parameters:
      `fieldName` - the `LateInteractionField` used for reranking.
      `queryVector` - query multi-vector to use for similarity comparison
      `vectorSimilarityFunction` - function used for vector similarity comparisons.