pub struct Context {
pub id: ContextId,
pub content: String,
pub domain: ContextDomain,
pub created_at: DateTime<Utc>,
pub accessed_at: DateTime<Utc>,
pub expires_at: Option<DateTime<Utc>>,
pub metadata: ContextMetadata,
pub embedding: Option<Vec<f32>>,
}Expand description
A context entry for storage and retrieval
Inspired by memory-gate’s LearningContext with additions for:
- Temporal reasoning (created_at, accessed_at, expires_at)
- Security screening integration
- RAG-optimized fields
Fields§
§id: ContextIdUnique identifier
content: StringMain content of the context
domain: ContextDomainDomain classification
created_at: DateTime<Utc>When this context was created
accessed_at: DateTime<Utc>When this context was last accessed
expires_at: Option<DateTime<Utc>>Optional expiration time
metadata: ContextMetadataAssociated metadata
embedding: Option<Vec<f32>>Optional embedding vector for similarity search
Implementations§
Source§impl Context
impl Context
Sourcepub fn new(content: impl Into<String>, domain: ContextDomain) -> Self
pub fn new(content: impl Into<String>, domain: ContextDomain) -> Self
Create a new context entry
Sourcepub fn with_metadata(self, metadata: ContextMetadata) -> Self
pub fn with_metadata(self, metadata: ContextMetadata) -> Self
Set metadata
Sourcepub fn with_source(self, source: impl Into<String>) -> Self
pub fn with_source(self, source: impl Into<String>) -> Self
Set source in metadata
Sourcepub fn with_importance(self, importance: f32) -> Self
pub fn with_importance(self, importance: f32) -> Self
Set importance
Add tags
Sourcepub fn with_expiration(self, expires_at: DateTime<Utc>) -> Self
pub fn with_expiration(self, expires_at: DateTime<Utc>) -> Self
Set expiration
Sourcepub fn with_embedding(self, embedding: Vec<f32>) -> Self
pub fn with_embedding(self, embedding: Vec<f32>) -> Self
Set embedding vector
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Check if context has expired
Sourcepub fn age_seconds(&self) -> i64
pub fn age_seconds(&self) -> i64
Get age in seconds
Sourcepub fn mark_accessed(&mut self)
pub fn mark_accessed(&mut self)
Mark as accessed (updates accessed_at)
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Context
impl<'de> Deserialize<'de> for Context
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Context
impl RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnwindSafe for Context
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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 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>
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