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 TursoStorage backend, a TursoSearcher, 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 builder(config: Config) -> ContextForgeBuilder

Create a builder for ContextForge.

The builder always pre-seeds DefaultEnglishScorer so plain-English importance signals are active without any configuration. Use ContextForgeBuilder::with_persona_scorer to stack a domain-specific scorer on top. See also Self::open for the lower-level path that wires no scorer.

Source

pub async 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 or migrations fail.

Source

pub async 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 async 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"}.

The distilled output is bounded before any of it is saved: at most MAX_FACTS facts are kept, each fact’s text is truncated to at most MAX_FACT_CHARS characters, and the summary is truncated to at most MAX_SUMMARY_CHARS characters. Excess facts and text beyond these limits are silently dropped or truncated, since they are untrusted model-generated content.

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

query is treated as natural-language text: it is split into alphanumeric terms which are OR-matched and ranked by bm25 relevance. FTS5 operator syntax (AND, OR, NEAR, prefix *, quoted phrases, column filters, etc.) is not interpreted — operator characters are treated as term separators, so arbitrary user text never produces a query syntax error. A query with no alphanumeric terms (empty or punctuation-only) returns an empty result set rather than an error. The special value MATCH_ALL_QUERY ("*") matches every entry.

§Errors

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

Source

pub async 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 async 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 async 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 async 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<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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Fruit for T
where T: Send + Downcast,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more