baseline_learn_contextual
Learn one conservative baseline band per declared context, so tags with multiple operating regimes (shift, recipe, start-up vs steady state) get context-specific normal ranges instead of one mixed band.
Instructions
[READ][risk=low] Learn one conservative band per declared context, not one per tag.
One band per tag is wrong the moment a tag has more than one normal. A dryer
running recipe A at 180 °C and recipe B at 240 °C gets a band spanning both,
after which neither regime can go wrong — the band is too wide to catch a
real excursion and too mixed to mean anything. OT normal ranges move with
shift, product/recipe, and start-up versus steady state.
**The context is declared, never inferred** (D16). Each sample carries a
label under `context_key`; nothing here guesses which shift a timestamp falls
in or clusters values into regimes it then treats as real. Each context is
handed to the same learner as a global baseline, so it refuses on the same
terms — a thin context is left without a band rather than borrowing another
context's samples. Samples with no label are counted and named, not pooled
into a default bucket, because a default bucket is that same fallback.
Pass samples in (as with `spc_check` / `tag_health`). The local store's
`samples` table has no context column, so there is deliberately no
`iaiops baseline learn --context` yet; wiring one is a schema change and is
not done.
Args:
samples: [{ts, value, quality?, tag?, <context_key>}] rows.
tag: The tag being learned.
context_key: Field that declares the context (default "context").
min_samples: Per-context minimum before a band is learned (default 100).
min_span_s: Per-context minimum history span in seconds (default 86400).
Returns dict: {tag, context_key, contexts:{label: learn_baseline result},
learned_contexts, refused_contexts, uncontexted_samples, note}.
Example: baseline_learn_contextual(samples=[{"ts":"...","value":181.0,
"context":"recipe-A"}], tag="dryer.temp").
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"samples": "<samples>",
"tag": "<tag>"
},
"name": "baseline_learn_contextual"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tag | Yes | ||
| samples | Yes | ||
| min_span_s | No | ||
| context_key | No | context | |
| min_samples | No |