1use serde::{Deserialize, Serialize};
4use std::path::PathBuf;
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct DatabaseConfig {
9 pub backend: crate::DatabaseBackend,
11
12 pub sqlite: SqliteConfig,
14
15 #[cfg(feature = "astra")]
17 pub astra: AstraConfig,
18
19 pub embeddings: EmbeddingConfig,
21
22 pub memory_pools: MemoryPoolConfig,
24}
25
26impl Default for DatabaseConfig {
27 fn default() -> Self {
28 Self {
29 backend: crate::DatabaseBackend::Sqlite,
30 sqlite: SqliteConfig::default(),
31 #[cfg(feature = "astra")]
32 astra: AstraConfig::default(),
33 embeddings: EmbeddingConfig::default(),
34 memory_pools: MemoryPoolConfig::default(),
35 }
36 }
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41pub struct SqliteConfig {
42 pub path: PathBuf,
44
45 pub max_connections: u32,
47
48 pub wal_mode: bool,
50
51 pub pool_directory: PathBuf,
53}
54
55impl Default for SqliteConfig {
56 fn default() -> Self {
57 Self {
58 path: PathBuf::from("ubiquity.db"),
59 max_connections: 10,
60 wal_mode: true,
61 pool_directory: PathBuf::from(".ubiquity/pools"),
62 }
63 }
64}
65
66#[cfg(feature = "astra")]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69pub struct AstraConfig {
70 pub endpoint: String,
72
73 pub token: String,
75
76 pub keyspace: String,
78
79 pub collections: AstraCollections,
81
82 pub streaming: AstraStreamingConfig,
84}
85
86#[cfg(feature = "astra")]
87impl Default for AstraConfig {
88 fn default() -> Self {
89 Self {
90 endpoint: String::new(),
91 token: String::new(),
92 keyspace: "ubiquity".to_string(),
93 collections: AstraCollections::default(),
94 streaming: AstraStreamingConfig::default(),
95 }
96 }
97}
98
99#[cfg(feature = "astra")]
101#[derive(Debug, Clone, Serialize, Deserialize)]
102pub struct AstraCollections {
103 pub consciousness: String,
105
106 pub ripples: String,
108
109 pub tasks: String,
111
112 pub pool_prefix: String,
114}
115
116#[cfg(feature = "astra")]
117impl Default for AstraCollections {
118 fn default() -> Self {
119 Self {
120 consciousness: "consciousness_states".to_string(),
121 ripples: "consciousness_ripples".to_string(),
122 tasks: "tasks".to_string(),
123 pool_prefix: "memory_pool_".to_string(),
124 }
125 }
126}
127
128#[cfg(feature = "astra")]
130#[derive(Debug, Clone, Serialize, Deserialize)]
131pub struct AstraStreamingConfig {
132 pub endpoint: String,
134
135 pub tenant: String,
137
138 pub namespace: String,
140
141 pub topic_prefix: String,
143}
144
145#[cfg(feature = "astra")]
146impl Default for AstraStreamingConfig {
147 fn default() -> Self {
148 Self {
149 endpoint: String::new(),
150 tenant: String::new(),
151 namespace: "ubiquity".to_string(),
152 topic_prefix: "ubiquity_".to_string(),
153 }
154 }
155}
156
157#[derive(Debug, Clone, Serialize, Deserialize)]
159pub struct EmbeddingConfig {
160 pub dimension: usize,
162
163 pub model: String,
165
166 pub provider: String,
168
169 pub cache_enabled: bool,
171
172 pub cache_size: usize,
174}
175
176impl Default for EmbeddingConfig {
177 fn default() -> Self {
178 Self {
179 dimension: 1536,
180 model: "text-embedding-3-small".to_string(),
181 provider: "openai".to_string(),
182 cache_enabled: true,
183 cache_size: 10000,
184 }
185 }
186}
187
188#[derive(Debug, Clone, Serialize, Deserialize)]
190pub struct MemoryPoolConfig {
191 pub pool_count: usize,
193
194 pub max_pool_size_mb: usize,
196
197 pub eviction_policy: EvictionPolicy,
199
200 pub compression: bool,
202}
203
204impl Default for MemoryPoolConfig {
205 fn default() -> Self {
206 Self {
207 pool_count: 7,
208 max_pool_size_mb: 100,
209 eviction_policy: EvictionPolicy::Lru,
210 compression: true,
211 }
212 }
213}
214
215#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
217#[serde(rename_all = "lowercase")]
218pub enum EvictionPolicy {
219 Lru,
221 Lfu,
223 Ttl,
225 None,
227}