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 ¶
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 ¶
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 ¶
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 ¶
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.
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 ¶
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.
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" )