Skip to main content

QueryLog

Struct QueryLog 

Source
pub struct QueryLog {
    pub total_recorded: u64,
    /* private fields */
}
Expand description

Query log for tracking routing history and computing statistics

Fields§

§total_recorded: u64

Total entries ever recorded (including evicted)

Implementations§

Source§

impl QueryLog

Source

pub fn new() -> Self

Create a new query log with the default capacity

Source

pub fn with_capacity(max_size: usize) -> Self

Create a new query log with given capacity

Source

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.

Source

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.

Source

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).

Source

pub fn source_stats(&self, source_id: &str) -> Option<&SourceLogStats>

Get aggregated statistics for a source

Source

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.

Source

pub fn best_source(&self) -> Option<&str>

Get the best source ID based on log history

Source

pub fn ranked_sources(&self) -> Vec<(String, f32)>

Get all source IDs that have log history, sorted by score (descending)

Source

pub fn recent_entries(&self, limit: usize) -> &[RoutingLogEntry]

Get recent log entries (up to limit)

Source

pub fn len(&self) -> usize

Get the number of entries in the log

Source

pub fn is_empty(&self) -> bool

Check if the log is empty

Source

pub fn clear_entries(&mut self)

Clear the log (preserves source statistics)

Source

pub fn clear_all(&mut self)

Clear everything including statistics

Source

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.

Source

pub fn tracked_source_count(&self) -> usize

Get the number of sources with log history

Source

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.

Trait Implementations§

Source§

impl Clone for QueryLog

Source§

fn clone(&self) -> QueryLog

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for QueryLog

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for QueryLog

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for QueryLog

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for QueryLog

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,