pub struct SemanticFeedbackLoop {
pub feedback: HashMap<u64, QueryFeedback>,
pub boosts: HashMap<u64, BoostRecord>,
pub stats: FeedbackStats,
/* private fields */
}Expand description
Core feedback-loop engine.
Ingests relevance signals emitted during search sessions and uses them to boost (or suppress) future rankings of individual results.
Fields§
§feedback: HashMap<u64, QueryFeedback>Per-query feedback records, keyed by query_id.
boosts: HashMap<u64, BoostRecord>Per-result cumulative boost records, keyed by result_id.
stats: FeedbackStatsGlobal statistics.
Implementations§
Source§impl SemanticFeedbackLoop
impl SemanticFeedbackLoop
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new, empty feedback loop with the default capacity of 50 000 entries.
Sourcepub fn with_max_entries(max_entries: usize) -> Self
pub fn with_max_entries(max_entries: usize) -> Self
Create a new, empty feedback loop with the given maximum entry capacity.
Sourcepub fn record_feedback(
&mut self,
query_id: u64,
signal: FeedbackSignal,
now_secs: u64,
)
pub fn record_feedback( &mut self, query_id: u64, signal: FeedbackSignal, now_secs: u64, )
Record a single relevance signal for the given query.
- Updates the per-query
QueryFeedbackrecord. - Updates the per-result
BoostRecord. - Updates global
FeedbackStats.
Sourcepub fn apply_boosts(&self, results: &[(u64, f64)]) -> Vec<(u64, f64)>
pub fn apply_boosts(&self, results: &[(u64, f64)]) -> Vec<(u64, f64)>
Re-score and re-rank a list of (result_id, score) pairs using boosts.
For each entry: new_score = score * (1.0 + effective_boost().max(-0.9))
The result list is returned sorted by new_score descending.
Sourcepub fn top_boosted_ids(&self, k: usize) -> Vec<u64>
pub fn top_boosted_ids(&self, k: usize) -> Vec<u64>
Return the top-k result IDs sorted by effective_boost descending.
Sourcepub fn positive_ids_for_query(&self, query_id: u64) -> Vec<u64>
pub fn positive_ids_for_query(&self, query_id: u64) -> Vec<u64>
Return the positive result_ids recorded for a specific query.
Returns an empty Vec if the query has not been seen.
Sourcepub fn stats(&self) -> &FeedbackStats
pub fn stats(&self) -> &FeedbackStats
Reference to the global statistics.
Sourcepub fn record(
&mut self,
query_id: &str,
doc_id: &str,
feedback: FeedbackType,
confidence: f64,
)
pub fn record( &mut self, query_id: &str, doc_id: &str, feedback: FeedbackType, confidence: f64, )
Record a user feedback entry. If the loop is at capacity the oldest entry is evicted before inserting the new one.
Sourcepub fn get_summary(&self, query_id: &str) -> Option<QueryFeedbackSummary>
pub fn get_summary(&self, query_id: &str) -> Option<QueryFeedbackSummary>
Aggregate feedback for a specific query. Returns None if the query
has no recorded entries.
Sourcepub fn relevant_docs(&self, query_id: &str) -> Vec<String>
pub fn relevant_docs(&self, query_id: &str) -> Vec<String>
Return document IDs marked Relevant for the given query.
Sourcepub fn irrelevant_docs(&self, query_id: &str) -> Vec<String>
pub fn irrelevant_docs(&self, query_id: &str) -> Vec<String>
Return document IDs marked Irrelevant for the given query.
Sourcepub fn precision_at_query(&self, query_id: &str) -> Option<f64>
pub fn precision_at_query(&self, query_id: &str) -> Option<f64>
Precision for a single query: relevant / (relevant + irrelevant).
Returns None when the query has no relevant or irrelevant entries.
Sourcepub fn overall_precision(&self) -> Option<f64>
pub fn overall_precision(&self) -> Option<f64>
Overall precision across all queries: total_relevant / (total_relevant + total_irrelevant).
Returns None when there are no relevant or irrelevant entries at all.
Sourcepub fn feedback_count(&self) -> usize
pub fn feedback_count(&self) -> usize
Total number of user feedback entries currently stored.
Sourcepub fn queries_with_feedback(&self) -> Vec<String>
pub fn queries_with_feedback(&self) -> Vec<String>
Unique query IDs that have at least one feedback entry.
Sourcepub fn clear_entries(&mut self)
pub fn clear_entries(&mut self)
Remove all user feedback entries and reset the tick counter.
Sourcepub fn loop_stats(&self) -> FeedbackLoopStats
pub fn loop_stats(&self) -> FeedbackLoopStats
Compute aggregate FeedbackLoopStats from the current entries.
Trait Implementations§
Source§impl Debug for SemanticFeedbackLoop
impl Debug for SemanticFeedbackLoop
Auto Trait Implementations§
impl Freeze for SemanticFeedbackLoop
impl RefUnwindSafe for SemanticFeedbackLoop
impl Send for SemanticFeedbackLoop
impl Sync for SemanticFeedbackLoop
impl Unpin for SemanticFeedbackLoop
impl UnsafeUnpin for SemanticFeedbackLoop
impl UnwindSafe for SemanticFeedbackLoop
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.