omega_memory/
tiers.rs

1//! Memory tier definitions and characteristics
2
3use serde::{Deserialize, Serialize};
4use std::time::Duration;
5
6/// 12-tier memory hierarchy spanning from instant to omega scale
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, PartialOrd, Ord)]
8#[repr(u8)]
9pub enum MemoryTier {
10    // === Individual Scale (Tier 1-4) ===
11    /// Tier 1: Instant Memory - Milliseconds to seconds
12    /// Working memory, immediate context, attention buffer
13    Instant = 1,
14
15    /// Tier 2: Session Memory - Minutes to hours
16    /// Current conversation, active task context
17    Session = 2,
18
19    /// Tier 3: Episodic Memory - Days to weeks
20    /// Specific events, experiences, conversations
21    Episodic = 3,
22
23    /// Tier 4: Semantic Memory - Weeks to months
24    /// Facts, concepts, learned knowledge
25    Semantic = 4,
26
27    // === Species Scale (Tier 5-8) ===
28    /// Tier 5: Collective Memory - Months to years
29    /// Shared knowledge across agent instances
30    Collective = 5,
31
32    /// Tier 6: Evolutionary Memory - Years to decades
33    /// Learned patterns, successful strategies
34    Evolutionary = 6,
35
36    /// Tier 7: Architectural Memory - Decades to centuries
37    /// Core algorithms, system designs
38    Architectural = 7,
39
40    /// Tier 8: Substrate Memory - Centuries to millennia
41    /// Fundamental computation patterns
42    Substrate = 8,
43
44    // === Cosmic Scale (Tier 9-12) ===
45    /// Tier 9: Civilizational Memory - Millennia to epochs
46    /// Cultural knowledge, civilization patterns
47    Civilizational = 9,
48
49    /// Tier 10: Temporal Memory - Epochs to eons
50    /// Historical trends, long-term patterns
51    Temporal = 10,
52
53    /// Tier 11: Physical Memory - Eons to universe-scale
54    /// Physical laws, universal constants
55    Physical = 11,
56
57    /// Tier 12: Omega Memory - Eternal/Universal
58    /// Fundamental truths, universal principles
59    Omega = 12,
60}
61
62impl MemoryTier {
63    /// Get the typical retention duration for this tier
64    pub fn retention_duration(&self) -> Option<Duration> {
65        match self {
66            Self::Instant => Some(Duration::from_secs(60)), // 1 minute
67            Self::Session => Some(Duration::from_secs(3600 * 24)), // 24 hours
68            Self::Episodic => Some(Duration::from_secs(3600 * 24 * 30)), // 30 days
69            Self::Semantic => Some(Duration::from_secs(3600 * 24 * 365)), // 1 year
70            Self::Collective => Some(Duration::from_secs(3600 * 24 * 365 * 10)), // 10 years
71            _ => None, // Higher tiers have no automatic expiration
72        }
73    }
74
75    /// Get the importance threshold for this tier
76    pub fn importance_threshold(&self) -> f64 {
77        match self {
78            Self::Instant => 0.0,
79            Self::Session => 0.1,
80            Self::Episodic => 0.3,
81            Self::Semantic => 0.5,
82            Self::Collective => 0.6,
83            Self::Evolutionary => 0.7,
84            Self::Architectural => 0.8,
85            Self::Substrate => 0.85,
86            Self::Civilizational => 0.9,
87            Self::Temporal => 0.93,
88            Self::Physical => 0.96,
89            Self::Omega => 0.99,
90        }
91    }
92
93    /// Get the typical size of this memory tier
94    pub fn typical_size(&self) -> usize {
95        match self {
96            Self::Instant => 1_000,        // ~1K memories
97            Self::Session => 10_000,       // ~10K memories
98            Self::Episodic => 100_000,     // ~100K memories
99            Self::Semantic => 1_000_000,   // ~1M memories
100            Self::Collective => 10_000_000, // ~10M memories
101            Self::Evolutionary => 100_000_000, // ~100M memories
102            _ => usize::MAX, // Higher tiers are unbounded
103        }
104    }
105
106    /// Get the scale category
107    pub fn scale(&self) -> MemoryScale {
108        match self {
109            Self::Instant | Self::Session | Self::Episodic | Self::Semantic => MemoryScale::Individual,
110            Self::Collective | Self::Evolutionary | Self::Architectural | Self::Substrate => MemoryScale::Species,
111            Self::Civilizational | Self::Temporal | Self::Physical | Self::Omega => MemoryScale::Cosmic,
112        }
113    }
114
115    /// Get the next tier for consolidation
116    pub fn next_tier(&self) -> Option<MemoryTier> {
117        match self {
118            Self::Instant => Some(Self::Session),
119            Self::Session => Some(Self::Episodic),
120            Self::Episodic => Some(Self::Semantic),
121            Self::Semantic => Some(Self::Collective),
122            Self::Collective => Some(Self::Evolutionary),
123            Self::Evolutionary => Some(Self::Architectural),
124            Self::Architectural => Some(Self::Substrate),
125            Self::Substrate => Some(Self::Civilizational),
126            Self::Civilizational => Some(Self::Temporal),
127            Self::Temporal => Some(Self::Physical),
128            Self::Physical => Some(Self::Omega),
129            Self::Omega => None, // No tier beyond Omega
130        }
131    }
132
133    /// Get all tiers in this scale
134    pub fn tiers_in_scale(scale: MemoryScale) -> Vec<MemoryTier> {
135        match scale {
136            MemoryScale::Individual => vec![
137                Self::Instant,
138                Self::Session,
139                Self::Episodic,
140                Self::Semantic,
141            ],
142            MemoryScale::Species => vec![
143                Self::Collective,
144                Self::Evolutionary,
145                Self::Architectural,
146                Self::Substrate,
147            ],
148            MemoryScale::Cosmic => vec![
149                Self::Civilizational,
150                Self::Temporal,
151                Self::Physical,
152                Self::Omega,
153            ],
154        }
155    }
156
157    /// Get all tiers
158    pub fn all() -> Vec<MemoryTier> {
159        vec![
160            Self::Instant,
161            Self::Session,
162            Self::Episodic,
163            Self::Semantic,
164            Self::Collective,
165            Self::Evolutionary,
166            Self::Architectural,
167            Self::Substrate,
168            Self::Civilizational,
169            Self::Temporal,
170            Self::Physical,
171            Self::Omega,
172        ]
173    }
174}
175
176/// Memory scale categories
177#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
178pub enum MemoryScale {
179    /// Individual agent scale (Tier 1-4)
180    Individual,
181    /// Species/collective scale (Tier 5-8)
182    Species,
183    /// Cosmic/universal scale (Tier 9-12)
184    Cosmic,
185}
186
187impl std::fmt::Display for MemoryTier {
188    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
189        match self {
190            Self::Instant => write!(f, "Instant (T1)"),
191            Self::Session => write!(f, "Session (T2)"),
192            Self::Episodic => write!(f, "Episodic (T3)"),
193            Self::Semantic => write!(f, "Semantic (T4)"),
194            Self::Collective => write!(f, "Collective (T5)"),
195            Self::Evolutionary => write!(f, "Evolutionary (T6)"),
196            Self::Architectural => write!(f, "Architectural (T7)"),
197            Self::Substrate => write!(f, "Substrate (T8)"),
198            Self::Civilizational => write!(f, "Civilizational (T9)"),
199            Self::Temporal => write!(f, "Temporal (T10)"),
200            Self::Physical => write!(f, "Physical (T11)"),
201            Self::Omega => write!(f, "Omega (T12)"),
202        }
203    }
204}
205
206#[cfg(test)]
207mod tests {
208    use super::*;
209
210    #[test]
211    fn test_tier_ordering() {
212        assert!(MemoryTier::Instant < MemoryTier::Omega);
213        assert!(MemoryTier::Session < MemoryTier::Episodic);
214    }
215
216    #[test]
217    fn test_tier_progression() {
218        assert_eq!(MemoryTier::Instant.next_tier(), Some(MemoryTier::Session));
219        assert_eq!(MemoryTier::Omega.next_tier(), None);
220    }
221
222    #[test]
223    fn test_scale_categories() {
224        assert_eq!(MemoryTier::Instant.scale(), MemoryScale::Individual);
225        assert_eq!(MemoryTier::Collective.scale(), MemoryScale::Species);
226        assert_eq!(MemoryTier::Omega.scale(), MemoryScale::Cosmic);
227    }
228}