umi_memory/lib.rs
1//! # Umi Memory
2//!
3//! A production-ready memory library for AI agents with deterministic simulation testing.
4//!
5//! ## Features
6//!
7//! - **π§ Smart Memory Management**: Core, working, and archival memory tiers with automatic eviction
8//! - **π Dual Retrieval**: Fast vector search + LLM-powered semantic query expansion
9//! - **π Evolution Tracking**: Automatically detect updates, contradictions, and derived insights
10//! - **β
Graceful Degradation**: System continues operating even when LLM/storage components fail
11//! - **π― Deterministic Testing**: Full DST (Deterministic Simulation Testing) for reproducible fault injection
12//! - **π Production Backends**: LanceDB for embedded vectors, Postgres for persistence
13//!
14//! ## Quick Start
15//!
16//! ```rust
17//! use umi_memory::umi::{Memory, RememberOptions, RecallOptions};
18//!
19//! # #[tokio::main]
20//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
21//! // Create memory with simulation providers (deterministic, seed 42)
22//! let mut memory = Memory::sim(42);
23//!
24//! // Remember information
25//! memory.remember(
26//! "Alice is a software engineer at Acme Corp",
27//! RememberOptions::default()
28//! ).await?;
29//!
30//! // Recall information
31//! let results = memory.recall("Who works at Acme?", RecallOptions::default()).await?;
32//!
33//! for entity in results {
34//! println!("Found: {} - {}", entity.name, entity.content);
35//! }
36//! # Ok(())
37//! # }
38//! ```
39//!
40//! ## Architecture
41//!
42//! ```text
43//! βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
44//! β Memory Orchestrator β
45//! βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
46//! β EntityExtractor β DualRetriever β EvolutionTracker β
47//! βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
48//! β Core Memory (32KB) β Always loaded, persistent β
49//! β Working Memory (1MB) β TTL-based eviction, cache β
50//! β Archival Memory β Vector search + storage β
51//! βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
52//! β DST Framework β Fault injection + simulationβ
53//! βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
54//! ```
55//!
56//! ## Core Components
57//!
58//! - [`Memory`](umi::Memory) - Main orchestrator, coordinates all components
59//! - [`EntityExtractor`](extraction::EntityExtractor) - Extracts structured entities from text
60//! - [`DualRetriever`](retrieval::DualRetriever) - Fast + semantic search with RRF merging
61//! - [`EvolutionTracker`](evolution::EvolutionTracker) - Detects memory evolution patterns
62//!
63//! ## Simulation-First Philosophy
64//!
65//! > "If you're not testing with fault injection, you're not testing."
66//!
67//! Every component has a deterministic simulation implementation:
68//!
69//! ```rust
70//! use umi_memory::dst::{Simulation, SimConfig, FaultConfig, FaultType};
71//!
72//! # #[tokio::test]
73//! # async fn test_example() {
74//! let sim = Simulation::new(SimConfig::with_seed(42))
75//! .with_fault(FaultConfig::new(FaultType::LlmTimeout, 0.1));
76//!
77//! sim.run(|env| async move {
78//! // Test code with deterministic fault injection
79//! // Same seed = same faults = reproducible bugs
80//! Ok::<_, anyhow::Error>(())
81//! }).await.unwrap();
82//! # }
83//! ```
84//!
85//! ## Feature Flags
86//!
87//! - `lance` - LanceDB storage backend
88//! - `postgres` - PostgreSQL storage backend
89//! - `anthropic` - Anthropic LLM provider (Claude)
90//! - `openai` - OpenAI LLM provider (GPT, embeddings)
91//! - `llm-providers` - All LLM providers
92//! - `embedding-providers` - All embedding providers
93//!
94//! ## Examples
95//!
96//! See the [examples directory](https://github.com/rita-aga/umi/tree/main/umi-memory/examples) for:
97//!
98//! - `quick_start.rs` - Basic remember/recall workflow
99//! - `production_setup.rs` - Production configuration
100//! - `configuration.rs` - Custom memory settings
101//!
102//! ## Documentation
103//!
104//! - [GitHub Repository](https://github.com/rita-aga/umi)
105//! - [Architecture Decision Records](https://github.com/rita-aga/umi/tree/main/docs/adr)
106//! - [Development Guide](https://github.com/rita-aga/umi/blob/main/CLAUDE.md)
107
108#![warn(missing_docs)]
109#![warn(clippy::all)]
110#![warn(clippy::pedantic)]
111#![allow(clippy::module_name_repetitions)]
112
113pub mod constants;
114pub mod dst;
115pub mod embedding;
116pub mod evolution;
117pub mod extraction;
118pub mod llm;
119pub mod memory;
120pub mod retrieval;
121pub mod storage;
122pub mod umi;
123
124// Re-export common types
125pub use constants::*;
126pub use dst::{
127 create_simulation,
128 run_property_tests,
129 test_seeds,
130 DeterministicRng,
131 FaultConfig,
132 FaultInjector,
133 FaultType,
134 NetworkError,
135 NetworkMessage,
136 // Property-based testing
137 PropertyTest,
138 PropertyTestFailure,
139 PropertyTestResult,
140 PropertyTestable,
141 SimClock,
142 SimConfig,
143 SimEnvironment,
144 SimNetwork,
145 SimStorage,
146 Simulation,
147 StorageError,
148 TimeAdvanceConfig,
149};
150pub use memory::{
151 ArchivalMemory, ArchivalMemoryConfig, CoreMemory, CoreMemoryConfig, CoreMemoryError,
152 MemoryBlock, MemoryBlockId, MemoryBlockType, WorkingMemory, WorkingMemoryConfig,
153 WorkingMemoryError,
154};
155pub use storage::{Entity, EntityBuilder, EntityType, SimStorageBackend, StorageBackend};
156// Note: storage::StorageError not re-exported to avoid conflict with dst::StorageError
157// Use `umi_memory::storage::StorageError` explicitly if needed
158
159#[cfg(feature = "lance")]
160pub use storage::LanceStorageBackend;
161
162// LLM Provider exports
163pub use llm::{CompletionRequest, LLMProvider, ProviderError, SimLLMProvider};
164
165#[cfg(feature = "anthropic")]
166pub use llm::AnthropicProvider;
167
168#[cfg(feature = "openai")]
169pub use llm::OpenAIProvider;
170
171// Embedding Provider exports
172pub use embedding::{EmbeddingError, EmbeddingProvider, SimEmbeddingProvider};
173
174#[cfg(feature = "embedding-openai")]
175pub use embedding::OpenAIEmbeddingProvider;
176
177// Extraction exports
178pub use extraction::{
179 EntityExtractor, ExtractedEntity, ExtractedRelation, ExtractionError, ExtractionOptions,
180 ExtractionResult,
181};
182// Note: extraction::EntityType and extraction::RelationType not re-exported
183// to avoid conflict with storage::EntityType. Use explicit paths if needed.
184
185// Retrieval exports
186pub use retrieval::{DualRetriever, RetrievalError, SearchOptions, SearchResult};
187
188// Evolution exports
189pub use evolution::{DetectionOptions, DetectionResult, EvolutionError, EvolutionTracker};
190
191// Umi Memory exports (main API)
192pub use umi::{Memory, MemoryError, RecallOptions, RememberOptions, RememberResult};