use ruvector_tiny_dancer_core::{Candidate, Router, RouterConfig, RoutingRequest};
use std::collections::HashMap;
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("=== Tiny Dancer Admin Example ===\n");
let router_config = RouterConfig {
model_path: "./models/fastgrnn.safetensors".to_string(),
confidence_threshold: 0.85,
max_uncertainty: 0.15,
enable_circuit_breaker: true,
circuit_breaker_threshold: 5,
enable_quantization: true,
database_path: None,
};
println!("Creating router with config:");
println!(" Model path: {}", router_config.model_path);
println!(
" Confidence threshold: {}",
router_config.confidence_threshold
);
println!(" Max uncertainty: {}", router_config.max_uncertainty);
println!(
" Circuit breaker: {}",
router_config.enable_circuit_breaker
);
let router = Router::new(router_config.clone())?;
println!("\n--- Health Check ---");
let health = check_health(&router);
println!("Status: {}", if health { "healthy" } else { "unhealthy" });
println!("\n--- Readiness Check ---");
let ready = check_readiness(&router);
println!("Ready: {}", ready);
println!("\n--- Configuration ---");
let config = router.config();
println!("Current configuration: {:?}", config);
println!("\n--- Circuit Breaker Status ---");
match router.circuit_breaker_status() {
Some(true) => println!("State: Closed (accepting requests)"),
Some(false) => println!("State: Open (rejecting requests)"),
None => println!("State: Disabled"),
}
println!("\n--- Test Routing ---");
let candidates = vec![Candidate {
id: "test-1".to_string(),
embedding: vec![0.5; 384],
metadata: HashMap::new(),
created_at: chrono::Utc::now().timestamp(),
access_count: 10,
success_rate: 0.95,
}];
let request = RoutingRequest {
query_embedding: vec![0.5; 384],
candidates,
metadata: None,
};
match router.route(request) {
Ok(response) => {
println!(
"Test routing successful: {} candidates in {}μs",
response.candidates_processed, response.inference_time_us
);
}
Err(e) => {
println!("Test routing failed: {}", e);
}
}
println!("\n--- Model Reload ---");
println!("Attempting model reload...");
match router.reload_model() {
Ok(_) => println!("Model reload: Success"),
Err(e) => println!("Model reload: {} (expected if model file doesn't exist)", e),
}
println!("\n=== Admin Example Complete ===");
println!("\nFor a full HTTP admin server, you would need:");
println!("1. Add axum and tokio dependencies");
println!("2. Enable the admin-api feature");
println!("3. Use the AdminServer from the api module");
Ok(())
}
fn check_health(router: &Router) -> bool {
router.config().model_path.len() > 0
}
fn check_readiness(router: &Router) -> bool {
match router.circuit_breaker_status() {
Some(is_closed) => is_closed, None => true, }
}