Skip to main content

KnowledgeBase

Struct KnowledgeBase 

Source
pub struct KnowledgeBase {
    pub storage: Storage,
    /* private fields */
}

Fields§

§storage: Storage

Implementations§

Source§

impl KnowledgeBase

Source

pub fn appraise(&self, params: AppraiseParams<'_>) -> Result<Verdict>

Source§

impl KnowledgeBase

Source

pub fn evolve(&self, trigger: &str) -> Result<Value>

Source§

impl KnowledgeBase

Source

pub fn inspect(&self) -> Result<Value>

Source

pub fn rebuild_embeddings(&self) -> Result<usize>

Source

pub fn inspect_id(&self, id: &str) -> Result<Value>

Source§

impl KnowledgeBase

Source

pub fn add( &self, content: &str, kind: &str, trigger_desc: Option<&str>, anti_trigger_desc: Option<&str>, source: &str, skill_name: Option<&str>, ) -> Result<String>

Source

pub fn add_with_deps( &self, content: &str, kind: &str, trigger_desc: Option<&str>, anti_trigger_desc: Option<&str>, source: &str, skill_name: Option<&str>, deps: &[(String, String)], ) -> Result<String>

Full-form writer: persist a chunk, its vectors, and all declared dependencies in a single transaction. Each dep is (dst_chunk_id, kind); kind ∈ {soft,hard}. Dependency targets are validated to exist inside the transaction, so a bad dependency rolls back the whole write — the chunk is never persisted on its own.

Source

pub fn add_dependency(&self, src: &str, dst: &str, kind: &str) -> Result<()>

Declare that chunk src depends on chunk dst.

kind is "hard" (fail-closed: if dst is unavailable or archived at recall time the whole seed is dropped) or "soft" (a recall-time ranking bonus). Both chunks must exist. Idempotent — re-declaring the same edge is a no-op (INSERT OR IGNORE).

Source

pub fn spark( &self, content: &str, trigger_desc: Option<&str>, anti_trigger_desc: Option<&str>, ) -> Result<String>

Source

pub fn mature_spark(&self, spark_id: &str, to: &str) -> Result<()>

Source

pub fn promote_spark(&self, spark_id: &str, to: &str) -> Result<String>

Source

pub fn drop_spark(&self, spark_id: &str, reason: &str) -> Result<()>

Source

pub fn approve(&self, chunk_id: &str) -> Result<()>

Source

pub fn archive(&self, chunk_id: &str, reason: &str) -> Result<()>

Source

pub fn invalidate(&self, chunk_id: &str, reason: &str) -> Result<()>

Source

pub fn restore(&self, chunk_id: &str) -> Result<()>

Source§

impl KnowledgeBase

Source

pub fn recall(&self, params: RecallParams<'_>) -> Result<RecallResult>

Source§

impl KnowledgeBase

Source

pub fn record(&self, params: RecordParams<'_>) -> Result<()>

Source§

impl KnowledgeBase

Source

pub fn repair_traces(&self, dry_run: bool) -> Result<TraceRepairReport>

One-shot data repair for trace pollution that predates the strict selected = “entered the model context” semantics (Priority 1).

Before the fix, the daemon recalled on every session start, discarded the knowledge, and kept only the trace_id — yet recall() had already written per-chunk selected/retrieved events and an open episodic log. That inflated selected_count (which feeds the curate archive heuristic selected_count >= N AND used_count = 0) and stuffed the open pool that drives trace-completion stats. Empty hook recalls did the same.

This repair, in one transaction:

  1. deletes daemon-sourced selected/retrieved usage events;
  2. recomputes selected_count from the cleaned facts (curate’s formula);
  3. retires orphaned open logs (daemon session traces + no-answer recalls whose snapshot selected nothing) to discarded/known_none.

Idempotent: a second run deletes nothing and recomputes the same counts. With dry_run the transaction is rolled back and the report reflects what would change.

Source§

impl KnowledgeBase

Source

pub fn open(db_path: impl AsRef<Path>) -> Result<Self>

Source

pub fn open_with( db_path: impl AsRef<Path>, embedding: Option<Arc<dyn EmbeddingProvider>>, refiner: Option<Arc<dyn Refiner>>, distiller: Option<Arc<dyn Distiller>>, curator: Option<Arc<dyn Curator>>, sanitizer: Option<Arc<dyn Sanitizer>>, ) -> Result<Self>

Source

pub fn with_reranker(self, reranker: Arc<dyn Reranker>) -> Self

Install an opt-in offline reranker (part d). Used by open_kb when an LLM is configured; recall only invokes it when a caller passes rerank=true, so the default hook path stays no-LLM regardless.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.