ranking

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package ranking evaluates ranked outputs against graded relevance judgments.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidSample = errors.New("eval/ranking: invalid sample")

Functions

This section is empty.

Types

type Config

type Config struct {
	Metric    Metric
	Cutoff    int
	Threshold *eval.Score
}

Config configures one deterministic ranking evaluator. Cutoff is required and positive. A nil Threshold produces a score without a pass/fail verdict.

type Evaluator

type Evaluator struct {
	// contains filtered or unexported fields
}

Evaluator measures one standard ranking metric at a fixed cutoff.

func NewEvaluator

func NewEvaluator(config Config) (*Evaluator, error)

func (*Evaluator) Evaluate

func (e *Evaluator) Evaluate(ctx context.Context, sample Sample) (eval.Report, error)

type Judgment

type Judgment struct {
	Identity  string  `json:"identity"`
	Relevance float64 `json:"relevance"`
}

Judgment assigns a non-negative relevance grade to one ranked identity. A positive grade is relevant for binary metrics; NDCG uses the full grade.

type Metric

type Metric string

Metric selects a ranking-quality calculation evaluated at a configured cutoff.

const (
	MetricPrecision        Metric = "precision"
	MetricRecall           Metric = "recall"
	MetricReciprocalRank   Metric = "reciprocal_rank"
	MetricAveragePrecision Metric = "average_precision"
	MetricNDCG             Metric = "ndcg"
)

func (Metric) Validate

func (m Metric) Validate() error

type Sample

type Sample struct {
	Ranking   []string   `json:"ranking,omitzero"`
	Judgments []Judgment `json:"judgments"`
}

Sample contains one observed ranking and its relevance judgments. Ranking identities without a judgment are treated as having zero relevance.

func NewSample

func NewSample(ranking []string, judgments []Judgment) (Sample, error)

func (Sample) Clone

func (s Sample) Clone() Sample

func (Sample) Validate

func (s Sample) Validate() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL