Introduction

APR Cookbook provides idiomatic Rust patterns for deploying machine learning models using the APR format. Built on Toyota Way principles, it emphasizes zero-defect quality and production readiness.

What is APR?

APR (Aprender Portable Runtime) is a native Rust ML model format designed for:

  • Zero-copy loading - Models load directly from memory without parsing overhead
  • Compile-time embedding - Use include_bytes!() to bundle models in your binary
  • WASM compatibility - Deploy the same model to browser and server
  • Security - Optional AES-256-GCM encryption with Argon2id key derivation

Why APR Cookbook?

ChallengeSolution
Large model filesQuantization (Q4, Q8) reduces size 4-8x
Slow cold startsZero-copy loading, no deserialization
Model theftAES-256-GCM encryption at rest
Format lock-inConvert from/to SafeTensors, GGUF
Platform limitsWASM-ready, no native dependencies

The Sovereign Stack

APR Cookbook integrates with the Sovereign AI Stack:

┌──────────────────────────────────────────────────┐
│              Your Application                    │
├──────────────────────────────────────────────────┤
│  apr-cookbook    │  Recipes & patterns            │
├─────────────────┼────────────────────────────────┤
│  aprender 0.25  │  ML algorithms, APR v2 format  │
├─────────────────┼────────────────────────────────┤
│  trueno 0.14    │  SIMD/GPU compute              │
├─────────────────┼────────────────────────────────┤
│  entrenar 0.5   │  Training, monitoring & optim  │
└──────────────────────────────────────────────────┘

Quick Example

use apr_cookbook::bundle::{BundledModel, ModelBundle};

// Embed model at compile time
const MODEL: &[u8] = include_bytes!("model.apr");

fn main() -> apr_cookbook::Result<()> {
    // Zero-copy load
    let model = BundledModel::from_bytes(MODEL)?;

    println!("Loaded: {} ({} bytes)", model.name(), model.size());
    Ok(())
}

Toyota Way Principles

This cookbook follows Toyota Way quality principles:

  1. Jidoka - Build quality in, don't inspect it in
  2. Genchi Genbutsu - Go see for yourself
  3. Kaizen - Continuous improvement
  4. Muda elimination - Remove waste (unnecessary copies, allocations)

Every recipe includes tests, benchmarks, and quality metrics.

Next Steps