[Draft] Add AI Capabilities to SpacetimeDB#4589
[Draft] Add AI Capabilities to SpacetimeDB#4589definenoob wants to merge 6 commits intoclockworklabs:masterfrom
Conversation
|
@definenoob have you tested this? |
|
@cloutiertyler Not yet, I was wondering if you thought it would be worth pursuing before diving too much deeper. Training a neural network to do something interesting in a whole game isn't exactly light work! |
Testing the ONNX featureUnit testsThe host-side inference logic has unit tests that run without any external dependencies — models are built programmatically using tract_onnx::pb protobuf types: cargo test -p spacetimedb-core --features onnx -- onnx::tests This covers: model loading from bytes, loading from filesystem, Add/Relu inference, run_multi batching, invalid model handling, shape mismatch errors, and path traversal rejection. Integration tests (smoketests)End-to-end tests verify the full WASM module → FFI → host path. The server must be built with the onnx feature:
The smoketests compile a WASM module with onnx bindings at runtime, place a test .onnx model file in the server's data directory, then call reducers that invoke ctx.onnx.run() and ctx.onnx.run_multi() and verify the inference results in the What's tested across the two levels
|
With this PR, STDB becomes the first AI-enabled database. Seeking feedback from CWL on this.
Summary
tensor data crosses the boundary
Design
Single ABI call (spacetime_10.5):
Crate changes:
from HostController.data_dir
Usage from a module:
let input = vec![Tensor { shape: vec![1, 10], data: vec![0.0; 10] }];
let output = ctx.onnx.run("bot_brain", &input)?;
Test plan
The onnx feature flag works across all three crates:
Without the feature, tract-onnx isn't compiled, no ONNX code exists in the binary, and the ABI function isn't registered.
This is ACID-compliant AI inference.
run the model inside the reducer to decide what to write. The inference result feeds directly into the transactional state change — no round-trip to an external service, no eventual consistency, just one atomic unit of "think and act."