Skip to main content

ContextForge

Struct ContextForge 

Source
pub struct ContextForge { /* private fields */ }
Expand description

The documented entry point for context-forge.

ContextForge wires together a SqliteStorage backend, a SqliteSearcher, and a ContextEngine behind a small, stable API surface. Advanced callers that need direct access to the underlying storage or searcher can construct those types directly and pass them to ContextEngine::new instead.

Implementations§

Source§

impl ContextForge

Source

pub fn open(config: Config) -> Result<Self>

Open (or create) the database at config.db_path, run any pending migrations, and build the engine.

§Errors

Returns an error if the database cannot be opened, the connection pool cannot be built, or migrations fail.

Source

pub fn save( &self, content: &str, kind: &str, opts: &SaveOptions, ) -> Result<String>

Save a new entry. Returns the generated entry ID.

kind is a caller-defined classification (see kind for well-known values). Capacity enforcement (LRU eviction) is handled atomically by the storage layer.

Before persistence, content is passed through scrub_secrets using this instance’s ScrubConfig (see Config::scrub), redacting common credential formats with [REDACTED:<label>] placeholders. opts.metadata is stored verbatim and is not scrubbed — see SaveOptions::metadata.

§Errors

Returns an error if content is empty or if the underlying storage write fails.

Source

pub fn distill_and_save( &self, transcript: &str, distiller: &dyn Distiller, opts: &SaveOptions, ) -> Result<Vec<String>>

Distill transcript into a summary and durable facts, then save them as separate entries sharing opts.scope and opts.session_id.

transcript is passed through scrub_secrets before it is sent to distiller (so secrets never reach a distillation endpoint), and the summary/facts produced are scrubbed again before persistence via the normal ContextForge::save path (defense in depth).

The summary is saved with kind::SUMMARY; each fact is saved with kind::FACT and metadata {"fact_kind": "<kind>", "source": "distill"}.

Returns the IDs of the saved entries: the summary’s ID first, followed by each fact’s ID in order.

§Errors

Returns an error if distillation fails, or if any save fails.

Source

pub fn query( &self, query: &str, scope: Option<&str>, token_budget: usize, ) -> Result<Vec<ContextEntry>>

Assemble entries matching query that fit within token_budget.

scope = None searches every entry regardless of scope (global recall). scope = Some(s) restricts the search to entries whose scope equals s.

§Errors

Returns an error if the search or recency-weighting step fails.

Source

pub fn delete(&self, id: &str) -> Result<bool>

Delete a single entry by id. Returns true if an entry was removed.

§Errors

Returns an error if the underlying storage delete fails.

Source

pub fn clear_scope(&self, scope: &str) -> Result<usize>

Remove all entries within a given scope. Returns the number of entries removed.

§Errors

Returns an error if the underlying storage delete fails.

Source

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

Remove all entries. Returns the number of entries removed.

§Errors

Returns an error if the underlying storage delete fails.

Source

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

Return the total number of stored entries.

§Errors

Returns an error if the underlying storage count fails.

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<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, 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.