Skip to content

vox-constrained-gen API Reference (generated)

Crate: vox-constrained-gen · Version: 0.6.0 · Target: Library (lib.rs)

Grammar-constrained inference engine for Vox — Earley/PDA backends, deadlock watchdog, and stream-of-revision.

Grammar-constrained inference engine for Vox.

Provides a [ConstrainedSampler] trait with two backends:

  • [earley::EarleySampler] — Earley parser consuming the EBNF grammar export
  • [pda::PdaSampler] — Pushdown automaton with context-independent token caching

Both are wrapped by:

  • [deadlock::DeadlockWatchdog] — configurable timeout; produces VoxValidationError on deadlock
  • [revision::RevisionSampler] — injects a backtrack token for mid-generation self-correction

Research rationale: Grammar Constraints §4.4 proves deadlocks are systemic, not edge-case. XGrammar-2/llguidance PDA backends achieve <40µs/token with native recursion support.

DependencyKind
vox-grammar-exportNormal
ModuleDescription
deadlock—
earley—
pda—
revision—
Dependency Topology, diagram 14 nodes, 3 edges: vox-constrained-gen → vox-grammar-export; vox-cli → vox-constrained-gen; vox-ml-cli → vox-constrained-genvox-constrained-genvox-grammar-exportvox-clivox-ml-cli
Diagram source
graph {
direction: right
node vox_constrained_gen: "vox-constrained-gen"
node vox_grammar_export: "vox-grammar-export"
vox_constrained_gen -> vox_grammar_export
node vox_cli: "vox-cli"
vox_cli -> vox_constrained_gen
node vox_ml_cli: "vox-ml-cli"
vox_ml_cli -> vox_constrained_gen
}
Consumer CrateRole
vox-cliDirect workspace dependent
vox-ml-cliDirect workspace dependent
KindSymbolSignatureSourceDescription
structdeadlock::WatchdogConfigpub struct WatchdogConfigcrates/vox-constrained-gen/src/deadlock.rs#L20-L27Watchdog configuration.
structdeadlock::DeadlockWatchdogpub struct DeadlockWatchdog<S: ConstrainedSampler>crates/vox-constrained-gen/src/deadlock.rs#L40-L43Wraps a [ConstrainedSampler] with timeout enforcement.
fndeadlock::newpub fn new(inner: S, config: WatchdogConfig) -> Selfcrates/vox-constrained-gen/src/deadlock.rs#L46-L48—
fndeadlock::mask_logits_with_retrypub fn mask_logits_with_retry(crates/vox-constrained-gen/src/deadlock.rs#L114Execute mask_logits with automatic retry on deadlock/timeout. On each failure the function waits config.backoff_base_ms * 2^attempt ms (capped at config.max_retries). If all retries are exhausted, the last error is returned.
structearley::EarleyStatepub struct EarleyStatecrates/vox-constrained-gen/src/earley.rs#L42-L49Incremental Earley chart state persisted between generation steps.
structearley::EarleySamplerpub struct EarleySamplercrates/vox-constrained-gen/src/earley.rs#L177-L179Earley parser-backed constrained sampler.
fnearley::from_ebnfpub fn from_ebnf(ebnf: &str) -> Result<Self>crates/vox-constrained-gen/src/earley.rs#L183-L192Build from an explicit EBNF string.
fnearley::from_vox_grammarpub fn from_vox_grammar() -> Result<Self>crates/vox-constrained-gen/src/earley.rs#L195-L198Build from the canonical Vox EBNF via vox-grammar-export.
structpda::PdaStatepub struct PdaStatecrates/vox-constrained-gen/src/pda.rs#L22-L30Stack-based PDA state persisted between generation steps.
structpda::PdaSamplerpub struct PdaSamplercrates/vox-constrained-gen/src/pda.rs#L219-L222PDA-backed constrained sampler with context-independent token caching.
fnpda::from_ebnfpub fn from_ebnf(ebnf: &str) -> Result<Self>crates/vox-constrained-gen/src/pda.rs#L226-L238Build from an explicit EBNF string.
fnpda::from_vox_grammarpub fn from_vox_grammar() -> Result<Self>crates/vox-constrained-gen/src/pda.rs#L241-L244Build from the canonical Vox EBNF.
structrevision::RevisionConfigpub struct RevisionConfigcrates/vox-constrained-gen/src/revision.rs#L23-L26Configuration for the revision sampler.
structrevision::RevisionSamplerpub struct RevisionSampler<S: ConstrainedSampler>crates/vox-constrained-gen/src/revision.rs#L37-L40Wraps a [ConstrainedSampler] with backtrack support.
fnrevision::newpub fn new(inner: S) -> Selfcrates/vox-constrained-gen/src/revision.rs#L43-L48—
fnrevision::with_configpub fn with_config(inner: S, config: RevisionConfig) -> Selfcrates/vox-constrained-gen/src/revision.rs#L50-L55—
fnrevision::is_backtrack_tokenpub fn is_backtrack_token(token_strings: &[String], chosen_idx: usize) -> boolcrates/vox-constrained-gen/src/revision.rs#L122-L127Check whether a chosen token index corresponds to the backtrack sentinel.