router

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package router implements a per-task logistic entry-tier router. It reads the JSONL ledger, fits a binary logistic regression (pure Go, gradient descent, L2 regularisation) per task, and persists the weights so that the pipeline can call PreferLargerEntry to decide whether to skip the small E2B tier and enter at E4B directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Train

func Train(ledgerPath, labelsPath, outPath string) (string, error)

Train reads the JSONL ledger at ledgerPath, optionally merges a sidecar of synthesized E2B-counterfactual rows at labelsPath (empty string = skip), fits one logistic-regression model per eligible task (triage/classify with >=minRows labelled rows), writes the results to outPath (router-weights.json), and returns a human-readable report.

Types

type Model

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

Model holds per-task logistic-regression weights loaded from disk. A nil *Model is safe to call — PreferLargerEntry returns false (keep default).

func Load

func Load(path string) *Model

Load reads router-weights.json from path. Returns nil if the file is absent or cannot be parsed (caller should treat nil as "no routing preference").

func (*Model) HasTask

func (m *Model) HasTask(task string) bool

HasTask reports whether the model has trained weights for task. A caller can use this to prefer the router and skip a more expensive fallback (e.g. the kNN pre-filter). Returns false for a nil receiver or an unknown task.

func (*Model) PreferLargerEntry

func (m *Model) PreferLargerEntry(task string, feat map[string]float64) bool

PreferLargerEntry returns true when the model predicts that P(accept at E2B) < 0.5 for the given task and feature vector, meaning the caller should skip E2B and enter at E4B. Returns false for unknown tasks or a nil receiver.

Jump to

Keyboard shortcuts

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