pub struct SemanticContextWindow {
pub entries: Vec<ContextEntry>,
pub config: WindowConfig,
pub total_added: u64,
}Expand description
Sliding context window for session-aware semantic search personalization.
Maintains a bounded list of recent queries, search results, and user feedback. Provides a weighted context embedding that captures recency-biased user intent.
Fields§
§entries: Vec<ContextEntry>Current window entries, oldest at index 0, newest at end.
config: WindowConfigConfiguration for this window.
total_added: u64Monotonically increasing counter of all entries ever added.
Implementations§
Source§impl SemanticContextWindow
impl SemanticContextWindow
Sourcepub fn new(config: WindowConfig) -> Self
pub fn new(config: WindowConfig) -> Self
Creates a new context window with the given configuration.
Sourcepub fn add(&mut self, entry: ContextEntry)
pub fn add(&mut self, entry: ContextEntry)
Adds an entry to the window.
If the window is full (len > max_entries), the oldest entry is evicted.
Sourcepub fn context_embedding(&self) -> Vec<f32>
pub fn context_embedding(&self) -> Vec<f32>
Computes a recency-weighted average context embedding.
Only ContextEntry::Query and ContextEntry::Result entries contribute
embeddings. Entries with the wrong embedding dimension are skipped silently.
The weight of entry at window index i (0 = oldest) is:
decay_factor ^ (window_len - 1 - i)
Returns a zero vector of length embedding_dim when no valid embeddings
are present in the window.
Sourcepub fn recent_queries(&self, n: usize) -> Vec<&ContextEntry>
pub fn recent_queries(&self, n: usize) -> Vec<&ContextEntry>
Returns the last n ContextEntry::Query entries, newest first.
Sourcepub fn recent_results(&self, n: usize) -> Vec<&ContextEntry>
pub fn recent_results(&self, n: usize) -> Vec<&ContextEntry>
Returns the last n ContextEntry::Result entries, newest first.
Sourcepub fn positive_docs(&self) -> Vec<u64>
pub fn positive_docs(&self) -> Vec<u64>
Returns doc_ids with positive feedback, oldest first, deduplicated.
Sourcepub fn negative_docs(&self) -> Vec<u64>
pub fn negative_docs(&self) -> Vec<u64>
Returns doc_ids with negative feedback, oldest first, deduplicated.
Sourcepub fn stats(&self) -> ContextStats
pub fn stats(&self) -> ContextStats
Returns a snapshot of current window statistics.
Auto Trait Implementations§
impl Freeze for SemanticContextWindow
impl RefUnwindSafe for SemanticContextWindow
impl Send for SemanticContextWindow
impl Sync for SemanticContextWindow
impl Unpin for SemanticContextWindow
impl UnsafeUnpin for SemanticContextWindow
impl UnwindSafe for SemanticContextWindow
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> 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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.