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 with_scorer(self, scorer: Arc<dyn LexiconScorer>) -> Self
pub fn with_scorer(self, scorer: Arc<dyn LexiconScorer>) -> Self
Attach a LexiconScorer to this engine.
The scorer runs inside Self::assemble after BM25 + recency decay
and before the token-budget cut. Calling this again replaces the previous
scorer. Prefer constructing via crate::ContextForgeBuilder, which
automatically composes crate::DefaultEnglishScorer with any
caller-provided persona scorer.
Sourcepub async fn assemble(
&self,
query: &str,
scope: Option<&str>,
token_budget: usize,
) -> Result<Vec<ContextEntry>>
pub async 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 async fn save_snapshot(
&self,
content: &str,
kind: &str,
options: &SaveOptions,
) -> Result<String>
pub async 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.
Auto Trait Implementations§
impl !RefUnwindSafe for ContextEngine
impl !UnwindSafe for ContextEngine
impl Freeze for ContextEngine
impl Send for ContextEngine
impl Sync for ContextEngine
impl Unpin for ContextEngine
impl UnsafeUnpin for ContextEngine
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>, 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
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