ranking

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 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")

ErrInvalidSample identifies a ranking or judgment set that cannot define one deterministic relevance calculation.

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)

NewEvaluator freezes the metric, cutoff, and optional decision threshold.

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 measures relevant results among the admitted ranking.
	MetricPrecision Metric = "precision"
	// MetricRecall measures admitted relevant results among all relevant items.
	MetricRecall Metric = "recall"
	// MetricReciprocalRank rewards the rank of the first relevant result.
	MetricReciprocalRank Metric = "reciprocal_rank"
	// MetricAveragePrecision averages precision at every relevant result.
	MetricAveragePrecision Metric = "average_precision"
	// MetricNDCG preserves graded relevance while discounting later ranks.
	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)

NewSample snapshots identities and judgments before validating their unique correlation.

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