1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use thiserror::Error;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7#[serde(rename_all = "snake_case")]
8pub enum MemoryKind {
9 Semantic,
11 Procedural,
13}
14
15impl std::fmt::Display for MemoryKind {
16 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17 match self {
18 MemoryKind::Semantic => write!(f, "Semantic"),
19 MemoryKind::Procedural => write!(f, "Procedural"),
20 }
21 }
22}
23
24#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
26#[serde(rename_all = "snake_case")]
27pub enum EntityKind {
28 File,
29 Url,
30 Code,
31 Concept,
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36pub struct Entity {
37 pub id: String,
38 pub name: String,
39 pub kind: EntityKind,
40 pub created_at: DateTime<Utc>,
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
45pub struct MemoryItem {
46 pub id: String,
48 pub kind: MemoryKind,
50 pub key: String,
52 pub content: String,
54 pub confidence: f64,
56 pub created_at: DateTime<Utc>,
58 pub last_reinforced: DateTime<Utc>,
60 pub last_accessed: Option<DateTime<Utc>>,
62 pub contradiction_ref: Option<String>,
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize)]
68pub struct EvidenceLink {
69 pub id: String,
71 pub memory_id: String,
73 pub source_type: String,
75 pub source_ref: String,
77 pub created_at: DateTime<Utc>,
79}
80
81#[derive(Debug, Clone)]
83pub struct RetrievalResult {
84 pub item: MemoryItem,
86 pub evidence: Vec<EvidenceLink>,
88 pub score: f64,
90 pub score_breakdown: String,
92}
93
94#[derive(Debug, Error)]
96pub enum MemoryStoreError {
97 #[error("database operation failed: {0}")]
99 Database(#[from] rusqlite::Error),
100 #[error("invalid timestamp: {0}")]
102 InvalidTimestamp(String),
103 #[error("I/O error: {0}")]
105 Io(#[from] std::io::Error),
106 #[error("maintenance failed: {0}")]
108 Maintenance(String),
109}
110
111#[derive(Debug, Clone, Serialize, Deserialize)]
113pub struct MemoryStatus {
114 pub total_items: usize,
115 pub semantic_count: usize,
116 pub procedural_count: usize,
117 pub evidence_count: usize,
118 pub entity_count: usize,
119 pub db_path: Option<String>,
120 pub db_size_bytes: u64,
121}
122
123#[derive(Debug, Clone, Default)]
125pub struct RetentionPolicy {
126 pub min_confidence: Option<f64>,
127 pub max_age_days: Option<i64>,
128 pub unreinforced_only: bool,
129}
130
131#[derive(Debug, Clone)]
133pub struct RetentionCandidate {
134 pub id: String,
135 pub kind: String,
136 pub key_preview: String,
137 pub confidence: f64,
138 pub last_reinforced: DateTime<Utc>,
139 pub age_days: i64,
140 pub evidence_count: usize,
141 pub reason: String,
142}