Skip to main content

Crate laya

Crate laya 

Source
Expand description

§laya

Pure-Rust port of the Laya non-autoregressive System-1 decision engine (the Laya-Decision project).

Given a state (text, JSON, or a conversation list) and a set of typed questions (choice, score, noul), Laya scores every question in a single forward pass — no text generation. Inference runs natively on candle; the routing, language-detection, email-cleaning, preset and shortlist logic is dependency-free.

The pure-logic modules build without the model feature; enabling it (on by default) pulls in candle + the Hugging Face tokenizer and Hub download.

Re-exports§

pub use error::LayaError;
pub use error::Result;
pub use common::QType;
pub use common::TEMP_MAX;
pub use common::TEMP_MIN;
pub use email::clean_email_body;
pub use email::email_state;
pub use lang::analyse;
pub use lang::detect_script;
pub use lang::is_english;
pub use presets::email_questions;
pub use presets::guard_questions;
pub use presets::moderation_questions;
pub use presets::router_questions;
pub use presets::triage_questions;
pub use router::RouteDecision;
pub use router::RouteHints;
pub use router::Router;
pub use router::RouterOptions;
pub use agent::Agent;
pub use agent::SystemOneResult;
pub use shortlist::embed_fn_from_agent;
pub use shortlist::predict_shortlist;
pub use shortlist::shortlist_choice;

Modules§

agent
High-level inference runtime. Ported from laya/agent.py (load, validate/normalize questions, tokenize, forward, decode typed answers) — minus the TileLang fast path.
common
Core model-independent logic: state serialization (Python json.dumps parity), option rendering, token-sequence construction, collation, and calibration helpers.
email
Email utilities for cleaning and structuring email inputs in laya.
error
lang
Dependency-free language/script detection used to route between Laya checkpoints.
model
Native candle implementation of the Laya DecisionModel: a ModernBERT/mmBERT encoder (from candle-transformers) plus the decision head (type_emb + 2-layer pre-norm transformer + scorer + act_head). Ported from DecisionModel in laya/common.py and the _HeadOnly export in laya-ts/scripts/export_onnx.py.
presets
Ready-to-use question presets for common decision workflows. Ported from laya/presets.py.
router
Route a request to the Laya checkpoint best suited to it. Ported from laya/router.py.
shortlist
Opt-in embedding shortlist for high-cardinality choice questions. Ported from laya/shortlist.py. The ranking core (shortlist_choice, predict_shortlist) takes a caller-supplied embedding function embed_fn: Fn(&[String]) -> Vec<Vec<f64>>; embed_fn_from_agent builds one from a loaded checkpoint’s encoder.
tokenizer
Checkpoint tokenizer: a thin wrapper over the Hugging Face tokenizers crate that loads tokenizer.json directly and resolves Laya’s special token ids. Mirrors the special-id resolution in laya-ts/src/tokenizer.ts.

Constants§

UPSTREAM_VERSION
Crate version, mirroring the upstream Laya release this port tracks.

Type Aliases§

Questions
An ordered map of question id → question definition. Order is significant (it determines choice-label and probability ordering), so this is an IndexMap.
State
A state to evaluate: a string, a JSON object, or a conversation list — represented as a serde_json::Value. A bare string is Value::String.