pub struct ContextEngine { /* private fields */ }Expand description
The core context engine that coordinates storage, search, and assembly.
Implementations§
Source§impl ContextEngine
impl ContextEngine
Sourcepub fn new(
storage: Box<dyn ContextStorage>,
searcher: Box<dyn Searcher>,
config: Config,
) -> Self
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.
Sourcepub fn assemble(
&self,
query: &str,
scope: Option<&str>,
token_budget: usize,
) -> Result<Vec<ContextEntry>>
pub fn assemble( &self, query: &str, scope: Option<&str>, token_budget: usize, ) -> Result<Vec<ContextEntry>>
Assemble context entries that fit within token_budget.
- Searches for candidates matching
query, restricted toscopeif given. - Applies recency weighting to each candidate’s score.
- Sorts by weighted score descending.
- 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.
Sourcepub fn save_snapshot(
&self,
content: &str,
kind: &str,
options: &SaveOptions,
) -> Result<String>
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.
Sourcepub fn storage(&self) -> &dyn ContextStorage
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.