Repository navigation
Commit 37e366b
feat: fit()/predict() + backtest() aggregate for an agent-guessable API (#20)
* feat: fit()/predict()/backtest() SQL surface + hardened training core
Reshape the tabular and evaluation surface into the scikit-learn shape agents
guess, and extract and harden the native-student training core that backs it.
Surface:
- fit(f1, ..., fN, label [, options]) is an aggregate over the caller's rows and
returns a registered model id or a serialized blob; predict(model, f1, ..., fN
[, options]) is a scalar serving one prediction per row (deserialized once,
cached on the model argument). The label is the last positional argument; the
optional trailing '{...}' is always the options object.
- backtest(ts, value, horizon [, options]) is an aggregate (matching forecast /
detect_anomalies) that runs rolling-origin evaluation and returns one JSON
document; backtest_rows() expands it into typed rows. The old TVF is renamed
predict_batch.
- The tabular training core (tree / gradient-boosted / MLP fitters) moves to
predict-train.{c,h}, shared by fit() and the distill recipes.
Correctness and safety hardening (a thorough review pass, fixed at the root and
swept across every sibling, not only where first flagged):
- Memory safety: a compile-time assert that predict()'s feature buffer holds any
student the loader admits; re-fetch after sqlite3_set_auxdata to avoid a
use-after-free; propagate OOM through the row-cursor mprintf paths instead of
silent NULL columns; 64-bit sizing for model-scaled allocations; bounded,
overflow-safe onnx io_spec arrays (a 32-bit-wasm overflow); a fit() training-set
cap.
- Determinism: total-order split comparators so the tree, and its content_hash,
are identical across platforms/libc (no reads of uninitialized task-union
fields).
- Fail loud, never silently: reject non-finite features/labels/teacher cells and
NULL labels; surface malformed-JSON parse errors, prepare failures, and
mid-read step errors; preserve distinct error codes; cap the classifier
vocabulary at PREDICT0_MAX_CLASS during interning and parsing; require a
positive json-array cap rather than a silent-unbounded footgun.
- The receipt tool's operation taxonomy is restructured (aggregate vs row-shaped,
with the *_rows TVFs first-class and wrapper-aware inference).
Tests: adversarial coverage for the new surface and every hardening path
(malformed/oversized/boundary/non-finite inputs asserting concrete PREDICT_ERR_*
codes); the corrupt-blob tests now supply a matching content hash so they reach
the bounds-checked deserializer; the C soak drivers assert row counts and the
specific error code per branch, and propagate statement failures to the exit
code.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* docs: fit/predict/backtest reference, skills, and receipts
Document the new surface for a first-time reader: the functions reference
(fit/predict/backtest, predict_batch's optional train_query and required
apply_query, the JSON-object-label convention), the models and options pages, the
sqlite-predict / distill-lifecycle / interpret-backtest skills, README, and the
CHANGELOG. Scope the read-only guarantee to the serving functions (registration
writes to _predict_models).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>1 parent d924067 commit 37e366b
37 files changed
Lines changed: 3563 additions & 1947 deletions
File tree
- scripts
- skills
- distill-lifecycle
- interpret-backtest
- prediction-receipts/scripts
- sqlite-predict
- tests
- website/src/content/docs
- guides
- reference
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
9 | 27 | | |
10 | 28 | | |
11 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
113 | | - | |
| 112 | + | |
114 | 113 | | |
115 | 114 | | |
116 | 115 | | |
| |||
159 | 158 | | |
160 | 159 | | |
161 | 160 | | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
174 | 176 | | |
175 | 177 | | |
176 | 178 | | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
181 | 187 | | |
182 | 188 | | |
183 | 189 | | |
| |||
200 | 206 | | |
201 | 207 | | |
202 | 208 | | |
203 | | - | |
204 | | - | |
| 209 | + | |
| 210 | + | |
205 | 211 | | |
206 | 212 | | |
207 | 213 | | |
| |||
219 | 225 | | |
220 | 226 | | |
221 | 227 | | |
222 | | - | |
| 228 | + | |
223 | 229 | | |
224 | 230 | | |
225 | 231 | | |
| |||
298 | 304 | | |
299 | 305 | | |
300 | 306 | | |
301 | | - | |
302 | | - | |
| 307 | + | |
| 308 | + | |
303 | 309 | | |
304 | 310 | | |
305 | 311 | | |
| |||
384 | 390 | | |
385 | 391 | | |
386 | 392 | | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
391 | 399 | | |
392 | 400 | | |
393 | 401 | | |
| |||
0 commit comments