dataset

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 9 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 dataset owns the train/holdout split of the search feedback labels and the boundary that keeps the holdout half out of the optimiser's reach.

The package exists because "we agreed not to tune on the validation set" is not a mechanism. Here the separation is carried by types: Load hands back a TrainSet whose pairs are readable and a HoldoutSet whose pairs are not, and the Go compiler — not a convention — refuses code in any other package that tries to read them.

Index

Constants

View Source
const (
	SplitTrain   = "train"
	SplitHoldout = "holdout"
)

Split values stored in feedback.split.

View Source
const DefaultHoldoutBudget = 2

DefaultHoldoutBudget is how many times a HoldoutSet may be evaluated: one baseline measurement plus one candidate measurement. Repeatedly probing the holdout set and keeping whichever candidate scores best turns it into a second training set with extra steps, so the budget is a hard stop rather than a warning.

Variables

View Source
var ErrHoldoutBudgetExhausted = errors.New("dataset: holdout evaluation budget exhausted")

ErrHoldoutBudgetExhausted is returned by HoldoutSet.Evaluate once the evaluation budget is spent.

Functions

func Load

func Load(ctx context.Context, src Source) (*TrainSet, *HoldoutSet, error)

Load reads the two splits with two separate queries and returns them as distinct types.

Splits are read separately rather than read whole and partitioned in memory: a single "read everything" call would put the holdout rows in a variable that some future caller could pass along, and the point of this package is that such a variable never exists outside it.

func Normalize

func Normalize(query string) string

Normalize collapses a query to the form the split rule hashes.

It mirrors PostgreSQL's `lower(btrim(query))` used by the backfill and the uniqueness index in migrations/025_feedback_evidence.sql. btrim's default trim set is the space character only, so this deliberately uses strings.Trim(q, " ") rather than strings.TrimSpace: TrimSpace also strips tabs and newlines, which would make Go and SQL disagree on any query that carries one, and a disagreement here puts the same query in both splits.

func ObjectiveOf

func ObjectiveOf(ndcg10, fpPenalty10 float64) float64

ObjectiveOf is the single objective function used for both search and promotion: NDCG@10 penalised by half the false-positive rate at 10 (plan §2.4). Defined once here so a tuner and a gate cannot disagree about what "better" means.

func QueryHash

func QueryHash(query string) string

QueryHash returns the first 8 hex characters of md5(normalized query). It is the only identifier for a query that may appear in logs, spans or error messages: the raw text is user speech and routinely contains names, phone numbers and other personal detail.

func SplitOf

func SplitOf(query string) string

SplitOf returns SplitTrain or SplitHoldout for a query, or "" when the query is empty after normalisation (such rows are not splittable and are ignored by the loader).

The rule is: uint32(first 4 bytes of md5(splitSeed || normalized)) % 100. PostgreSQL's ('x'||substr(md5(...),1,8))::bit(32)::bigint yields the same unsigned value, which is why the SQL backfill and this function agree. TestSplitOf_KnownVectors pins that agreement to concrete values.

Types

type HoldoutSet

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

HoldoutSet is the closed half. Every field is unexported and the only exported methods are Evaluate and Queries, neither of which returns a query string, a document ID or an evaluation pair. A caller in another package can therefore measure against the holdout set but cannot look at it — the compiler enforces this, and TestHoldoutSet_ExportedSurfaceIsFrozen keeps the surface from quietly growing.

func (*HoldoutSet) Evaluate

func (h *HoldoutSet) Evaluate(ctx context.Context, run RunFunc) (Metrics, error)

Evaluate runs the supplied searcher over every holdout query and returns the aggregate metrics. The pairs themselves never leave this method.

The budget is spent on entry, including for a run that later fails: an attempt that reached the search path has already observed the holdout set, and letting failures be free would make an unlimited probing loop trivial to write by accident.

func (*HoldoutSet) Queries

func (h *HoldoutSet) Queries() int

Queries returns how many holdout queries exist. It is a count, not the queries — the promotion gate needs the size of the sample and nothing more.

type Metrics

type Metrics struct {
	NDCG10      float64 `json:"ndcg10"`
	MRR10       float64 `json:"mrr10"`
	FPPenalty10 float64 `json:"fp_penalty10"`
	Objective   float64 `json:"objective"`
	Pairs       int     `json:"pairs"`
	Queries     int     `json:"queries"`
}

Metrics is the entire output of an evaluation: scalars, no per-query detail.

type RunFunc

type RunFunc func(ctx context.Context, query string, k int) ([]string, error)

RunFunc executes one search and returns the top-k document IDs in rank order. It is the only thing a caller hands to HoldoutSet.Evaluate — the caller supplies the searcher, the set supplies the questions, and only aggregate numbers come back.

type Source

type Source interface {
	EvalPairsBySplit(ctx context.Context, split string) ([]store.EvalPair, error)
}

Source supplies evaluation pairs for exactly one split at a time. *store.EvalStore satisfies it.

The interface takes the split as an argument on purpose: there is no "give me everything" method to accidentally call, so no code path exists that could hand the whole labelled set to a tuner.

type TrainSet

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

TrainSet is the readable half. Coordinate search needs the raw pairs, so they are exposed.

func (*TrainSet) EvaluateTrain

func (t *TrainSet) EvaluateTrain(ctx context.Context, run RunFunc) (Metrics, error)

EvaluateTrain runs the searcher over the training pairs. Unlike the holdout path this is unbudgeted — the train split is what coordinate search is supposed to be hammering.

func (*TrainSet) Pairs

func (t *TrainSet) Pairs() []store.EvalPair

Pairs returns a copy of the training pairs. The copy keeps a caller from mutating the set between evaluations, which would make a search run irreproducible.

func (*TrainSet) Queries

func (t *TrainSet) Queries() int

Queries returns the number of training pairs (one pair per distinct query).

Jump to

Keyboard shortcuts

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