pub struct QueryLog {
pub total_recorded: u64,
/* private fields */
}Expand description
Query log for tracking routing history and computing statistics
Fields§
§total_recorded: u64Total entries ever recorded (including evicted)
Implementations§
Source§impl QueryLog
impl QueryLog
Sourcepub fn with_capacity(max_size: usize) -> Self
pub fn with_capacity(max_size: usize) -> Self
Create a new query log with given capacity
Sourcepub fn record_routing(
&mut self,
query_id: u64,
source_id: impl Into<String>,
confidence: f32,
ml_used: bool,
feature_vector: Option<Vec<f32>>,
)
pub fn record_routing( &mut self, query_id: u64, source_id: impl Into<String>, confidence: f32, ml_used: bool, feature_vector: Option<Vec<f32>>, )
Record a routing decision (before execution result is known).
feature_vector is the ML feature vector used for this routing decision; stored
so that learn_from_outcome can retrieve it for online model updates.
Sourcepub fn find_entry_features(
&self,
query_id: u64,
source_id: &str,
) -> Option<Vec<f32>>
pub fn find_entry_features( &self, query_id: u64, source_id: &str, ) -> Option<Vec<f32>>
Find the feature vector stored for a given routing decision.
Returns None if the entry doesn’t exist or has no feature vector.
Sourcepub fn record_outcome(
&mut self,
query_id: u64,
source_id: &str,
success: bool,
latency_ms: u32,
result_count: u32,
reward: f32,
)
pub fn record_outcome( &mut self, query_id: u64, source_id: &str, success: bool, latency_ms: u32, result_count: u32, reward: f32, )
Record the outcome of a routing decision
Matches by query_id + source_id (most recent match).
Sourcepub fn source_stats(&self, source_id: &str) -> Option<&SourceLogStats>
pub fn source_stats(&self, source_id: &str) -> Option<&SourceLogStats>
Get aggregated statistics for a source
Sourcepub fn routing_score(&self, source_id: &str) -> Option<f32>
pub fn routing_score(&self, source_id: &str) -> Option<f32>
Get the routing score for a source based on log history
Returns a value in 0.0–1.0 representing how well this source
has performed historically. Returns None if no history.
Sourcepub fn best_source(&self) -> Option<&str>
pub fn best_source(&self) -> Option<&str>
Get the best source ID based on log history
Sourcepub fn ranked_sources(&self) -> Vec<(String, f32)>
pub fn ranked_sources(&self) -> Vec<(String, f32)>
Get all source IDs that have log history, sorted by score (descending)
Sourcepub fn recent_entries(&self, limit: usize) -> &[RoutingLogEntry]
pub fn recent_entries(&self, limit: usize) -> &[RoutingLogEntry]
Get recent log entries (up to limit)
Sourcepub fn clear_entries(&mut self)
pub fn clear_entries(&mut self)
Clear the log (preserves source statistics)
Sourcepub fn evict_older_than(&mut self, max_age_ms: u64) -> usize
pub fn evict_older_than(&mut self, max_age_ms: u64) -> usize
Remove entries older than max_age_ms milliseconds
Returns the number of entries removed.
Sourcepub fn tracked_source_count(&self) -> usize
pub fn tracked_source_count(&self) -> usize
Get the number of sources with log history
Sourcepub fn combined_reliability(&self, source_id: &str, current_rate: f32) -> f32
pub fn combined_reliability(&self, source_id: &str, current_rate: f32) -> f32
Compute a reliability score for a source: combines log stats and the
provided current success_rate from SourceStats.
current_rate should be source.stats.success_rate.
If no log history, falls back to current_rate.