Configuration
Define the classification contract, dataset policy and storage without coupling it to a training host.
const relevance = createClassifier({
name: "accountant-relevance",
result: { type: "number", min: 0, max: 1 },
reference: classifyWithGrok,
training: runpodTrainer({
apiKey: process.env.RUNPOD_API_KEY!,
maximumCostUsd: 1,
maximumRuntimeMinutes: 30,
sshPrivateKey: "/run/secrets/runpod-ssh-key",
registerSshPublicKeyForTraining: true,
}),
decisionBoundaries: [0.5],
facets: ["documentFamily"],
acceptableError: "10%",
maxTrainingSet: 10_000,
dataDirectory: "/var/lib/my-service/swapai",
onBackgroundError: reportError,
});Classification contract
name is a stable, non-empty task identity. result declares its only valid output shape. reference is the authoritative function used while no promoted model is available and when a fallback is required.
Dataset policy
decisionBoundaries identifies numeric thresholds that change product behavior. facets names product slices whose collected distribution must remain visible to operators. datasetRequirements can override the default result-bin and protected-set minimums described in Data policy.
maxTrainingSet limits retained trainable data. Retention preserves result-bin distribution; it is not a newest-global-rows truncation.
Candidate acceptance
acceptableError accepts a decimal or percentage string:
acceptableError: 0.1
acceptableError: "10%"It is the maximum aggregate protected-test error. Per-bin evaluation and declared-facet collection coverage are retained for operator review.
Training provider
training is optional during collection. Supply localTrainer(), runpodTrainer(options), or your own TrainingProvider before calling requestTraining().
Provider credentials, hardware and cost limits belong to the provider. They do not change the classifier's persisted task contract.
Storage
dataDirectory defaults to .swapai under the working directory. Production must use a persistent path with SQLite-compatible locking.
Failure reporting
onBackgroundError receives queued collection and runtime failures. Operator actions such as requestTraining() and promoteCandidate() reject directly, so callers must also handle those errors.