Skip to main content

ContextEngine

Struct ContextEngine 

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

The core context engine that coordinates storage, search, and assembly.

Implementations§

Source§

impl ContextEngine

Source

pub fn new( storage: Box<dyn ContextStorage>, searcher: Box<dyn Searcher>, config: Config, ) -> Self

Create a new engine with the given storage backend, searcher, and config.

If config.recency_half_life_secs is not positive and finite, it is clamped to DEFAULT_RECENCY_HALF_LIFE_SECS to prevent NaN/inf in recency decay scoring.

Source

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

Assemble context entries that fit within token_budget.

  1. Searches for candidates matching query, restricted to scope if given.
  2. Applies recency weighting to each candidate’s score.
  3. Sorts by weighted score descending.
  4. Packs entries greedily until the budget is exhausted.

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 underlying search fails.

Source

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

Save a new snapshot entry. Capacity enforcement (LRU eviction) is handled atomically by the storage layer inside an immediate transaction, so no in-process locking is required here.

Returns the generated entry ID.

§Security

This is a low-level write path that does not scrub secrets from content. ContextForge::save is the only entry point that applies scrub_secrets before persistence; callers writing through the engine directly are responsible for scrubbing first.

§Errors

Returns Error::InvalidEntry if content is empty, or propagates any error from the underlying storage write.

Source

pub fn storage(&self) -> &dyn ContextStorage

Return a reference to the underlying storage backend.

This is exposed for callers that need direct access to storage operations (delete, clear, count) not covered by Self::assemble or Self::save_snapshot.

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.