| Crates.io | codex-memory |
| lib.rs | codex-memory |
| version | 3.0.15 |
| created_at | 2025-08-19 21:12:05.496384+00 |
| updated_at | 2025-09-09 16:34:41.194753+00 |
| description | A simple memory storage service with MCP interface for Claude Desktop |
| homepage | https://github.com/Ladvien/codex-memory |
| repository | https://github.com/Ladvien/codex-memory |
| max_upload_size | |
| id | 1802515 |
| size | 985,511 |
A high-performance Rust-based memory storage service designed for reliable content management with advanced extensibility for companion applications. Codex Memory provides deduplicated storage, automatic chunking, and MCP (Model Context Protocol) interface for Claude Desktop integration - all while maintaining a clean, extensible architecture that enables powerful companion applications like Codex-Dreams.
โ ๏ธ Development Notice
This project was developed using AI-assisted iterative coding. While functional and tested, the codebase may contain unconventional patterns or edge cases. We recommend thorough testing in development environments before production use. Contributions and feedback are welcome!
Codex-Dreams is a companion application that adds biological memory modeling and semantic search capabilities to your Codex-stored memories.
What Codex-Dreams Adds:
How They Work Together:
memories tableCodex follows a modular architecture focused on simplicity, reliability, and extensibility:
graph TD
A[Codex CLI] -->|Store/Retrieve| B[(PostgreSQL: memories table)]
C[MCP Server] -->|JSON-RPC 2.0| B
C -->|Claude Desktop| D[AI Assistant Integration]
%% Optional semantic enhancement
E[Codex-Dreams] -.->|Reads & Enhances| B
E -.->|Adds embeddings| F[pgvector similarity search]
B -->|Fast retrieval| G[2ms response time]
B -->|Reliable storage| H[ACID compliance]
style E fill:#f9f,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5
style F fill:#f9f,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Codex Memory Architecture โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โ โ CLI Interface โ โ MCP Server โ โ PostgreSQL โ โ
โ โ โ โ โ โ Database โ โ
โ โ โข store โโโโโบโ โข JSON-RPC 2.0 โโโโโบโ โ โ
โ โ โข get โ โ โข 5 MCP Tools โ โ โข Indexes โ โ
โ โ โข stats โ โ โข stdio I/O โ โ โข ACID โ โ
โ โ โข setup โ โ โ โ โ โ
โ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# Clone the repository
git clone https://github.com/Ladvien/codex-memory.git
cd codex-memory
# Set up environment
cp .env.example .env
# Edit .env with your database credentials
# Install
cargo install --path . --force
# Setup database (creates database, user, and tables)
codex-memory setup
# Run MCP server for Claude Desktop
codex-memory mcp
Install Codex Memory first (provides the storage foundation):
cargo install codex-memory
codex-memory setup --database-url postgresql://user:pass@host:5432/codex_db
Store some memories:
codex-memory store "Your content here" --context "Meeting notes" --summary "Team sync"
Install Codex-Dreams for semantic enhancement:
git clone https://github.com/Ladvien/codex-dreams.git
cd codex-dreams
pip install -e .
# Configure to use the same database
cp .env.example .env # Edit DATABASE_URL to match your Codex database
Run semantic processing:
# Generate embeddings for existing memories
python -m codex_dreams.process_memories
Use enhanced features:
# Verify Codex is working
codex-memory stats
# Check if Codex-Dreams extensions are present (optional)
psql $DATABASE_URL -c "\d memories"
# Look for embedding_vector column if Codex-Dreams is installed
Create a .env file with:
DATABASE_URL=postgresql://codex_user:codex_pass@localhost:5432/codex_db
RUST_LOG=info # Optional: debug, info, warn, error
# Store content with metadata
codex-memory store "Your content here" \
--context "Meeting notes" \
--summary "Q4 planning discussion" \
--tags "meeting,planning,q4"
# Retrieve content by ID
codex-memory get <UUID>
# View storage statistics
codex-memory stats
# Run MCP server for Claude Desktop
codex-memory mcp
For the full cognitive memory experience, use both applications together:
# 1. Store memories with Codex Memory (fast, reliable)
codex-memory store "Research findings on neural networks" \
--context "AI Research" \
--summary "Key insights from latest papers" \
--tags "ai,research,neural-networks"
# 2. Generate insights with Codex-Dreams (AI-powered analysis)
codex-dreams generate-insights --time-period week
codex-dreams show-insights --limit 5
codex-dreams search-insights "neural networks" --limit 10
๐ก Workflow Tip: Use Codex Memory for day-to-day storage and retrieval, then run Codex-Dreams periodically to generate insights and discover patterns across your stored memories.
The search_memory tool provides intelligent 3-stage progressive search that automatically finds results without manual threshold tuning:
Progressive Search Stages:
Search Strategies:
Configurable Parameters:
query: Search text (required)tag_filter: Filter results by specific tagssimilarity_threshold: Minimum similarity score (0.0-1.0, default: 0.7)max_results: Maximum results to return (default: 10)search_strategy: TagsFirst, ContentFirst, or Hybrid (default)boost_recent: Apply recency boost to newer memoriestag_weight / content_weight: Customize scoring balance (default: 0.4/0.6)use_tag_embedding / use_content_embedding: Enable/disable embedding typesProgressive Search Benefits:
The search leverages existing embeddings from Codex-Dreams when available, with intelligent fallback to PostgreSQL full-text search.
Codex provides 6 MCP tools:
| Tool | Description | Parameters |
|---|---|---|
store_memory |
Store text with metadata | content, context, summary, tags |
search_memory |
Progressive 3-stage search with automatic fallback | query, tag_filter, similarity_threshold, max_results, search_strategy, and more |
get_memory |
Retrieve by ID | id (UUID) |
delete_memory |
Remove by ID | id (UUID) |
get_statistics |
Get storage stats | none |
store_file |
Chunk and store files | file_path, chunk_size, overlap, tags |
Add to your Claude Desktop config:
{
"mcpServers": {
"codex-memory": {
"command": "/path/to/codex-memory",
"args": ["mcp"],
"env": {
"DATABASE_URL": "postgresql://codex_user:codex_pass@localhost:5432/codex_db"
}
}
}
}
use codex_memory::{Storage, Config, create_pool};
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create connection pool
let config = Config::from_env()?;
let pool = create_pool(&config.database_url).await?;
let storage = Arc::new(Storage::new(pool));
// Store content
let id = storage.store(
"Content to store",
"Context information".to_string(),
"Brief summary".to_string(),
Some(vec!["tag1".to_string(), "tag2".to_string()])
).await?;
// Retrieve content
if let Some(memory) = storage.get(id).await? {
println!("Retrieved: {}", memory.content);
}
Ok(())
}
CREATE TABLE memories (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
content TEXT NOT NULL,
content_hash VARCHAR(64) NOT NULL UNIQUE,
context TEXT NOT NULL,
summary TEXT NOT NULL,
metadata JSONB DEFAULT '{}',
tags TEXT[] DEFAULT '{}',
chunk_index INTEGER DEFAULT NULL,
total_chunks INTEGER DEFAULT NULL,
parent_id UUID DEFAULT NULL,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW()
);
The memories table can be optionally extended by companion applications like Codex-Dreams:
-- Core Codex schema (always present - shown above)
-- Optional extensions added by Codex-Dreams (ignored by Codex)
ALTER TABLE memories ADD COLUMN IF NOT EXISTS embedding_vector vector(768); -- For similarity search
ALTER TABLE memories ADD COLUMN IF NOT EXISTS semantic_cluster INTEGER; -- For cognitive grouping
ALTER TABLE memories ADD COLUMN IF NOT EXISTS importance_score FLOAT; -- For memory ranking
ALTER TABLE memories ADD COLUMN IF NOT EXISTS last_accessed TIMESTAMPTZ; -- For access patterns
-- Extensions don't affect Codex operations - all original commands work unchanged
Important Notes:
# Run all tests
cargo test
# Run with output
cargo test -- --nocapture
# Run specific test suite
cargo test integration
cargo test unit
cargo test edge_cases
# Run with coverage (requires cargo-tarpaulin)
cargo tarpaulin --out Html
| Operation | Performance | Notes |
|---|---|---|
| Store (small) | ~5ms | Including deduplication |
| Store (chunked) | ~10ms/chunk | 8KB chunks |
| Retrieve | ~2ms | By UUID |
| Delete | ~3ms | Single operation |
| Statistics | ~15ms | Aggregate query |
When using applications like Codex-Dreams that extend the schema:
Extended schemas require additional storage:
# Development build
cargo build
# Release build (optimized)
cargo build --release
# Run clippy lints
cargo clippy -- -D warnings
# Format code
cargo fmt
# Security audit
cargo audit
codex-memory/
โโโ src/
โ โโโ main.rs # CLI entry point
โ โโโ lib.rs # Library exports
โ โโโ storage.rs # Core storage logic
โ โโโ models.rs # Data structures
โ โโโ database/ # Database operations
โ โโโ mcp_server/ # MCP protocol implementation
โ โโโ chunking.rs # File chunking logic
โโโ tests/
โ โโโ unit/ # Unit tests
โ โโโ integration/ # Integration tests
โ โโโ edge_cases/ # Edge case tests
โโโ migrations/ # Database migrations
Yes! Codex stores data in a standard PostgreSQL table that other applications can read from and extend. Popular companion applications include:
No. Well-designed companion applications like Codex-Dreams only ADD columns to the memories table and never modify or remove existing data. Your Codex CLI and MCP server continue working exactly as before.
Companion apps use PostgreSQL's ALTER TABLE ADD COLUMN to add their specific fields. For example:
-- Codex-Dreams adds optional columns for semantic search
ALTER TABLE memories ADD COLUMN IF NOT EXISTS embedding_vector vector(768);
These columns are ignored by Codex but enable advanced features in the companion app.
Extensions are typically just additional columns that can be safely removed:
-- Example: Remove Codex-Dreams extensions (optional)
ALTER TABLE memories DROP COLUMN IF EXISTS embedding_vector;
ALTER TABLE memories DROP COLUMN IF EXISTS semantic_cluster;
-- Your core Codex data remains intact
While the recommended setup is to share the database, you can configure Codex-Dreams to periodically sync from your Codex database if needed. See the Codex-Dreams documentation for sync configuration.
No. Codex Memory is fully functional on its own. Companion applications are optional enhancements that add specialized features when you need them.
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)This project is licensed under the MIT License - see the LICENSE file for details.
๐ก Pro Tip: Maximize your memory system by using both applications together. Codex Memory handles fast storage and retrieval, while Codex-Dreams adds intelligent analysis and insights generation.