pub struct SonaEngine { /* private fields */ }Expand description
The SONA engine for trajectory-based self-learning.
Records execution trajectories, distills patterns from successful ones, and adapts future behavior by matching against learned patterns.
Implementations§
Source§impl SonaEngine
impl SonaEngine
Sourcepub fn new(mode: SonaMode, embedding: Arc<dyn EmbeddingProvider>) -> Self
pub fn new(mode: SonaMode, embedding: Arc<dyn EmbeddingProvider>) -> Self
Create a new SONA engine with the given mode and embedding provider.
Sourcepub async fn record(&self, trajectory: Trajectory) -> Result<String, Error>
pub async fn record(&self, trajectory: Trajectory) -> Result<String, Error>
Record a new trajectory.
Generates an embedding for the trajectory’s input text and stores it for future distillation.
Sourcepub async fn distill(&self) -> Result<Vec<LearnedPattern>, Error>
pub async fn distill(&self) -> Result<Vec<LearnedPattern>, Error>
Distill learned patterns from successful trajectories.
Groups successful trajectories by domain and extracts common patterns. Returns the newly distilled patterns.
Sourcepub async fn adapt(&self, query: &str) -> Result<Option<LearnedPattern>, Error>
pub async fn adapt(&self, query: &str) -> Result<Option<LearnedPattern>, Error>
Adapt to a new query by finding the most similar learned pattern.
Returns the best matching pattern if similarity exceeds threshold. Target: < 0.05ms for in-memory lookup.
Sourcepub fn get_learned_patterns(&self) -> Vec<LearnedPattern>
pub fn get_learned_patterns(&self) -> Vec<LearnedPattern>
Get all learned patterns for persistence.
Sourcepub fn load_learned_patterns(&self, patterns: Vec<LearnedPattern>)
pub fn load_learned_patterns(&self, patterns: Vec<LearnedPattern>)
Load learned patterns from persistence.
Sourcepub fn trajectories_by_verdict(&self, verdict: Verdict) -> Vec<Trajectory>
pub fn trajectories_by_verdict(&self, verdict: Verdict) -> Vec<Trajectory>
Get trajectories filtered by verdict.