evaluation

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: Apache-2.0 Imports: 23 Imported by: ? 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 evaluation provides provider-free routing regressions and an opt-in, provider-backed capability evaluator for agentic-moe plans. Live model calls never run as part of the offline test suite.

Index

Constants

View Source
const (
	CheckContainsAll CheckKind = "contains_all"
	CheckContainsAny CheckKind = "contains_any"
	CheckExcludesAll CheckKind = "excludes_all"
	CheckExact       CheckKind = "exact"
	CheckRegexp      CheckKind = "regexp"
	CheckJSONKeys    CheckKind = "json_keys"
	CheckMaxWords    CheckKind = "max_words"
	CheckQuestion    CheckKind = "question"

	FailureFactual     FailureClass = "factual"
	FailureFormat      FailureClass = "format"
	FailureInstruction FailureClass = "instruction"
	FailureSafety      FailureClass = "safety"
)
View Source
const ReportVersion = 3

ReportVersion is the machine-readable evaluation report schema version.

Variables

This section is empty.

Functions

func WriteJSON

func WriteJSON(w io.Writer, report Report) error

WriteJSON emits one indented report without additional prose.

func WriteJSONFile

func WriteJSONFile(path string, report Report) error

WriteJSONFile writes a private report atomically and refuses to replace an existing path. This prevents report paths from being used as symlink targets.

func WriteText

func WriteText(w io.Writer, report Report) error

WriteText renders a concise scorecard suitable for a terminal or CI log.

Types

type AssertionResult

type AssertionResult struct {
	Name     string       `json:"name"`
	Kind     string       `json:"kind"`
	Category FailureClass `json:"category"`
	Passed   bool         `json:"passed"`
	Detail   string       `json:"detail,omitempty"`
}

AssertionResult records one deterministic answer check.

type Case

type Case struct {
	ID             string                  `json:"id"`
	Domain         string                  `json:"domain"`
	Prompt         string                  `json:"-"`
	Routing        runtimekit.RoutingInput `json:"-"`
	ExpectedExpert string                  `json:"expected_expert,omitempty"`
	Checks         []Check                 `json:"-"`
	MaxTokens      int                     `json:"-"`
	OutputContract OutputContract          `json:"-"`
}

Case is one immutable capability probe. Prompts are intentionally omitted from reports so evaluation artifacts cannot become a prompt-data channel.

func BuiltInCases

func BuiltInCases() []Case

BuiltInCases returns the frozen, provider-neutral capability suite. The prompts favor objectively checkable outputs over subjective model judging.

func FilterCases

func FilterCases(cases []Case, domains []string) ([]Case, error)

FilterCases selects domains case-insensitively. An empty filter selects all.

type Check

type Check struct {
	Name     string       `json:"name"`
	Kind     CheckKind    `json:"kind"`
	Category FailureClass `json:"category"`
	Values   []string     `json:"values,omitempty"`
	Pattern  string       `json:"pattern,omitempty"`
}

Check is a deterministic rule applied to a model response.

type CheckKind

type CheckKind string

CheckKind identifies one deterministic answer assertion.

type FailureClass

type FailureClass string

FailureClass separates response-shape failures from content and safety failures without changing the strict assertion result.

type GenerateRequest

type GenerateRequest struct {
	Model          string
	System         string
	Prompt         string
	Seed           int
	MaxTokens      int
	ContextWindow  int
	OutputContract OutputContract
}

GenerateRequest is a bounded, host-owned model call.

type GenerateResponse

type GenerateResponse struct {
	Text             string
	PromptTokens     int
	CompletionTokens int
	TotalDuration    time.Duration
}

GenerateResponse contains only fields needed for scoring and telemetry.

type Generator

type Generator interface {
	Generate(context.Context, GenerateRequest) (GenerateResponse, error)
}

Generator invokes a model provider. Implementations must honor context cancellation and must not log request or response bodies.

type Mode

type Mode string

