Skip to main content

innate_core/
lib.rs

1pub mod backup;
2pub mod cli;
3pub mod daemon;
4pub mod embedding;
5pub mod errors;
6pub mod hook;
7pub mod install;
8pub mod kb;
9pub mod llm;
10pub mod llm_trace;
11pub mod mcp;
12pub mod migrate;
13pub mod paths;
14pub mod refine;
15pub mod settings;
16pub mod storage;
17pub mod upgrade;
18pub mod utils;
19pub mod web;
20
21#[cfg(test)]
22mod tests;
23
24pub use errors::{InnateError, Result};
25pub use kb::{
26    AbstainReason, AppraiseParams, Contributor, CurateReport, FlaggedPoint, KnowledgeBase,
27    RecallParams, RecallResult, RecordParams, Situation, Tier, Valence, Verdict, APPRAISE_ADVISORY,
28};
29
30/// Open a KnowledgeBase at `db_path`, injecting LLM providers from `~/.innate/settings.json`
31/// if configured. Falls back to DummyEmbeddingProvider + HeuristicDistiller when no LLM
32/// settings are present.
33pub fn open_kb(db_path: impl AsRef<std::path::Path>) -> Result<KnowledgeBase> {
34    use std::sync::Arc;
35    let s = settings::load()?;
36
37    let embedding: Option<Arc<dyn embedding::EmbeddingProvider>> = s.embedding.as_ref().map(|c| {
38        Arc::new(llm::LlmEmbeddingProvider::new(c.clone())) as Arc<dyn embedding::EmbeddingProvider>
39    });
40
41    // When a remote LLM distiller is configured, wrap it with a deterministic
42    // fallback so knowledge creation never depends on the LLM staying available:
43    // the LLM gets the first 2 attempts per log (quality); after that the
44    // deterministic HeuristicDistiller guarantees capture (stability).
45    let distiller: Option<Arc<dyn refine::Distiller>> = s.llm.as_ref().map(|c| {
46        let primary = llm::build_distiller(c) as Arc<dyn refine::Distiller>;
47        Arc::new(refine::ResilientDistiller::new(
48            primary,
49            Arc::new(refine::HeuristicDistiller),
50            2,
51        )) as Arc<dyn refine::Distiller>
52    });
53
54    KnowledgeBase::open_with(db_path, embedding, None, distiller, None, None)
55}