pub struct Engine { /* private fields */ }Expand description
A compiled decision engine. train needs &mut, hence the RwLock; the
Arc lets the async path hand a clone to the libuv thread pool.
Implementations§
Source§impl Engine
impl Engine
pub fn into_reference(val: Engine, env: Env) -> Result<Reference<Engine>>
pub fn into_instance(self, env: Env) -> Result<ClassInstance<Engine>>
Source§impl Engine
impl Engine
Sourcepub fn new(options_json: String) -> Result<Self>
pub fn new(options_json: String) -> Result<Self>
optionsJson: {"embedder":"hash","dims":256} or
{"embedder":{"kind":"onnx","modelDir":"...","manifest":"..."}} (onnx
requires the native-onnx build feature). Throws on malformed options
JSON, an unsupported embedder, or an onnx model that fails to load.
Sourcepub fn decide_json(&self, request_json: String) -> String
pub fn decide_json(&self, request_json: String) -> String
Synchronous decide. Returns a DecisionResponse JSON, or the documented
error JSON — never throws for a request-level failure.
Sourcepub fn decide(&self, request_json: String) -> AsyncTask<DecideTask>
pub fn decide(&self, request_json: String) -> AsyncTask<DecideTask>
Asynchronous decide, implemented as a napi AsyncTask so the CPU work
runs off the JS thread (ADR-002 §4). Resolves to the same JSON string
decideJson returns.
Sourcepub fn train_json(&self, train_json: String) -> String
pub fn train_json(&self, train_json: String) -> String
Admit labeled examples for one question. Returns a TrainReport JSON or
the documented error JSON.
Sourcepub fn stats_json(&self) -> String
pub fn stats_json(&self) -> String
Introspection: {"embedderId","dims","examples","promotable"}. The
example counts come from the bank’s redacted summary (no text).
Sourcepub fn optimize_json(&self, campaign_json: String) -> String
pub fn optimize_json(&self, campaign_json: String) -> String
Run an optimize campaign (ADR-004). campaignJson is a CampaignSpec;
returns a CampaignReport JSON, or the documented error JSON. The model
arm is chosen by constructing one engine per embedder — this campaign is
over EngineOptions for the engine’s fixed embedder.
Sourcepub fn export_bank_json(&self) -> String
pub fn export_bank_json(&self) -> String
Full-fidelity bank JSON (the user’s own examples) for typesafe train --bank bank.json, or the documented error JSON.
Sourcepub fn import_bank_json(&self, bank_json: String) -> String
pub fn import_bank_json(&self, bank_json: String) -> String
Replace the bank from JSON (re-embeds every stored text). Returns
{"ok":true} or the documented error JSON.