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
impl ContextForge
Sourcepub async fn open(config: Config) -> Result<Self>
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.
Sourcepub async fn save(
&self,
content: &str,
kind: &str,
opts: &SaveOptions,
) -> Result<String>
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.
Sourcepub async fn distill_and_save(
&self,
transcript: &str,
distiller: &dyn Distiller,
opts: &SaveOptions,
) -> Result<Vec<String>>
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.
Sourcepub async fn query(
&self,
query: &str,
scope: Option<&str>,
token_budget: usize,
) -> Result<Vec<ContextEntry>>
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.
Sourcepub async fn delete(&self, id: &str) -> Result<bool>
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.
Sourcepub async fn clear_scope(&self, scope: &str) -> Result<usize>
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.
Auto Trait Implementations§
impl !RefUnwindSafe for ContextForge
impl !UnwindSafe for ContextForge
impl Freeze for ContextForge
impl Send for ContextForge
impl Sync for ContextForge
impl Unpin for ContextForge
impl UnsafeUnpin for ContextForge
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<T> Fruit for T
impl<T> Fruit for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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