pub struct FeedbackStore { /* private fields */ }Expand description
SQLite-backed feedback store.
Implementations§
Source§impl FeedbackStore
impl FeedbackStore
Sourcepub fn open_in_memory() -> Result<Self>
pub fn open_in_memory() -> Result<Self>
Open an in-memory store (test / ephemeral).
§Examples
use samkhya_core::feedback::FeedbackStore;
let store = FeedbackStore::open_in_memory().unwrap();
assert_eq!(store.count().unwrap(), 0);Sourcepub fn record_plan(&self, obs: &PlanObservation) -> Result<i64>
pub fn record_plan(&self, obs: &PlanObservation) -> Result<i64>
Record an observation with the plan-shape features the corrector will see at inference time.
§Examples
use samkhya_core::feedback::{FeedbackStore, PlanObservation};
use samkhya_core::residual::CorrectionFeatures;
let store = FeedbackStore::open_in_memory().unwrap();
let obs = PlanObservation {
template_hash: "job-slow".into(),
plan_fingerprint: "hash-join#7".into(),
features: CorrectionFeatures {
baseline_estimate: 1_000,
left_input_rows: Some(500),
right_input_rows: Some(2_000),
predicate_count: 2,
join_depth: 3,
..Default::default()
},
actual_rows: 9_500,
latency_ms: Some(12.5),
};
store.record_plan(&obs).unwrap();
let history = store.plan_history("job-slow").unwrap();
assert_eq!(history.len(), 1);
assert_eq!(history[0].features.join_depth, 3);Sourcepub fn plan_history(&self, template_hash: &str) -> Result<Vec<PlanObservation>>
pub fn plan_history(&self, template_hash: &str) -> Result<Vec<PlanObservation>>
Return every observation for template_hash that carries plan
features, oldest first.
Rows recorded through record have no features and
are skipped: training on them would silently reintroduce the
feature-space mismatch this type exists to prevent. The filter is
predicate_count IS NOT NULL, which only
record_plan sets.
Sourcepub fn record(&self, obs: &Observation) -> Result<i64>
pub fn record(&self, obs: &Observation) -> Result<i64>
Record an observation.
§Examples
use samkhya_core::feedback::{FeedbackStore, Observation};
let store = FeedbackStore::open_in_memory().unwrap();
let obs = Observation {
template_hash: "tpch-q1".into(),
plan_fingerprint: "hash-join#42".into(),
est_rows: 1000,
actual_rows: 950,
latency_ms: Some(12.5),
};
let id = store.record(&obs).unwrap();
assert!(id > 0);
assert_eq!(store.count().unwrap(), 1);Auto Trait Implementations§
impl !Freeze for FeedbackStore
impl !RefUnwindSafe for FeedbackStore
impl !Sync for FeedbackStore
impl !UnwindSafe for FeedbackStore
impl Send for FeedbackStore
impl Unpin for FeedbackStore
impl UnsafeUnpin for FeedbackStore
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