use context_forge::{
bootstrap_prompt, kind, ConfigLexiconScorer, ContextForge, SaveOptions, MATCH_ALL_QUERY,
};
#[tokio::main]
async fn main() -> Result<(), context_forge::Error> {
let prompt = bootstrap_prompt("A Space Marine Chaplain from Warhammer 40k");
println!("=== bootstrap prompt (first 300 chars) ===");
println!("{}\n", &prompt[..300.min(prompt.len())]);
let persona_toml = r#"
[terms]
"Omnissiah" = 0.9 # critical proper noun — almost always in high-value content
"Astartes" = 0.6 # strong domain noun
"bolter" = 0.3 # mild domain term
[affirmations]
patterns = [
"for the emperor", # confirmation / commitment
"it shall be done", # future obligation
"affirmative, brother", # agreement
]
[negations]
patterns = [
"negative, battle-brother", # disagreement
"the emperor frowns upon this", # dismissal
]
"#;
let persona: ConfigLexiconScorer = persona_toml.parse()?;
let mut config = context_forge::Config::default();
config.db_path = std::path::PathBuf::from(":memory:");
let cf = ContextForge::builder(config)
.with_persona_scorer(persona)
.build()
.await?;
let opts = SaveOptions::default();
let neutral_id = cf
.save(
"the routine maintenance check was completed",
kind::SNAPSHOT,
&opts,
)
.await?;
let english_id = cf
.save(
"confirmed, the patrol route is clear",
kind::SNAPSHOT,
&opts,
)
.await?;
let persona_id = cf
.save(
"for the emperor — the Astartes have secured the sector",
kind::SNAPSHOT,
&opts,
)
.await?;
let hits = cf.query(MATCH_ALL_QUERY, None, 10_000).await?;
println!("=== query results (highest importance first) ===");
for (i, hit) in hits.iter().enumerate() {
let label = if hit.id == persona_id {
"persona signal"
} else if hit.id == english_id {
"english signal"
} else if hit.id == neutral_id {
"neutral"
} else {
"unknown"
};
println!(" {}. [{}] {}", i + 1, label, hit.content);
}
assert_eq!(
hits[0].id, persona_id,
"persona-signaled entry should rank first"
);
assert_eq!(hits[2].id, neutral_id, "neutral entry should rank last");
println!("\nRanking is correct — lexicon scoring is working.");
Ok(())
}