engine

package
v0.0.0-...-dfadc02 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package engine runs the classification cascade: records flow from a Source through an ordered list of Stages into a Sink. Each record exits at the first stage that can decide it, so cheap stages shield expensive ones. Records no stage can classify are routed to an optional review sink.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deps

type Deps struct {
	// Source yields the records to classify. Required.
	Source source.Source
	// Stages is the cascade, cheapest first. At least one is required.
	Stages []stage.Stage
	// Sink receives every classified record. Required.
	Sink sink.Sink
	// Review receives records no stage could classify, with a zero
	// Classification. Optional; when nil such records are dropped.
	Review sink.Sink
	// Logger defaults to slog.Default.
	Logger *slog.Logger
	// MinConfidence is the gate: a stage's classification below this
	// threshold is treated as undecided and the record escalates to the
	// next stage. Zero disables gating. Deterministic stages emit 1, so
	// they always pass.
	MinConfidence float64
	// Workers is how many goroutines classify at once. Zero or one keeps
	// the serial loop. More requires stages safe for concurrent Classify,
	// and the engine closes the Source when a failure ends the run early.
	// Order, errors, and Stats match the serial loop exactly.
	Workers int
}

Deps bundles everything an Engine needs.

type Engine

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

Engine drives records through the cascade.

func New

func New(d Deps) (*Engine, error)

New validates deps and returns a ready Engine.

func (*Engine) Run

func (e *Engine) Run(ctx context.Context) (Stats, error)

Run drains the source through the cascade. It returns when the source is drained, the context is cancelled, or a source, stage, or sink fails. Stats reflect everything processed up to the point of return.

type Stats

type Stats struct {
	// Processed counts records read from the source.
	Processed int
	// Classified counts records some stage decided.
	Classified int
	// Reviewed counts records no stage decided, whether routed to the
	// review sink or dropped.
	Reviewed int
	// ByStage counts classifications per stage name.
	ByStage map[string]int
}

Stats summarizes one Run.

Jump to

Keyboard shortcuts

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