pub struct PatternStore { /* private fields */ }Expand description
SQLite-backed tool invocation pattern store for PASTE.
Thread-safe via Arc. Call observe after each tool completion
and predict at skill activation to get speculative candidates.
§Examples
let store = PatternStore::new(pool, 14.0);
store.observe("my-skill", "abc123", None, "bash",
r#"{"command":"ls"}"#, ToolOutcome::Success, 42).await?;
let predictions = store.predict("my-skill", "abc123", None, 3).await?;Implementations§
Source§impl PatternStore
impl PatternStore
Sourcepub fn new(pool: DbPool, half_life_days: f64) -> Self
pub fn new(pool: DbPool, half_life_days: f64) -> Self
Create a new pattern store.
half_life_days controls the exponential decay; 14 days is the default.
Sourcepub fn with_min_observations(self, n: u32) -> Self
pub fn with_min_observations(self, n: u32) -> Self
Set the minimum number of raw observations required before predicting.
Sourcepub async fn observe(
&self,
skill_name: &str,
skill_hash: &str,
prev_tool: Option<&str>,
next_tool: &str,
args_json: &str,
outcome: ToolOutcome,
latency_ms: u64,
) -> Result<(), PatternError>
pub async fn observe( &self, skill_name: &str, skill_hash: &str, prev_tool: Option<&str>, next_tool: &str, args_json: &str, outcome: ToolOutcome, latency_ms: u64, ) -> Result<(), PatternError>
Record a completed tool invocation.
Updates count_decayed using the exponential decay formula (computed in Rust,
not via pow() in SQLite — pow requires SQLITE_ENABLE_MATH_FUNCTIONS
which is not available in bundled libsqlite3-sys) and appends to
success_raw / count_raw. Also triggers a debounced refresh.
§Errors
Returns PatternError::Db on SQLite failure.
Sourcepub async fn predict(
&self,
skill_name: &str,
skill_hash: &str,
prev_tool: Option<&str>,
k: u8,
) -> Result<Vec<Prediction>, PatternError>
pub async fn predict( &self, skill_name: &str, skill_hash: &str, prev_tool: Option<&str>, k: u8, ) -> Result<Vec<Prediction>, PatternError>
Return the top-k predicted next tool calls for (skill, prev_tool).
Only returns predictions with wilson_lower_bound >= 0.5 and
count_raw >= min_observations.
§Errors
Returns PatternError::Db on SQLite failure.
Sourcepub async fn refresh(
&self,
skill_name: &str,
skill_hash: &str,
prev_tool: Option<&str>,
) -> Result<(), PatternError>
pub async fn refresh( &self, skill_name: &str, skill_hash: &str, prev_tool: Option<&str>, ) -> Result<(), PatternError>
Recompute and materialize predictions for (skill, skill_hash, prev_tool).
Debounced to at most once per 60 s per (skill_hash, prev_tool).
Runs DELETE + N INSERTs inside a single transaction (H3: atomic refresh).
§Errors
Returns PatternError::Db on SQLite failure.
Sourcepub async fn vacuum(&self) -> Result<u64, PatternError>
pub async fn vacuum(&self) -> Result<u64, PatternError>
Purge tool_pattern_transitions rows with stale skill_hash older than 30 days.
§Errors
Returns PatternError::Db on SQLite failure.
Auto Trait Implementations§
impl Freeze for PatternStore
impl !RefUnwindSafe for PatternStore
impl Send for PatternStore
impl Sync for PatternStore
impl Unpin for PatternStore
impl UnsafeUnpin for PatternStore
impl !UnwindSafe for PatternStore
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
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request