do-memory-core
Version: v0.1.13 | Production-ready core episodic learning system for AI agents
Overview
do-memory-core provides the foundation for building AI agents that learn from their execution history. It implements a complete episode lifecycle (start → execute → score → learn → retrieve) with intelligent pattern extraction, semantic embeddings, and spatiotemporal indexing.
Key Features
- Episodic Memory: Complete episode lifecycle with detailed step logging and reward scoring
- Pattern Recognition: Automatic extraction of ToolSequences, DecisionPoints, ErrorRecovery, and ContextPatterns
- Intelligent Reward Scoring: Sophisticated multi-factor scoring with efficiency, complexity, and quality bonuses
- Smart Reflection: Generate actionable insights and improvement recommendations from completed episodes
- Semantic Embeddings: Optional multi-provider semantic search (OpenAI, Cohere, Ollama, local)
- Spatiotemporal Indexing: Location and time-aware memory retrieval with k-d tree optimization
- Dual Storage: Seamless integration with Turso/libSQL (durable) and redb (cache) backends
- Async Pattern Learning: Queue-based pattern extraction with worker pool and backpressure handling
- Monitoring: Comprehensive metrics and performance tracking
Module Breakdown
| Module | LOC | Purpose |
|---|---|---|
patterns |
5,319 | Pattern extraction, recognition, and learning algorithms |
embeddings |
5,250 | Semantic search and vector embeddings with multi-provider support |
memory |
4,457 | Core memory operations and episode management |
spatiotemporal |
3,377 | Spatiotemporal indexing with k-d tree optimization |
reflection |
1,950 | Reflection generation and insight extraction |
pre_storage |
1,618 | Pre-storage processing and data preparation |
monitoring |
1,358 | Metrics, telemetry, and performance monitoring |
Total: ~23,326 LOC across 7 core modules
Feature Flags
Enable optional embedding providers via Cargo features:
# Individual providers
= { = "0.1", = ["openai"] }
= { = "0.1", = ["mistral"] }
= { = "0.1", = ["local-embeddings"] }
# All providers
= { = "0.1", = ["embeddings-full"] }
Key Capabilities
Episodic Memory Management
- Start, track, and complete episodes with full context
- Detailed execution step logging with timestamps
- Multi-factor reward scoring (outcome, efficiency, complexity, quality, learning)
- Automatic reflection generation with insights and recommendations
Pattern Recognition
- Extract 4 pattern types: ToolSequence, DecisionPoint, ErrorRecovery, ContextPattern
- Pattern similarity matching for relevant experience retrieval
- Reward-based pattern learning and improvement
- Frequency and success rate tracking
Semantic Search (Optional)
- Multi-provider embeddings: OpenAI, Mistral, local CPU-based
- Vector similarity search for context-aware retrieval
- Automatic embedding generation and caching
- Batch processing for efficiency
Spatiotemporal Indexing
- Location-aware memory retrieval
- Time-based context queries
- k-d tree optimized nearest neighbor search
- Geospatial distance calculations
Monitoring & Metrics
- Performance tracking for all operations
- Cache hit/miss statistics
- Operation latency metrics
- Memory usage monitoring
Quick Start
Add this to your Cargo.toml:
[]
= "0.1"
= "0.1"
= "0.1"
Basic Usage
use ;
async
With Semantic Embeddings
[]
= { = "0.1", = ["openai"] }
// Semantic search automatically enabled when embeddings feature is active
let relevant = memory.retrieve_relevant_context.await?;
// Results ranked by semantic similarity
Core Concepts
Episodes
An episode represents a complete task execution with:
- Unique ID and timestamps
- Task context (language, domain, tags, optional location)
- Execution steps with tool usage and outcomes
- Reward score and reflection upon completion
- Extracted patterns for future learning
- Optional semantic embeddings
Patterns
Four types of patterns are automatically extracted:
- ToolSequence: Common sequences of tool usage
- DecisionPoint: Critical decision moments and their outcomes
- ErrorRecovery: Successful error handling strategies
- ContextPattern: Recurring contextual features
Reward & Reflection
Episodes are scored based on:
- Base reward from outcome (success/partial/failure)
- Efficiency multiplier (time + step count)
- Complexity bonus (task difficulty)
- Quality multipliers (code quality, test coverage, error handling)
- Learning bonuses (diverse tools, pattern usage, error recovery)
Reflections include:
- Success pattern identification
- Improvement opportunity analysis
- Key insight extraction
- Contextual recommendations
Storage Backends
do-memory-core works with two storage backends:
- do-memory-storage-turso: Turso/libSQL for durable, distributed SQL storage
- do-memory-storage-redb: redb for fast embedded key-value caching
Performance
All operations meet or exceed performance targets:
| Operation | Target (P95) | Typical Performance | Speedup |
|---|---|---|---|
| Episode Creation | < 50ms | ~2.5 µs | 19,531x faster |
| Step Logging | < 20ms | ~1.1 µs | 17,699x faster |
| Episode Completion | < 500ms | ~3.8 µs | 130,890x faster |
| Pattern Extraction | < 1000ms | ~10.4 µs | 95,880x faster |
| Memory Retrieval | < 100ms | ~721 µs | 138x faster |
Quality Metrics
- Test Coverage: 92.5% across all modules
- Test Pass Rate: 99.3% (424/427 tests)
- Clippy Warnings: 0 (strictly enforced)
- Code Formatting: 100% rustfmt compliant
Dependencies
Core Dependencies
- tokio: Async runtime
- async-trait: Async trait support
- anyhow: Error handling
- serde: Serialization framework
- postcard: Serialization format
- uuid: Unique identifiers
- chrono: Date/time handling
- tracing: Structured logging
Optional Embedding Dependencies
- openai: OpenAI API embeddings
- mistral: Mistral AI embeddings
- local-embeddings: CPU-based local embeddings
- embeddings-full: All embedding providers (openai + mistral)
Documentation
Comprehensive API documentation is available at docs.rs/do-memory-core.
Additional Documentation
- README_SEMANTIC_EMBEDDINGS.md - Semantic search guide
- QUICK_START_EMBEDDINGS.md - Quick embeddings setup
- OPTIMIZATION_QUICK_REF.md - Performance optimization
Testing
Run the test suite:
With debug logging:
RUST_LOG=debug
License
Licensed under the MIT License. See LICENSE for details.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Project
This crate is part of the rust-self-learning-memory project.
Version: v0.1.13 (Production-ready) Status: Stable, 99.3% test pass rate, 92.5% coverage, 0 clippy warnings