Engram-Mem
Dual-memory AI system combining episodic (vector) + semantic (graph) memory with LLM reasoning. Entity-gated ingestion ensures only meaningful data is stored. Enterprise-ready with multi-tenancy, auth, caching, observability, and Docker deployment.
Works with any AI agent or IDE — Claude Code, OpenClaw, Cursor, and any MCP-compatible client. Federates with external knowledge systems (mem0, LightRAG, Graphiti) via auto-discovery. Exposes CLI, MCP (stdio), HTTP API (/api/v1/), and WebSocket (/ws) interfaces.
pip install engram-memFeatures
Core Memory
Episodic Memory — Qdrant vector store (embedded or server), semantic similarity search, Ebbinghaus decay, activation-based scoring, topic-key upsert
Semantic Graph — NetworkX MultiDiGraph, typed entities and relationships, SQLite (default) or PostgreSQL backend, weighted edges
Reasoning Engine — LLM synthesis (Gemini via litellm), dual-memory context fusion, constitution-guarded prompts
Recall Pipeline — Query decision, temporal+pronoun entity resolution, parallel multi-source search, dedup, composite scoring
Entity-Gated Ingestion — Only stores messages with extracted entities; skips noise (system prompts, trivial messages)
Auto Memory — Detect and persist save-worthy messages automatically, poisoning guard for injection prevention
Meeting Ledger — Structured meeting records with decisions, action items, attendees, topics
Feedback Loop — Confidence scoring (+0.15/-0.2), importance adjustment, auto-delete on 3x negative feedback
Graph Visualization — Interactive entity relationship explorer with dark theme, search, click-to-inspect (vis-network)
Intelligence Layer
Temporal Resolution — 28 Vietnamese+English date patterns resolve "hom nay/yesterday" to ISO dates before storing
Pronoun Resolution — "anh ay/he/she" to named entity from graph context, LLM-based fallback
Fusion Formatter — Group recall results by type
[preference]/[fact]/[lesson]for structured LLM contextMemory Consolidation — Jaccard clustering + LLM summarization reduces redundancy
Multi-Agent & Federated Knowledge
Agent Support — Claude Code, OpenClaw, Cursor, any MCP-compatible agent or IDE
Session Capture — Real-time JSONL session watchers for OpenClaw + Claude Code (inotify/watchdog)
Federated Search — Query mem0, LightRAG, Graphiti, custom REST/File/Postgres/MCP providers in parallel
Auto-Discovery — Scans local ports, file paths, and MCP configs (
~/.claude/,~/.cursor/) to find providersProvider Adapters — REST (with JWT auto-login), File (glob patterns), PostgreSQL (custom SQL), MCP (stdio)
Enterprise
Multi-Surface — CLI (Typer), MCP Server (stdio), HTTP API (FastAPI), WebSocket, Web UI
Authentication — JWT + API keys with RBAC (ADMIN, AGENT, READER), optional, disabled by default
Multi-Tenancy — Isolated per-tenant stores, contextvar propagation, row-level PostgreSQL isolation
Caching — Redis-backed result caching with per-endpoint TTLs
Rate Limiting — Sliding-window per-tenant limits,
fail_openoptionAudit Trail — Structured before/after JSONL log for every episodic mutation
Resource Tiers — 4-tier LLM degradation (FULL > STANDARD > BASIC > READONLY), 60s auto-recovery
Data Constitution — 3-law LLM governance (namespace isolation, no fabrication, audit rights), SHA-256 tamper detection
Consolidation Scheduler — Asyncio background tasks (cleanup daily, consolidate 6h, decay daily), tier-aware
Key Rotation — Failover/round-robin for embedding API keys (GEMINI_API_KEY + GEMINI_API_KEY_FALLBACK)
Observability — OpenTelemetry + JSONL audit logging (optional)
Deployment — Docker Compose, Kubernetes-ready, health checks
Backup/Restore — Memory snapshots, point-in-time recovery
Benchmark Suite — p50/p95/p99 latency measurements for all endpoints
Architecture
flowchart TD
subgraph Agents["Agents & IDEs"]
CC["Claude Code"]
OC["OpenClaw"]
CU["Cursor"]
ANY["Any MCP Client"]
end
subgraph Interfaces
CLI["CLI (Typer)"]
MCP["MCP (stdio)"]
HTTP["HTTP API /api/v1/"]
WS["WebSocket /ws"]
end
CC & OC & CU & ANY --> MCP
CLI & MCP & HTTP & WS --> Auth["Auth Middleware\n(JWT + RBAC, optional)"]
Auth --> Tenant["TenantContext (ContextVar)"]
Tenant --> Recall["Recall Pipeline\n(decision > resolve > search > feedback)"]
Recall --> Episodic["EpisodicStore\n(Qdrant)"]
Recall --> Semantic["SemanticGraph\n(NetworkX + SQLite/PG)"]
Recall --> Fed["Federated Providers"]
Episodic & Semantic --> Reasoning["Reasoning Engine\n(Gemini via litellm)"]
Episodic --> Cache["Redis Cache (optional)"]
WS --> EventBus["Event Bus\n(push events)"]
subgraph Fed["Federated Knowledge"]
M0["mem0"]
LR["LightRAG"]
GR["Graphiti"]
REST["REST / File / PG / MCP"]
endQuick Start
# Install from PyPI
pip install engram-mem
# Or from source
git clone https://github.com/docaohieu2808/Engram-Mem.git
cd engram && pip install -e .
# Initialize config
engram init
# Set API key
export GEMINI_API_KEY="your-key"
# Start daemon (background HTTP server + watcher)
engram start
# Store a memory
engram remember "Deployed v2.1 to production at 14:00 - caused 503 spike"
# Search memories
engram recall "production incidents"
# Browse all data (episodic + semantic)
engram dump
# Reason across all memory
engram think "What deployment issues have we had?"Requirements: Python 3.11+, GEMINI_API_KEY for LLM reasoning and embeddings. Basic storage works without it.
Integrations
Claude Code (MCP)
Add to ~/.claude.json:
{
"mcpServers": {
"engram": {
"command": "engram-mcp",
"env": { "GEMINI_API_KEY": "your-key" }
}
}
}Cursor (MCP)
Add to Cursor's MCP settings — engram auto-discovers Cursor's config at ~/.cursor/settings.json:
{
"mcpServers": {
"engram": {
"command": "engram-mcp",
"env": { "GEMINI_API_KEY": "your-key" }
}
}
}OpenClaw
Install the engram skill, then enable session watcher in ~/.engram/config.yaml:
capture:
openclaw:
enabled: true
sessions_dir: ~/.openclaw/workspace/sessionsFederated Knowledge Providers
Engram auto-discovers and federates with external memory systems. Supported providers:
Provider | Type | Auto-Discovery |
mem0 | REST | Port 8080, |
LightRAG | REST | Port 9520, |
Graphiti | REST | Port 8000, |
OpenClaw | File |
|
Custom REST | REST | Manual config |
PostgreSQL | SQL | Manual config |
MCP servers | MCP | Scans |
# Auto-discovery (enabled by default)
discovery:
local: true
hosts: ["10.10.0.2"] # additional hosts to scan
# Or manual provider config
providers:
- name: my-mem0
type: rest
url: http://localhost:8080
search_endpoint: /v1/memories/search
search_method: POST
search_body: '{"query": "{query}", "limit": {limit}}'
result_path: "results[].memory"HTTP API
# Start server
engram serve --port 8765
# Store memory
curl -X POST http://localhost:8765/api/v1/remember \
-H "Content-Type: application/json" \
-d '{"content": "Deployed v1.0", "memory_type": "fact", "priority": 8}'
# Search
curl "http://localhost:8765/api/v1/recall?query=deployment&limit=5"
# Reason
curl -X POST http://localhost:8765/api/v1/think \
-H "Content-Type: application/json" \
-d '{"question": "What deployment issues have we had?"}'
# Meeting ledger
curl -X POST http://localhost:8765/api/v1/meeting-ledger \
-H "Content-Type: application/json" \
-d '{"title": "Sprint Review", "decisions": ["Ship v2"], "action_items": ["Update docs"]}'CLI Reference (61 Commands)
Memory Operations
engram remember <content> [--type fact|decision|...] [--priority 1-10]
[--tags tag1,tag2] [--expires 7d] [--topic-key key]
engram recall <query> [--limit 5] [--type <type>] [--tags tag1,tag2]
engram ask <question> # Smart query (auto-routes)
engram think <question> # LLM reasoning
engram summarize [--count 20] [--save]
engram decay [--limit 20] # Ebbinghaus retention curveSemantic Graph
engram add node <name> --type <type>
engram add edge <from> <to> --relation <relation>
engram remove node <key>
engram remove edge <key>
engram query [keyword] [--type X] [--related-to Y] [--format table|json]
engram autolink-orphans [--apply] [--min-co-mentions 3]Browse & Export
engram status # Memory counts
engram dump [--format table|json] # All memories + graph
engram health # Full system health check
engram tui # Terminal UI (interactive browser)
engram graph [--port 8100] # Open visualization browserData Management
engram cleanup # Delete expired memories
engram consolidate [--limit 50] # LLM clustering + summarization
engram ingest <file.json> [--dry-run] # Extract entities + remember
engram backup # Export snapshot
engram restore <file> # Import snapshot
engram migrate <file> # Import legacy JSONSession & Feedback
engram session-start
engram session-end
engram feedback <id> --positive|--negative
engram resolve <query> # Pronoun + temporal resolution
engram audit [--limit 50] # Retrieval audit logServer & Capture
engram init # Zero-config setup
engram start # Start daemon (HTTP server + watcher)
engram stop # Stop daemon
engram logs [--tail 50] # Show logs
engram serve [--host 0.0.0.0] [--port 8765] # Foreground HTTP server
engram watch [--daemon] # Watch inbox + OpenClaw/Claude Code sessionsConfiguration & Setup
engram setup # Interactive IDE connector wizard
engram config show|get <key>|set <key> <value>
engram auth # API key management
engram providers discover # Auto-discover external providers
engram providers list|add|remove # Manage providers
engram schema # Manage semantic schemasMonitoring & Status
engram queue-status # Embedding queue health
engram resource-status # LLM tier (FULL/STANDARD/BASIC/READONLY)
engram constitution-status # 3-law governance + SHA-256
engram scheduler-status # Background task schedule
engram benchmark [--quick] # Run recall accuracy benchmarkDaemon & Advanced
engram autostart # Install systemd user services
engram sync [--direction] # Git-friendly memory sharingMCP Tools (21 Total)
Tool | Description |
| Store episodic memory with type, priority, tags, expires, topic-key |
| Search episodic memories (compact or full) with filtering |
| Retrieve full memory content by ID or 8-char prefix |
| Get chronological context around a memory (±window minutes) |
| Delete all expired memories |
| Deduplicate similar memories by cosine similarity threshold |
| Dual ingest: extract entities + store memories from chat |
| Record positive/negative feedback (adjusts confidence) |
| Auto-detect feedback sentiment from text |
| Reason across episodic + semantic memory via LLM |
| Smart query — auto-routes to recall or think based on intent |
| Summarize recent N memories into insights via LLM |
| Add/update entity node to knowledge graph |
| Add/update relationship edge between entities |
| Query knowledge graph (keyword, type, related-to) |
| Record structured meeting (decisions, action items, attendees) |
| Show memory statistics (episodic count, semantic nodes/edges) |
| Begin new conversation session |
| End active session |
| Get summary of completed session |
| Retrieve memories from active session |
Configuration
Config file: ~/.engram/config.yaml — Priority: CLI flags > env vars > YAML > defaults
episodic:
mode: embedded # embedded (Qdrant in-process) or server
path: ~/.engram/qdrant
namespace: default
embedding:
provider: gemini
model: gemini-embedding-001
key_strategy: failover # failover or round-robin
semantic:
provider: sqlite # or postgresql
path: ~/.engram/semantic.db
llm:
provider: gemini
model: gemini/gemini-2.0-flash
api_key: ${GEMINI_API_KEY}
serve:
host: 127.0.0.1
port: 8765
capture:
openclaw:
enabled: false
sessions_dir: ~/.openclaw/workspace/sessions
claude_code:
enabled: false
sessions_dir: ~/.claude/projects
auth:
enabled: false
cache:
enabled: false
redis_url: redis://localhost:6379/0
rate_limit:
enabled: false
audit:
enabled: false
path: ~/.engram/audit.jsonlAPI Reference
Start server: engram serve [--host 0.0.0.0] [--port 8765]
Health & Info:
Method | Endpoint | Purpose |
GET |
| Liveness check |
GET |
| Readiness probe |
GET |
| Interactive graph UI |
Core Operations (/api/v1/):
Method | Endpoint | Purpose |
POST |
| Store episodic memory |
GET |
| Search memories ( |
POST |
| LLM reasoning across episodic + semantic |
GET |
| Graph search ( |
POST |
| Extract entities + store memories |
POST |
| Record structured meeting |
POST |
| Record memory feedback |
Memory Management (/api/v1/):
Method | Endpoint | Purpose |
GET |
| List/filter with pagination |
GET |
| Get single memory |
PUT |
| Update memory |
DELETE |
| Delete memory |
GET |
| Export all as JSON |
POST |
| Batch delete |
Semantic Graph (/api/v1/):
Method | Endpoint | Purpose |
GET |
| Graph data (nodes + edges) for vis.js |
POST |
| Add/update node |
PUT |
| Update node |
DELETE |
| Delete node |
POST |
| Add/update edge |
DELETE |
| Delete edge |
GET |
| Feedback history |
Admin (/api/v1/):
Method | Endpoint | Purpose |
POST |
| Delete expired memories |
POST |
| Deduplicate memories |
POST |
| Get JWT token |
GET |
| List active providers |
GET |
| Retrieval audit log |
GET |
| Scheduler status |
POST |
| Run task now |
POST |
| Run benchmark |
GET |
| Get config |
PUT |
| Update config |
GET |
| Memory statistics |
WebSocket API
Connect via ws://host:8765/ws?token=JWT (token optional when auth disabled).
Commands:
Command | Payload |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Push Events: memory_created, memory_updated, memory_deleted, feedback_recorded
Environment Variables
Variable | Purpose |
| LLM + embeddings (primary key) |
| Secondary key for key rotation |
| Memory namespace isolation |
| Enable JWT auth |
|
|
| Enable Redis caching |
| Enable audit logs |
| Enable OpenTelemetry |
Docker
# Quick start
docker build -t engram:latest .
docker run -e GEMINI_API_KEY="your-key" -p 8765:8765 engram:latest
# Production with PostgreSQL + Redis
ENGRAM_AUTH_ENABLED=true \
ENGRAM_SEMANTIC_PROVIDER=postgresql \
ENGRAM_SEMANTIC_DSN=postgresql://user:pass@postgres:5432/engram \
ENGRAM_CACHE_ENABLED=true \
ENGRAM_CACHE_REDIS_URL=redis://redis:6379/0 \
docker compose upTesting
pytest tests/ -v # All tests
pytest tests/ --cov=src/engram # With coverage
pytest tests/ -k "recall or feedback" # Specific suites894+ tests, 61%+ code coverage, CI/CD via GitHub Actions.
Documentation
License
MIT — Copyright (c) Do Cao Hieu
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/docaohieu2808/Engram-Mem'
If you have feedback or need assistance with the MCP directory API, please join our Discord server