What You'll Learn
- Setting up Edge Hive on your device
- Running local AI inference
- Configuring cloud fallback
- Managing encrypted local storage
Prerequisites
Complete Tutorial 5: Building a CHAI Hive first.
Step 1: Initialize Edge Hive
Edge Hive automatically detects your device capabilities and selects an appropriate model:
use edge_hive::{EdgeHive, LocalModel};
async fn main() {
// Auto-detect device and select best model
let hive = EdgeHive::new()
.with_model(LocalModel::auto())
.build().await?;
println("Device: {}", hive.device_class); // e.g., "Laptop"
println("Model: {}", hive.model_name); // e.g., "SmolLM-1.7B"
println("Memory: {} MB", hive.model_memory); // e.g., "1200"
}
Step 2: Process Requests Locally
Send requests to Edge Hive. It processes locally when confident, or falls back to cloud:
async fn main() {
let hive = EdgeHive::new()
.with_model(LocalModel::auto())
.with_fallback("wss://hive.example.com")
.with_confidence_threshold(0.7)
.build().await?;
// Simple request - likely handled locally
let response = hive.process("What time is it?").await?;
if response.processed_locally {
println("Handled by: {} (local)", response.specialist);
println("Latency: {}ms", response.latency_ms);
} else {
println("Escalated to cloud (confidence: {})", response.confidence);
}
println("Response: {}", response.text);
}
Confidence-Based Routing
If the local specialist's confidence is below the threshold (0.7 by default), Edge Hive automatically routes to the cloud for a higher-quality response.
Step 3: User Authentication
Authenticate users to enable encrypted personal storage:
async fn main() {
let hive = EdgeHive::new().build().await?;
// Authenticate - derives encryption key from password
let user = hive.authenticate(
"user@example.com",
get_password() // Password never stored
).await?;
println("Authenticated as: {}", user.email);
// Now beliefs and cache are encrypted with user's key
hive.remember("preference", "dark_mode").await?;
}
Step 4: Working with Specialists
Edge Hive includes built-in specialists for common tasks:
use edge_hive::{EdgeHive, Specialist};
async fn main() {
let hive = EdgeHive::new().build().await?;
// Route to specific specialist
let calendar = hive.specialist(Specialist::Calendar);
let events = calendar.query("What's on my schedule today?").await?;
// Context specialist uses time/location awareness
let context = hive.specialist(Specialist::Context);
let suggestion = context.query("Should I take an umbrella?").await?;
// Task specialist manages todos
let task = hive.specialist(Specialist::Task);
task.add("Buy groceries", priority: 2).await?;
}
Step 5: Offline Mode
Edge Hive works fully offline when no network is available:
use edge_hive::{EdgeHive, OfflineMode};
async fn main() {
let hive = EdgeHive::new()
.offline_mode(OfflineMode::Full) // Never use cloud
.build().await?;
// All processing happens locally
let response = hive.process("Summarize my notes").await?;
// Check network status
if !hive.is_online() {
println("Working offline - some features limited");
}
}
Exercise
Build a personal assistant that tracks your daily habits locally, never sending data to the cloud. Use the Task and Context specialists.
What's Next?
In Tutorial 15: Self-Learning Optimization, you'll learn to build systems where hyperparameters optimize themselves.