recover

package
v1.30.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Experimental — this package is not yet wired into the main framework.

Package recover provides an automatic retrain pipeline for models that have degraded in production. It imports the monitor package for drift detection and orchestrates rollback, retraining, validation, and redeployment.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutoRetrain

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

AutoRetrain orchestrates an automated recovery pipeline: detect drift -> rollback -> retrain -> validate -> redeploy.

func NewAutoRetrain

func NewAutoRetrain(cfg AutoRetrainConfig) (*AutoRetrain, error)

NewAutoRetrain creates an AutoRetrain with the given config. RetrainFn is required and must not be nil.

func (*AutoRetrain) Run

func (ar *AutoRetrain) Run(detector monitor.DriftDetector, stream func() (float64, bool)) error

Run feeds values from the stream to the detector. When drift is detected, it executes the full recovery pipeline: rollback -> retrain -> validate -> redeploy. The stream function is called repeatedly to get the next observation value. It should return the value and true to continue, or 0 and false to stop.

func (*AutoRetrain) RunOnDrift

func (ar *AutoRetrain) RunOnDrift() error

RunOnDrift executes the recovery pipeline immediately, without waiting for drift detection. Useful when drift has already been detected externally.

type AutoRetrainConfig

type AutoRetrainConfig struct {
	// RollbackFn rolls back to the last known good model state.
	// Called when drift is detected. May be nil to skip rollback.
	RollbackFn func() error

	// RetrainFn retrains the model. Required.
	RetrainFn func() error

	// ValidateFn validates the retrained model.
	// Should return an error if validation fails. May be nil to skip.
	ValidateFn func() error

	// RedeployFn redeploys the validated model.
	// May be nil to skip.
	RedeployFn func() error
}

AutoRetrainConfig holds callbacks for each stage of the recovery pipeline.

type Phase

type Phase int

Phase represents a stage in the auto-retrain pipeline.

const (
	// PhaseDetect is the drift detection phase.
	PhaseDetect Phase = iota
	// PhaseRollback rolls back to the last known good model.
	PhaseRollback
	// PhaseRetrain retrains the model.
	PhaseRetrain
	// PhaseValidate validates the retrained model.
	PhaseValidate
	// PhaseRedeploy redeploys the validated model.
	PhaseRedeploy
)

func (Phase) String

func (p Phase) String() string

String returns the phase name.

type PipelineError

type PipelineError struct {
	Phase Phase
	Err   error
}

PipelineError wraps an error with the phase in which it occurred.

func (*PipelineError) Error

func (e *PipelineError) Error() string

func (*PipelineError) Unwrap

func (e *PipelineError) Unwrap() error

Jump to

Keyboard shortcuts

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