//! `comprehend_demo` — *understand before you generate.* //! //! Drives `JouleClawStack::comprehend` against a seeded corpus. The //! cascade walks only the L0–L2.5 verifiable zone — never the L3 model //! — and returns a [`ComprehensionTrace`] with every passage that //! grounded the answer, per-stage joule attribution, the optional //! extractive answer from the L1.5 reader, and (when a classifier is //! installed) the query's intent verdict. //! //! This is the Priscilla-from-Sentry surface: the 67%-comprehension //! workload made operationally visible. //! //! Run with: //! cargo run -p jouleclaw-stack --example comprehend_demo use jouleclaw_intent::HeuristicClassifier; use jouleclaw_local_index::{Document, InMemoryIndex, LocalIndexTier}; use jouleclaw_stack::{ComprehensionConfig, JouleClawStack}; fn main() { // Seed a tiny set of facts. let mut idx = InMemoryIndex::new(); idx.insert(Document::new("d1", "The capital of France is Paris.")); idx.insert(Document::new("d2", "The capital of Germany is Berlin.")); idx.insert(Document::new("d3", "The capital of Italy is Rome.")); let mut stack = JouleClawStack::with_defaults() .with_intent_classifier(Box::new(HeuristicClassifier::new())); stack.local_index = LocalIndexTier::new(idx); let cfg = ComprehensionConfig { use_federation: false, use_graph_enrich: false, ..ComprehensionConfig::default() }; let trace = stack.comprehend_with("explain what the capital of France is", 100.0, &cfg); println!("comprehension trace:"); println!(" question {}", trace.question); println!( " highest tier touched {} (verifiable-zone invariant)", trace.highest_tier_touched ); println!(" joules spent {:.6}", trace.joules_spent); println!(" budget exhausted {}", trace.budget_exhausted); if let Some(intent) = &trace.intent { println!( " intent {} ({:.0}% confident, classifier={})", intent.intent.label(), intent.confidence * 100.0, intent.classifier_id ); } println!(); println!("passages ({} total, in best-first order):", trace.passages.len()); for (i, p) in trace.passages.iter().enumerate() { let src = p.source.as_deref().unwrap_or("(no source)"); let score = p .rerank_score .map(|s| format!("{s:.3}")) .unwrap_or_else(|| "—".into()); println!(" [{i}] (score={score}) [{src}]"); println!(" {}", p.text); } println!(); if let Some(extracted) = trace.extracted_answer { println!("extracted answer: {extracted}"); println!("confidence: {:.3}", trace.confidence); } else { println!("(reader produced no extractive answer)"); } println!(); println!("per-stage trace:"); for s in &trace.stages { println!( " {stage:<26} {joules:>10.6} J {note}", stage = s.stage, joules = s.joules, note = s.note ); } }