Storage Engines
EngramDB supports multiple storage backends to accommodate different use cases. This document explains the available storage engines and how to use them effectively.Overview of Storage Engines
EngramDB provides two main storage engines:- Memory Storage Engine: Volatile in-memory storage for testing and development
- File Storage Engine: Persistent file-based storage for production use
- Saving memory nodes
- Loading memory nodes
- Deleting memory nodes
- Listing all available memory nodes
Memory Storage Engine
The Memory Storage Engine stores all data in RAM, making it fast but volatile. It’s ideal for:- Development and testing
- Short-lived applications
- Scenarios where persistence isn’t required
Creating a Memory Storage Engine
Rust Example
Python Example
Characteristics
- Speed: Very fast operations
- Persistence: None (data is lost when the application terminates)
- Scalability: Limited by available RAM
- Concurrency: Not thread-safe by default
File Storage Engine
The File Storage Engine stores data on disk, providing persistence. It’s suitable for:- Production applications
- Long-lived data
- Scenarios where data must survive application restarts
Creating a File Storage Engine
Rust Example
Python Example
Characteristics
- Speed: Slower than memory storage but still efficient
- Persistence: Data survives application restarts
- Scalability: Limited by available disk space
- Concurrency: Basic file locking for safety
File Storage Structure
The File Storage Engine organizes data as follows:Choosing a Storage Engine
Consider these factors when choosing a storage engine:| Factor | Memory Storage | File Storage |
|---|---|---|
| Speed | Very fast | Moderate |
| Persistence | None | Yes |
| Memory Usage | High | Low to moderate |
| Durability | None | Good |
| Use Case | Development, testing | Production |
Advanced Usage
Custom Configuration
You can customize the database configuration:Initialization
When using file storage, you should initialize the database to load existing memories into the vector index:Migrating Between Storage Engines
You can migrate data from one storage engine to another:Implementation Details
StorageEngine Trait
Both storage engines implement theStorageEngine trait:
Memory Storage Implementation
The Memory Storage Engine uses a simple HashMap to store memory nodes:File Storage Implementation
The File Storage Engine serializes memory nodes to JSON files:Best Practices
Memory Storage
- Use for development, testing, and ephemeral applications
- Be aware that all data will be lost when the application terminates
- Monitor memory usage for large datasets
File Storage
- Use for production applications where persistence is required
- Always call
initialize()after creating a file-based database - Implement regular backups of the storage directory
- Consider file system performance characteristics
General Recommendations
- Choose the appropriate storage engine based on your requirements
- Initialize file-based databases to load existing memories
- Implement error handling for storage operations
- Consider implementing a custom storage engine for specialized needs
Future Storage Engines
Future versions of EngramDB may include additional storage engines:- Database Storage Engine: Integration with SQL or NoSQL databases
- Distributed Storage Engine: Support for clustered deployments
- Encrypted Storage Engine: Enhanced security for sensitive data
- Tiered Storage Engine: Automatic migration between hot and cold storage

