Documentation
¶
Overview ¶
Package stage defines the classification contract. A pipeline is an ordered cascade of Stages: each record exits at the first stage confident enough to decide it, so cheap stages shield expensive ones.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrUnclassified = errors.New("stage: unclassified")
ErrUnclassified is returned by Classify when the stage cannot decide on a category for the record. The cascade then hands the record to the next stage; a record unclassified by every stage is routed for review.
Functions ¶
func ValidateNames ¶
ValidateNames rejects a cascade whose stages are not individually identifiable: every Name must be non-empty and unique, so stats, logs, and per-stage policy can key on it unambiguously. A nil stage, including a typed-nil pointer, is rejected rather than dereferenced.
func ValidateResult ¶
func ValidateResult(name string, c domain.Classification) error
ValidateResult guards the boundary between a stage and the cascade: a stage that returns no error is promising a well-formed Classification. When it is not (empty category, or confidence outside [0, 1]), it is reported as a stage Error so the cascade fails fast instead of emitting a malformed decision.
Types ¶
type Error ¶
type Error struct {
// Stage is the stage that failed.
Stage string
// Err is the underlying cause.
Err error
}
Error reports that a stage itself broke, as opposed to ErrUnclassified, which just asks the cascade to try the next stage. Stage names the stage that failed and Unwrap gives the cause, so callers can tell which stage failed and why with errors.As and errors.Is.
type Gate ¶
type Gate float64
Gate is a minimum confidence. A decision scoring below it is treated as undecided, so the cascade escalates to the next stage. The zero Gate admits everything, which turns gating off; deterministic stages emit 1, so they always pass.
type Gated ¶
type Gated struct {
// contains filtered or unexported fields
}
Gated wraps a Stage with its own confidence gate: a valid decision that clears the gate is returned unchanged, a valid one below it becomes ErrUnclassified so the cascade escalates. A malformed decision is passed through untouched so the cascade's contract check still rejects it rather than having it masked as an escalation.
type Named ¶
type Named struct {
// contains filtered or unexported fields
}
Named wraps a Stage to report a different name, so one stage type can appear more than once in a cascade under distinct config-declared ids without colliding on the name that stats, logs, and validation key on.
type Stage ¶
type Stage interface {
// Name identifies the stage in classifications, logs, and metrics.
Name() string
// Classify assigns a category to the record, or returns
// ErrUnclassified when this stage cannot decide. It must not mutate
// the record, which a concurrent engine shares with later consumers.
Classify(ctx context.Context, r domain.Record) (domain.Classification, error)
}
Stage classifies records. Implementations range from deterministic rule matching to in-process model inference to remote API calls.
type Static ¶
type Static struct {
// contains filtered or unexported fields
}
Static is a Stage that classifies by exact-match lookup of the record's payload, for tests and wiring examples. Records whose payload is not in the table are unclassified.
func NewStatic ¶
NewStatic returns a Stage named name that maps an exact payload string to a category with full confidence.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package mock implements a stage.Stage that stands in for a model: it emits declared confidences below 1.0 so gates, escalation, and review routing can be exercised end to end before a real model stage exists.
|
Package mock implements a stage.Stage that stands in for a model: it emits declared confidences below 1.0 so gates, escalation, and review routing can be exercised end to end before a real model stage exists. |
|
Package rules implements stage.Stage with deterministic, YAML-defined matching: ordered rules of payload and field matchers mapped to categories.
|
Package rules implements stage.Stage with deterministic, YAML-defined matching: ordered rules of payload and field matchers mapped to categories. |
|
Package schema implements a stage.Stage that validates a structured record's decoded Fields against a declared shape.
|
Package schema implements a stage.Stage that validates a structured record's decoded Fields against a declared shape. |