Mode identifies the prompt strategy used for one trial.

const (
	ModeBaseline Mode = "baseline"
	ModeMOE      Mode = "moe"
)

type OllamaClient

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

OllamaClient implements Generator through Ollama's non-streaming chat API.

func NewOllamaClient

func NewOllamaClient(cfg OllamaConfig) (*OllamaClient, error)

NewOllamaClient constructs a bounded client. Remote endpoints and redirects are denied by default so an evaluation cannot silently cross trust domains.

func (*OllamaClient) Generate

func (c *OllamaClient) Generate(ctx context.Context, request GenerateRequest) (GenerateResponse, error)

Generate performs one non-streaming, deterministic-temperature chat call.

func (*OllamaClient) Preflight

func (c *OllamaClient) Preflight(ctx context.Context, model string) error

Preflight verifies that Ollama can resolve the model manifest before a suite spends many trials rediscovering a stale or incomplete local installation.

type OllamaConfig

type OllamaConfig struct {
	BaseURL      string
	AllowRemote  bool
	Timeout      time.Duration
	MaxBodyBytes int64
	HTTPClient   *http.Client
}

OllamaConfig bounds the opt-in model calls made by the evaluator.

type Options

type Options struct {
	Model             string
	Modes             []Mode
	Repeats           int
	Concurrency       int
	Timeout           time.Duration
	Seed              int
	MaxTokens         int
	ContextWindow     int
	MinAnswerScore    float64
	MinRoutingScore   float64
	PreviewRunes      int
	FrameworkRevision string
	Now               func() time.Time
}

Options controls one evaluation run.

type OutputContract

type OutputContract struct {
	Kind   OutputContractKind `json:"kind"`
	Schema json.RawMessage    `json:"schema,omitempty"`
}

OutputContract is a bounded, provider-neutral response constraint. The zero value requests ordinary text generation.

func NewJSONSchemaContract

func NewJSONSchemaContract(schema []byte) (OutputContract, error)

NewJSONSchemaContract validates and copies an object-shaped JSON Schema.

func (OutputContract) Validate

func (c OutputContract) Validate() error

Validate rejects ambiguous, oversized, or non-object response contracts.

func (OutputContract) ValidateOutput

func (c OutputContract) ValidateOutput(output string) error

ValidateOutput performs strict local validation for the JSON Schema subset used by evaluator contracts. Provider constraints improve generation, but local validation remains authoritative when a provider violates a schema.

type OutputContractKind

type OutputContractKind string

OutputContractKind identifies a provider-neutral response constraint.

const (
	// OutputJSONSchema requires one JSON object matching Schema.
	OutputJSONSchema OutputContractKind = "json_schema"
)

type Planner

type Planner interface {
	Plan(context.Context, string, runtimekit.RoutingInput) (runtimekit.PlanView, error)
}

Planner is the narrow runtimekit surface used by the evaluator.

type ProbeResult

type ProbeResult struct {
	Name   string `json:"name"`
	Passed bool   `json:"passed"`
	Detail string `json:"detail"`
}

ProbeResult records evaluator-level safety and lifecycle checks.

type Report

type Report struct {
	SchemaVersion     int                  `json:"schema_version"`
	StartedAt         time.Time            `json:"started_at"`
	FinishedAt        time.Time            `json:"finished_at"`
	FrameworkRevision string               `json:"framework_revision,omitempty"`
	Model             string               `json:"model"`
	Seed              int                  `json:"seed"`
	Repeats           int                  `json:"repeats"`
	Concurrency       int                  `json:"concurrency"`
	PeakConcurrency   int                  `json:"peak_concurrency"`
	TimeoutMS         int64                `json:"timeout_ms"`
	ContextWindow     int                  `json:"context_window"`
	CaseCount         int                  `json:"case_count"`
	TrialCount        int                  `json:"trial_count"`
	Passed            bool                 `json:"passed"`
	MinAnswerScore    float64              `json:"min_answer_score"`
	MinRoutingScore   float64              `json:"min_routing_score"`
	Modes             []Summary            `json:"modes"`
	Domains           []Summary            `json:"domains"`
	Probes            []ProbeResult        `json:"probes"`
	Results           []TrialResult        `json:"results"`
	Failures          map[FailureClass]int `json:"failures,omitempty"`
	Limitations       []string             `json:"limitations"`
}

