use crate::{MemoryError, Result};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum MemoryLayer {
ShortTerm,
Episodic,
Procedural,
Semantic,
}
impl MemoryLayer {
#[must_use]
pub fn table(self) -> &'static str {
match self {
Self::ShortTerm => "short_term",
Self::Episodic => "episodic",
Self::Procedural => "procedural",
Self::Semantic => "semantic",
}
}
pub fn from_table(name: &str) -> Result<Self> {
match name {
"short_term" => Ok(Self::ShortTerm),
"episodic" => Ok(Self::Episodic),
"procedural" => Ok(Self::Procedural),
"semantic" => Ok(Self::Semantic),
other => Err(MemoryError::UnknownLayer(other.to_string())),
}
}
}
#[derive(Debug, Clone)]
pub struct Record {
pub id: String,
pub text: String,
pub layer: MemoryLayer,
pub score: f32,
}
impl Record {
#[must_use]
pub fn similarity(&self) -> f32 {
(1.0 - self.score).clamp(0.0, 1.0)
}
}
#[derive(Debug, Clone, Default)]
pub struct AgentStats {
pub short_term: usize,
pub episodic: usize,
pub procedural: usize,
pub semantic: usize,
}
impl AgentStats {
#[must_use]
pub fn total(&self) -> usize {
self.short_term + self.episodic + self.procedural + self.semantic
}
}