oxide-agent 0.1.0

Type-safe, high-performance Rust crate for building agentic systems on Ollama
Documentation
//! Batch embedding via a Mojo-compiled binary subprocess.
//!
//! Requires the `mojo-interop` feature:
//!   cargo run --example mojo_embedder --features mojo-interop
//!
//! Protocol — the binary reads one JSON line from stdin and writes one JSON
//! line to stdout:
//!
//!   stdin  → {"texts": ["hello", "world"]}
//!   stdout ← {"embeddings": [[0.1, 0.2, ...], [0.3, 0.4, ...]]}
//!
//! Any non-zero exit code is surfaced as `OxideError::Other`.

use oxide_agent::mojo::MojoEmbedder;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Point this at your compiled Mojo binary.
    let embedder = MojoEmbedder::new("/usr/local/bin/mojo-embed");

    let texts = vec![
        "Rust ownership model".to_string(),
        "Python garbage collection".to_string(),
        "Go goroutines and channels".to_string(),
    ];

    #[cfg(feature = "mojo-interop")]
    {
        let embeddings = embedder.embed_batch(texts).await?;

        println!("Got {} embedding vectors", embeddings.len());
        for (i, emb) in embeddings.iter().enumerate() {
            println!("  [{i}] dim={}, first_val={:.4}", emb.len(), emb[0]);
        }
    }

    // Without the feature, embed_batch returns a descriptive error.
    #[cfg(not(feature = "mojo-interop"))]
    {
        let err = embedder.embed_batch(texts).await.unwrap_err();
        println!("Expected error: {err}");
        println!("Enable with: oxide-agent = {{ features = [\"mojo-interop\"] }}");
    }

    Ok(())
}