1use anyhow::Result;
4use serde::{Deserialize, Serialize};
5use std::collections::HashMap;
6use std::time::{Duration, SystemTime};
7use uuid::Uuid;
8
9use crate::Vector;
10
11#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct ContentItem {
14 pub id: String,
16 pub content_type: String,
18 pub content: String,
20 pub metadata: HashMap<String, String>,
22 pub priority: ProcessingPriority,
24 pub created_at: SystemTime,
26 pub expires_at: Option<SystemTime>,
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
32pub enum ProcessingPriority {
33 Low,
35 Normal,
37 High,
39 Critical,
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
45pub enum ProcessingStatus {
46 Pending,
48 Processing,
50 Completed,
52 Failed { reason: String },
54 Retried { attempt: usize },
56}
57
58#[derive(Debug, Clone)]
60pub struct ProcessingResult {
61 pub item: ContentItem,
63 pub vector: Option<Vector>,
65 pub status: ProcessingStatus,
67 pub duration: Duration,
69 pub error: Option<String>,
71 pub metadata: HashMap<String, String>,
73}
74
75pub trait EmbeddingGenerator: Send + Sync {
77 fn generate_embedding(&self, content: &ContentItem) -> Result<Vector>;
79
80 fn generate_batch_embeddings(&self, content: &[ContentItem]) -> Result<Vec<ProcessingResult>>;
82
83 fn embedding_dimensions(&self) -> usize;
85
86 fn get_config(&self) -> serde_json::Value;
88
89 fn is_ready(&self) -> bool;
91
92 fn get_statistics(&self) -> GeneratorStatistics;
94}
95
96#[derive(Debug, Clone, Serialize, Deserialize)]
98pub struct GeneratorStatistics {
99 pub total_embeddings: u64,
101 pub total_processing_time: Duration,
103 pub average_processing_time: Duration,
105 pub error_count: u64,
107 pub last_error: Option<String>,
109}
110
111pub trait IncrementalVectorIndex: Send + Sync {
113 fn upsert_vector(&mut self, id: String, vector: Vector) -> Result<()>;
115
116 fn remove_vector(&mut self, id: &str) -> Result<bool>;
118
119 fn batch_upsert(&mut self, vectors: Vec<(String, Vector)>) -> Result<Vec<Result<()>>>;
121
122 fn get_statistics(&self) -> IndexStatistics;
124
125 fn optimize(&mut self) -> Result<()>;
127
128 fn health_check(&self) -> Result<HealthStatus>;
130}
131
132#[derive(Debug, Clone, Serialize, Deserialize)]
134pub struct IndexStatistics {
135 pub total_vectors: usize,
137 pub memory_usage: u64,
139 pub last_optimization: Option<SystemTime>,
141 pub total_operations: u64,
143 pub error_count: u64,
145}
146
147#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
149pub enum HealthStatus {
150 Healthy,
152 Warning { message: String },
154 Unhealthy { message: String },
156 Unknown,
158}
159
160pub trait AlertHandler: Send + Sync {
162 fn handle_alert(&self, alert: &Alert) -> Result<()>;
164
165 fn get_config(&self) -> AlertConfig;
167
168 fn is_enabled(&self) -> bool;
170}
171
172#[derive(Debug, Clone, Serialize, Deserialize)]
174pub struct Alert {
175 pub id: Uuid,
177 pub severity: AlertSeverity,
179 pub category: AlertCategory,
181 pub message: String,
183 pub details: HashMap<String, String>,
185 pub timestamp: SystemTime,
187 pub source: String,
189}
190
191#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
193pub enum AlertSeverity {
194 Info,
196 Warning,
198 Error,
200 Critical,
202}
203
204#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
206pub enum AlertCategory {
207 Performance,
209 Quality,
211 Health,
213 Security,
215 Configuration,
217}
218
219#[derive(Debug, Clone, Serialize, Deserialize)]
221pub struct AlertConfig {
222 pub min_severity: AlertSeverity,
224 pub throttling: AlertThrottling,
226 pub enable_notifications: bool,
228}
229
230#[derive(Debug, Clone, Serialize, Deserialize)]
232pub struct AlertThrottling {
233 pub enabled: bool,
235 pub window_duration: Duration,
237 pub max_alerts_per_window: usize,
239}
240
241pub trait MetricsStorage: Send + Sync {
243 fn store_metric(
245 &mut self,
246 name: &str,
247 value: f64,
248 timestamp: SystemTime,
249 tags: HashMap<String, String>,
250 ) -> Result<()>;
251
252 fn get_metrics(
254 &self,
255 name: &str,
256 start: SystemTime,
257 end: SystemTime,
258 ) -> Result<Vec<MetricPoint>>;
259
260 fn get_metric_names(&self) -> Result<Vec<String>>;
262
263 fn cleanup_old_metrics(&mut self, cutoff: SystemTime) -> Result<usize>;
265}
266
267#[derive(Debug, Clone, Serialize, Deserialize)]
269pub struct MetricPoint {
270 pub value: f64,
272 pub timestamp: SystemTime,
274 pub tags: HashMap<String, String>,
276}
277
278pub trait VersionStorage: Send + Sync {
280 fn store_version(&mut self, id: &str, version: &Version) -> Result<()>;
282
283 fn get_version(&self, id: &str, version_number: u64) -> Result<Option<Version>>;
285
286 fn get_all_versions(&self, id: &str) -> Result<Vec<Version>>;
288
289 fn cleanup_old_versions(&mut self, id: &str, keep_count: usize) -> Result<usize>;
291}
292
293#[derive(Debug, Clone, Serialize, Deserialize)]
295pub struct Version {
296 pub version: u64,
298 pub vector: Vector,
300 pub created_at: SystemTime,
302 pub metadata: HashMap<String, String>,
304 pub checksum: String,
306}
307
308pub trait ConflictResolutionFunction: Send + Sync {
310 fn resolve_conflict(&self, versions: &[Version]) -> Result<Vector>;
312
313 fn get_strategy_name(&self) -> &str;
315}
316
317pub trait TransactionLog: Send + Sync {
319 fn log_transaction(&mut self, transaction: &Transaction) -> Result<()>;
321
322 fn get_transactions(&self, start: SystemTime, end: SystemTime) -> Result<Vec<Transaction>>;
324
325 fn replay_from(&self, checkpoint: SystemTime) -> Result<Vec<Transaction>>;
327}
328
329#[derive(Debug, Clone, Serialize, Deserialize)]
331pub struct Transaction {
332 pub id: Uuid,
334 pub transaction_type: TransactionType,
336 pub resource_id: String,
338 pub timestamp: SystemTime,
340 pub data: serde_json::Value,
342 pub status: TransactionStatus,
344}
345
346#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
348pub enum TransactionType {
349 Insert,
351 Update,
353 Delete,
355 Batch,
357}
358
359#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
361pub enum TransactionStatus {
362 Pending,
364 Committed,
366 RolledBack,
368 Failed { reason: String },
370}
371
372pub trait InconsistencyDetectionAlgorithm: Send + Sync {
374 fn detect_inconsistencies(&self) -> Result<Vec<Inconsistency>>;
376
377 fn get_algorithm_name(&self) -> &str;
379}
380
381#[derive(Debug, Clone, Serialize, Deserialize)]
383pub struct Inconsistency {
384 pub inconsistency_type: InconsistencyType,
386 pub affected_resources: Vec<String>,
388 pub description: String,
390 pub severity: InconsistencySeverity,
392 pub detected_at: SystemTime,
394}
395
396#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
398pub enum InconsistencyType {
399 DataMismatch,
401 MissingData,
403 DuplicateData,
405 StaleData,
407 CorruptedData,
409}
410
411#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
413pub enum InconsistencySeverity {
414 Low,
416 Medium,
418 High,
420 Critical,
422}
423
424pub trait ConsistencyRepairStrategy: Send + Sync {
426 fn repair_inconsistencies(
428 &self,
429 inconsistencies: &[Inconsistency],
430 ) -> Result<Vec<RepairResult>>;
431
432 fn get_strategy_name(&self) -> &str;
434}
435
436#[derive(Debug, Clone, Serialize, Deserialize)]
438pub struct RepairResult {
439 pub inconsistency: Inconsistency,
441 pub status: RepairStatus,
443 pub actions: Vec<String>,
445 pub repaired_at: SystemTime,
447}
448
449#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
451pub enum RepairStatus {
452 Success,
454 PartialSuccess,
456 Failed { reason: String },
458 Skipped { reason: String },
460}