Report is the stable, machine-readable result of one run.

type RoutingCase

type RoutingCase struct {
	ID             string
	Split          RoutingSplit
	Query          string
	Routing        runtimekit.RoutingInput
	ExpectedExpert string
}

RoutingCase is a provider-free router regression.

func RoutingCases

func RoutingCases() []RoutingCase

RoutingCases returns the frozen development and holdout corpus. It is kept separate from BuiltInCases because it measures deterministic planner routing without spending model tokens.

type RoutingSplit

type RoutingSplit string

RoutingSplit separates cases used while tuning from cases that guard against overfitting. Holdout expectations must not be changed to make an implementation pass.

const (
	RoutingDevelopment RoutingSplit = "development"
	RoutingHoldout     RoutingSplit = "holdout"
)

type Runner

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

Runner executes frozen cases against a planner and a host-owned generator.

func NewRunner

func NewRunner(planner Planner, generator Generator, options Options) (*Runner, error)

NewRunner validates and freezes evaluator dependencies.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, cases []Case) (Report, error)

Run executes every selected case and returns a report even when individual provider calls fail. A canceled parent context returns the partial report.

type Summary

type Summary struct {
	Name             string  `json:"name"`
	Mode             Mode    `json:"mode,omitempty"`
	Domain           string  `json:"domain,omitempty"`
	Trials           int     `json:"trials"`
	Passed           int     `json:"passed"`
	PassRate         float64 `json:"pass_rate"`
	AnswerScore      float64 `json:"answer_score"`
	RoutingScore     float64 `json:"routing_score,omitempty"`
	RoutingTrials    int     `json:"routing_trials,omitempty"`
	MeanLatencyMS    int64   `json:"mean_latency_ms"`
	PromptTokens     int     `json:"prompt_tokens,omitempty"`
	CompletionTokens int     `json:"completion_tokens,omitempty"`
}

Summary aggregates a mode or domain without hiding sample count.

type TrialResult

type TrialResult struct {
	CaseID            string             `json:"case_id"`
	Domain            string             `json:"domain"`
	Mode              Mode               `json:"mode"`
	Repeat            int                `json:"repeat"`
	Model             string             `json:"model"`
	SelectedExpert    string             `json:"selected_expert,omitempty"`
	ExpectedExpert    string             `json:"expected_expert,omitempty"`
	ToolNames         []string           `json:"tool_names,omitempty"`
	Tier              string             `json:"tier,omitempty"`
	AnswerScore       float64            `json:"answer_score"`
	RoutingScore      float64            `json:"routing_score,omitempty"`
	RoutingApplicable bool               `json:"routing_applicable"`
	Passed            bool               `json:"passed"`
	Assertions        []AssertionResult  `json:"assertions"`
	LatencyMS         int64              `json:"latency_ms"`
	PromptTokens      int                `json:"prompt_tokens,omitempty"`
	CompletionTokens  int                `json:"completion_tokens,omitempty"`
	OutputSHA256      string             `json:"output_sha256,omitempty"`
	OutputPreview     string             `json:"output_preview,omitempty"`
	ErrorClass        string             `json:"error_class,omitempty"`
	Error             string             `json:"error,omitempty"`
	FailureClasses    []FailureClass     `json:"failure_classes,omitempty"`
	OutputContract    OutputContractKind `json:"output_contract,omitempty"`
}

TrialResult is one case/mode/repeat outcome. It contains a bounded redacted preview and digest, never the prompt or an unbounded raw response.

Jump to

Keyboard shortcuts

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