evalcompare

package
v0.25.2 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package evalcompare pairs two cmd/eval --dump files (baseline vs candidate) by query_id and reports per-slice regressions with a fixed-seed paired bootstrap confidence interval, instead of collapsing everything into one macro-average delta.

The package is pure: no database connection, no network call, no clock read (the caller supplies a seed; there is no "now"). It only reads internal/evaldump.Dump values already parsed from disk. This is what lets cmd/evalcompare run entirely offline in CI (issue #269).

Index

Constants

View Source
const (
	GroupOverall = "overall"
)

Group name prefixes. "overall" (GroupOverall) has no prefix — it is every paired query, unfiltered, and is what the top-level Regressed decision is based on.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

type Group struct {
	Name     string        `json:"name"`
	NDCG10   GroupMetric   `json:"ndcg10"`
	Recall10 GroupMetric   `json:"recall10"`
	FP10     GroupMetric   `json:"fp10"`
	Latency  LatencyMetric `json:"latency"`
	// Gating is true only for the "overall" group. It is the only group
	// whose ndcg10 verdict feeds Report.Regressed / cmd/evalcompare's exit
	// code 1 — see Report.Regressed doc for why (deep-verify #269 HIGH
	// finding: gating on any one of several independently-tested slices
	// inflates the false-alarm rate well past the nominal 5%). Every other
	// group's metrics below are reported for diagnosis only.
	Gating bool `json:"gating"`
	// WorstQueryIDs holds up to 3 query_id values with the most negative
	// ndcg10 delta in this group — IDs only, never query text or document
	// content (see cmd/eval/diagnostics.go's privacy contract, which this
	// package inherits by construction: it never reads anything but IDs and
	// numbers out of a Row).
	WorstQueryIDs []string `json:"worst_query_ids,omitempty"`
}

Group is one slice's comparison: "overall", or an "answer_source:"/"query_source:"/"tag:"-prefixed subset.

type GroupMetric

type GroupMetric struct {
	N         int     `json:"n"`
	MeanDelta float64 `json:"mean_delta"`
	// HasCI is false when N < Options.MinN — CILow/CIHigh are meaningless
	// (left at zero) in that case, and Verdict is always "inconclusive".
	HasCI   bool    `json:"has_ci"`
	CILow   float64 `json:"ci_low,omitempty"`
	CIHigh  float64 `json:"ci_high,omitempty"`
	Verdict Verdict `json:"verdict"`
	// BonferroniSignificant is non-nil only for a non-overall (diagnostic,
	// Group.Gating == false) group whose HasCI is true. It reports, purely
	// for information, whether this metric's bootstrap distribution would
	// still exclude zero under a Bonferroni-corrected alpha
	// (0.05 / number of non-overall groups in this report) instead of the
	// uncorrected 0.05 used for Verdict. It never changes Verdict and never
	// feeds Report.Regressed — only Group.Gating's group does that.
	BonferroniSignificant *bool `json:"bonferroni_significant,omitempty"`
}

GroupMetric is one metric's paired-bootstrap result within a group.

type InvalidError

type InvalidError struct {
	Reason string
}

InvalidError means the two dumps cannot be compared at all — the underlying data does not support any verdict, not even "inconclusive". cmd/evalcompare maps this to exit code 2.

func (*InvalidError) Error

func (e *InvalidError) Error() string

type LatencyMetric

type LatencyMetric struct {
	N           int     `json:"n"`
	MedianDelta float64 `json:"median_delta_ms"`
}

LatencyMetric never gates a verdict (see package doc and #269 design): only the median delta is reported.

type Options

type Options struct {
	// Seed is the PCG seed for the paired bootstrap. Required for
	// reproducibility; there is no time-based default.
	Seed uint64
	// Iterations is the number of bootstrap resamples per group/metric.
	// Defaults to 10000 when <= 0.
	Iterations int
	// MinN is the minimum paired-query count a group needs before its
	// verdict can be anything other than "inconclusive". Defaults to 20.
	MinN int
	// AllowV1 downgrades a v1-dump (missing header, unknown provenance)
	// from an InvalidError into a comparison that still runs but whose
	// every group verdict is forced to "inconclusive" — the tool can show
	// deltas for a human to read, but it refuses to call them a regression
	// or an improvement without provenance to back that up.
	AllowV1 bool
}

Options configures a comparison run. Every bootstrap draw is derived deterministically from Seed, so the same Options + the same two dumps always produce byte-identical output.

type Report

type Report struct {
	Seed       uint64 `json:"seed"`
	Iterations int    `json:"iterations"`
	MinN       int    `json:"min_n"`

	LabelHash          string `json:"label_hash"`
	BaselineConfigHash string `json:"baseline_config_hash"`
	// CandidateConfigHash is expected to differ from BaselineConfigHash —
	// that is the thing under comparison. Both are printed so a reader can
	// see exactly which knob changed.
	CandidateConfigHash string `json:"candidate_config_hash"`

	SlicesSHA256 string `json:"slices_sha256,omitempty"`

	PairedQueries int `json:"paired_queries"`

	// ProvenanceUnknown is true only when AllowV1 forced an inconclusive
	// compare of a v1 dump. Every group's verdicts are "inconclusive" in
	// that case regardless of what the deltas show.
	ProvenanceUnknown bool     `json:"provenance_unknown"`
	Warnings          []string `json:"warnings,omitempty"`

	Groups []Group `json:"groups"`

	// Regressed is true only when the "overall" group's (see GroupOverall)
	// NDCG10 verdict is "regressed". No other group can set this flag, even
	// when its own verdict is "regressed" — those are reported on
	// Groups[i] for diagnosis (Group.Gating is false for every group but
	// overall) but deliberately excluded from the gate.
	//
	// This is a multiple-comparison correction, not an oversight: Compare
	// runs an independent 95% bootstrap test per group per metric, and
	// gating on "any group regressed" compounds their false-alarm rates.
	// deep-verify's #269 review measured this directly — with 8 slices and
	// no true difference, at least one slice falsely showed "regressed" in
	// about 20% of 60 null trials, versus the ~5% a single test carries.
	// Restricting the gate to one pre-designated group (overall) keeps the
	// false-alarm rate at the nominal single-test level; see
	// GroupMetric.BonferroniSignificant for an informational,
	// correction-adjusted read on any individual slice.
	//
	// Recall10/FP10/latency never gate this flag either way (see package
	// doc for why: an fp10 or recall10 swing without an ndcg10 swing is not,
	// by itself, this tool's definition of a regression). cmd/evalcompare
	// maps this to exit code 1.
	Regressed bool `json:"regressed"`
}

Report is the full comparison result.

func Compare

func Compare(baseline, candidate *evaldump.Dump, slices *Slices, opts Options) (*Report, error)

Compare pairs baseline and candidate by query_id and returns a Report, or an *InvalidError when the two dumps cannot be compared at all (see the InvalidError doc and cmd/evalcompare's exit code 2).

func (*Report) JSON

func (r *Report) JSON() ([]byte, error)

JSON marshals the report with two-space indentation and a trailing newline. Given the same Report value, this always produces the same bytes: every slice inside Report is already built in a fixed order (see Compare), and json.Marshal of a struct emits fields in declaration order.

func (*Report) Text

func (r *Report) Text() string

Text renders a human-readable report. Like JSON, it is deterministic for a given Report value.

type Slices

type Slices struct {
	Schema  int                 `json:"schema"`
	Version string              `json:"version"`
	Tags    map[string][]string `json:"tags"`
	// contains filtered or unexported fields
}

Slices is the versioned, query-text-free slice-label file described in issue #269: golden query IDs (golden_queries.id, never the question text itself) mapped to human-reviewed tags such as "person", "time", "exact_token", "pronoun". It is designed to live outside this repository, next to the dumps it labels — LoadSlices only reads whatever path the caller points at, and nothing in this package writes one.

func LoadSlices

func LoadSlices(path string) (*Slices, error)

LoadSlices reads and validates a slice-label file. schema must be 1 (the only version this package understands); a future incompatible schema change should bump this and add explicit migration, not silently misinterpret an old file's tags.

func (*Slices) SHA256

func (s *Slices) SHA256() string

SHA256 is the hex digest of the raw file bytes LoadSlices read. It lets a Report cite exactly which slice-label version produced a given tag grouping without embedding the file's content.

type Verdict

type Verdict string

Verdict is a group's classification for one metric.

const (
	// VerdictRegressed means the bootstrap CI for (candidate - baseline)
	// falls entirely below zero: the candidate is worse with 95% confidence.
	VerdictRegressed Verdict = "regressed"
	// VerdictImprovedCandidate means the CI falls entirely above zero. It is
	// exploratory, not a deploy decision — there is no multiple-comparison
	// correction across the groups this package reports.
	VerdictImprovedCandidate Verdict = "improved_candidate"
	// VerdictNoChange means the CI straddles zero.
	VerdictNoChange Verdict = "no_detectable_change"
	// VerdictInconclusive means the group has fewer than Options.MinN paired
	// queries (or the comparison was forced inconclusive by --allow-v1). It
	// is the expected, normal outcome for most slices of a small golden set —
	// never treat it as "regressed" or as silence to fill in with a guess.
	VerdictInconclusive Verdict = "inconclusive"
)

Jump to

Keyboard shortcuts

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