quality

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package quality stores and retrieves per-version quality scores.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterRoutes

func RegisterRoutes(api huma.API, store *Store, skills *skill.Store)

RegisterRoutes wires up the read-only quality endpoints.

Types

type Executor

type Executor interface {
	Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
}

Executor is the subset of *pgxpool.Pool that Store's queries need.

type Record

type Record struct {
	SkillID string
	Version int

	Headline       float64
	HeadlineCILow  float64 // legacy; new rows carry zeroes
	HeadlineCIHigh float64

	// Nil means not measured. Lift is reported only; the gate reads Headline.
	PrimaryScore *float64
	Baseline     *float64
	Lift         *float64

	Pillars     json.RawMessage
	PanelMatrix json.RawMessage

	RobustnessGap  *float64 // nil = not computed; zero = floor kept up
	DriftGrade     string
	DriftBreakdown json.RawMessage

	Verified      bool
	PanelComplete bool
	SuiteDerived  bool

	SuiteRef      string
	EngineVersion string
	ModelPanel    json.RawMessage
	Tier          string
	UpliftSource  string
	// JudgeModel is nil for rows written before this field existed. series.go
	// maps nil to a shared "unknown judge" value so those rows still group.
	JudgeModel *string
	JobID      string
	ScoredAt   time.Time

	CriticalForbidViolations int
	ReportJSON               json.RawMessage
}

Record is one scored measurement of a skill version.

func FromReport

func FromReport(r *report.Report) (Record, error)

FromReport maps a report onto a record. Pure: no database or I/O.

func FromReportRaw

func FromReportRaw(r *report.Report, raw json.RawMessage) (Record, error)

FromReportRaw is FromReport plus the raw bytes. The caller passes what it received rather than re-marshalling, because a round trip drops unknown fields.

type RecordOutput

type RecordOutput struct {
	SkillID                  string          `json:"skill_id"`
	Version                  int             `json:"version"`
	Headline                 float64         `json:"headline_score"`
	HeadlineCILow            float64         `json:"headline_ci_low,omitempty"`
	HeadlineCIHigh           float64         `json:"headline_ci_high,omitempty"`
	PrimaryScore             *float64        `json:"primary_score,omitempty"`
	Baseline                 *float64        `json:"baseline,omitempty"`
	Lift                     *float64        `json:"lift,omitempty"`
	Pillars                  json.RawMessage `json:"pillar_breakdown"`
	PanelMatrix              json.RawMessage `json:"panel_matrix"`
	RobustnessGap            *float64        `json:"robustness_gap,omitempty"`
	DriftGrade               string          `json:"drift_grade,omitempty"`
	DriftBreakdown           json.RawMessage `json:"drift_breakdown"`
	Verified                 bool            `json:"verified"`
	PanelComplete            bool            `json:"panel_complete"`
	SuiteDerived             bool            `json:"suite_derived"`
	SuiteRef                 string          `json:"suite_ref"`
	EngineVersion            string          `json:"engine_version"`
	ModelPanel               json.RawMessage `json:"model_panel"`
	Tier                     string          `json:"tier"`
	UpliftSource             string          `json:"uplift_source,omitempty"`
	JudgeModel               *string         `json:"judge_model,omitempty"`
	JobID                    string          `json:"job_id,omitempty"`
	ScoredAt                 time.Time       `json:"scored_at"`
	CriticalForbidViolations int             `json:"critical_forbid_violations"`
	ReportJSON               json.RawMessage `json:"-"`
}

RecordOutput is the wire shape for a Record.

type Series

type Series struct {
	Key     string        `json:"key"`
	Current bool          `json:"current"`
	Reason  string        `json:"reason"`
	Points  []SeriesPoint `json:"points"`
}

Series is a run of scores that may be charted together.

func BuildSeries

func BuildSeries(skillName string, history []Record) []Series

BuildSeries groups a skill's history into comparable runs. History arrives newest-first; the first record's group is the current series.

type SeriesPoint

type SeriesPoint struct {
	Version        int       `json:"version"`
	Headline       float64   `json:"headline_score"`
	HeadlineCILow  float64   `json:"headline_ci_low,omitempty"`
	HeadlineCIHigh float64   `json:"headline_ci_high,omitempty"`
	Lift           *float64  `json:"lift,omitempty"`
	Verified       bool      `json:"verified"`
	ScoredAt       time.Time `json:"scored_at"`
}

SeriesPoint is one scored version on a trend line.

type Store

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

Store persists Records to skill_quality.

func NewStore

func NewStore(db *pgxpool.Pool) *Store

NewStore builds a Store over db.

func (*Store) GetVersion

func (s *Store) GetVersion(ctx context.Context, skillID string, version int) (*Record, error)

GetVersion returns the score for one version, including the full report.

func (*Store) History

func (s *Store) History(ctx context.Context, skillID string) ([]Record, error)

History returns every scored row for a skill, across all versions, newest first.

func (*Store) Latest

func (s *Store) Latest(ctx context.Context, skillID string, version int) (*Record, error)

Latest returns the newest scored row for a skill version. Returns (nil, nil) when the version has never been scored.

func (*Store) LatestAcrossVersions

func (s *Store) LatestAcrossVersions(ctx context.Context, skillID string) (*Record, error)

LatestAcrossVersions returns the newest scored row across all versions.

func (*Store) Upsert

func (s *Store) Upsert(ctx context.Context, rec Record) error

Upsert inserts a new row. History is kept because version-over-version comparison depends on earlier rows surviving a re-score.

func (*Store) WithExecutor

func (s *Store) WithExecutor(e Executor) *Store

WithExecutor returns a Store whose queries run against e instead of the pool.

Jump to

Keyboard shortcuts

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