Class RecallAtK

java.lang.Object
org.opensearch.index.rankeval.RecallAtK
All Implemented Interfaces:
NamedWriteable, Writeable, org.opensearch.core.xcontent.ToXContent, org.opensearch.core.xcontent.ToXContentObject, EvaluationMetric

public class RecallAtK extends Object implements EvaluationMetric
Metric implementing Recall@K (https://en.wikipedia.org/wiki/Evaluation_measures_(information_retrieval)#Recall).
By default documents with a rating equal or bigger than 1 are considered to be "relevant" for this calculation. This value can be changed using the `relevant_rating_threshold` parameter.
The `k` parameter (defaults to 10) controls the search window size.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
     

    Nested classes/interfaces inherited from interface org.opensearch.core.xcontent.ToXContent

    org.opensearch.core.xcontent.ToXContent.DelegatingMapParams, org.opensearch.core.xcontent.ToXContent.MapParams, org.opensearch.core.xcontent.ToXContent.Params

    Nested classes/interfaces inherited from interface org.opensearch.common.io.stream.Writeable

    Writeable.Reader<V extends Object>, Writeable.WriteableRegistry, Writeable.Writer<V extends Object>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     

    Fields inherited from interface org.opensearch.core.xcontent.ToXContent

    EMPTY_PARAMS
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    RecallAtK(int relevantRatingThreshold, int k)
    Metric implementing Recall@K.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
     
    evaluate(String taskId, SearchHit[] hits, List<RatedDocument> ratedDocs)
    Compute recall at k based on provided relevant document IDs.
    Metrics can define a size of the search hits windows they want to retrieve by overwriting this method.
    static RecallAtK
    fromXContent(org.opensearch.core.xcontent.XContentParser parser)
     
    int
     
    int
    Return the rating threshold above which ratings are considered to be "relevant" for this metric.
     
    final int
     
    org.opensearch.core.xcontent.XContentBuilder
    toXContent(org.opensearch.core.xcontent.XContentBuilder builder, org.opensearch.core.xcontent.ToXContent.Params params)
     
    void
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.opensearch.index.rankeval.EvaluationMetric

    combine

    Methods inherited from interface org.opensearch.core.xcontent.ToXContentObject

    isFragment
  • Field Details

  • Constructor Details

    • RecallAtK

      public RecallAtK(int relevantRatingThreshold, int k)
      Metric implementing Recall@K.
      Parameters:
      relevantRatingThreshold - ratings equal or above this value will be considered relevant.
      k - controls the window size for the search results the metric takes into account
    • RecallAtK

      public RecallAtK()
  • Method Details

    • fromXContent

      public static RecallAtK fromXContent(org.opensearch.core.xcontent.XContentParser parser)
    • writeTo

      public void writeTo(StreamOutput out) throws IOException
      Specified by:
      writeTo in interface Writeable
      Throws:
      IOException
    • toXContent

      public org.opensearch.core.xcontent.XContentBuilder toXContent(org.opensearch.core.xcontent.XContentBuilder builder, org.opensearch.core.xcontent.ToXContent.Params params) throws IOException
      Specified by:
      toXContent in interface org.opensearch.core.xcontent.ToXContent
      Throws:
      IOException
    • getWriteableName

      public String getWriteableName()
      Specified by:
      getWriteableName in interface NamedWriteable
    • getRelevantRatingThreshold

      public int getRelevantRatingThreshold()
      Return the rating threshold above which ratings are considered to be "relevant" for this metric. Defaults to 1.
    • getK

      public int getK()
    • forcedSearchSize

      public OptionalInt forcedSearchSize()
      Description copied from interface: EvaluationMetric
      Metrics can define a size of the search hits windows they want to retrieve by overwriting this method. The default implementation returns an empty optional.
      Specified by:
      forcedSearchSize in interface EvaluationMetric
      Returns:
      the number of search hits this metrics requests
    • evaluate

      public EvalQueryQuality evaluate(String taskId, SearchHit[] hits, List<RatedDocument> ratedDocs)
      Compute recall at k based on provided relevant document IDs.
      Specified by:
      evaluate in interface EvaluationMetric
      Parameters:
      taskId - an identifier of the query for which the search ranking is evaluated
      hits - the search result hits
      ratedDocs - the documents that contain the document rating for this query case
      Returns:
      recall at k for above SearchResult list.
    • equals

      public final boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object