OpenMemory Rust SDK
Report Bug • Request Feature Local-first long-term memory engine for AI apps and agents. Self-hosted. Explainable. Scalable.
A Rust port of the OpenMemory JavaScript SDK with native performance.
Quick Start
Add to your Cargo.toml:
[]
= "0.1"
= { = "1", = ["full"] }
use ;
async
That's it. You're now running a fully local cognitive memory engine 🎉
Features
✅ Local-first - Runs entirely on your machine, zero external dependencies ✅ Multi-sector memory - Episodic, Semantic, Procedural, Emotional, Reflective ✅ Memory decay - Adaptive forgetting with sector-specific rates ✅ Waypoint graph - Associative recall paths via BFS expansion ✅ Hybrid search - Vector similarity + keyword filtering ✅ Zero config - Works out of the box with sensible defaults ✅ Native performance - Rust-powered speed and memory safety
Configuration
Basic Configuration
use ;
use PathBuf;
let config = builder
.db_path
.tier
.embedding_kind
.build;
let mem = new.await?;
Embedding Providers
Synthetic (Testing/Development)
let config = builder
.embedding_kind
.build;
OpenAI (Recommended for Production)
let config = builder
.embedding_kind
.openai_key
.openai_model
.build;
Gemini
let config = builder
.embedding_kind
.gemini_key
.build;
Ollama (Fully Local)
let config = builder
.embedding_kind
.ollama_url
.ollama_model
.build;
AWS Bedrock
Enable the aws feature in Cargo.toml:
[]
= { = "0.1", = ["aws"] }
let config = builder
.embedding_kind
.build;
// Uses AWS credentials from environment or ~/.aws/credentials
Performance Tiers
| Tier | Vector Dim | Description |
|---|---|---|
Fast |
256 | Optimized for speed, lower precision |
Smart |
384 | Balanced performance and accuracy (default) |
Deep |
1536 | Maximum accuracy, slower |
Hybrid |
384 | Adaptive with keyword filtering |
use Tier;
let config = builder
.tier
.build;
API Reference
add(content, options)
Store a new memory.
use AddOptions;
let result = mem.add.await?;
println!;
println!;
query(query, options)
Search for relevant memories using the HSG (Hybrid Similarity Graph) algorithm.
use QueryOptions;
let results = mem.query.await?;
for r in results
get_all(limit, offset)
Retrieve all memories with pagination.
let memories = mem.get_all.await?;
println!;
delete(id)
Remove a memory by ID.
mem.delete.await?;
reinforce(id, boost)
Boost a memory's salience score.
mem.reinforce.await?;
run_decay()
Process memory decay based on time elapsed.
let stats = mem.run_decay.await?;
println!;
Cognitive Sectors
OpenMemory automatically classifies content into 5 cognitive sectors:
| Sector | Description | Examples | Decay Rate |
|---|---|---|---|
| Episodic | Time-bound events & experiences | "Yesterday I attended a conference" | Medium (0.015) |
| Semantic | Timeless facts & knowledge | "Paris is the capital of France" | Very Low (0.005) |
| Procedural | Skills, procedures, how-tos | "To deploy: build, test, push" | Low (0.008) |
| Emotional | Feelings, sentiment, mood | "I'm excited about this project!" | High (0.02) |
| Reflective | Meta-cognition, insights | "I learn best through practice" | Very Low (0.001) |
use Sector;
// Query specific sectors
let results = mem.query.await?;
HSG Query Algorithm
The Hybrid Similarity Graph (HSG) combines multiple signals for retrieval:
final_score = sigmoid(
0.40 × vector_similarity +
0.20 × token_overlap +
0.15 × waypoint_weight +
0.15 × recency_score +
0.10 × tag_match +
keyword_boost (Hybrid tier)
)
Features:
- Sector penalties for cross-sector retrieval
- BFS waypoint expansion for associative recall
- Feedback learning with EMA score updates
Environment Variables
| Variable | Description | Default |
|---|---|---|
OM_DB_PATH |
Database file path | :memory: |
OM_TIER |
Performance tier | smart |
OM_EMBEDDING |
Embedding provider | synthetic |
OM_VEC_DIM |
Vector dimensions | Tier default |
OPENAI_API_KEY |
OpenAI API key | - |
GEMINI_API_KEY |
Gemini API key | - |
Examples
Run the basic usage example:
Performance
Benchmarks on Apple M1:
| Operation | Time |
|---|---|
| Synthetic embed | ~0.5ms |
| Add memory | ~2ms |
| Query (1k memories) | ~15ms |
| Decay batch (1k) | ~50ms |
Run benchmarks:
Feature Flags
| Feature | Description |
|---|---|
aws |
Enable AWS Bedrock embedding provider |
[]
= { = "0.1", = ["aws"] }
Minimum Supported Rust Version
Rust 1.70 or later.
License
MIT License - see LICENSE for details.
Contributing
Contributions are welcome! Please read our contributing guidelines before submitting PRs.
# Run tests
# Run clippy
# Format code