Engram is an event-sourced memory system for AI agents. It uses a two-layer design where the episode log is the source of truth and any derived structures (graphs, indices) are materialized views that can be rebuilt from scratch.
Existing AI memory systems (Graphiti, Memento, etc.) couple write reliability to LLM API availability by performing entity extraction at write time. This creates fragile systems where:
Engram solves this by keeping the episode store as the foundation — no LLM in the write path. Every write succeeds if the database is up.
INSTALL vss;
LOAD vss;
CREATE TABLE episodes (
id VARCHAR PRIMARY KEY,
content TEXT NOT NULL,
name VARCHAR,
source VARCHAR NOT NULL,
source_model VARCHAR,
source_description TEXT,
group_id VARCHAR DEFAULT 'default',
tags VARCHAR[],
embedding FLOAT[768],
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
valid_at TIMESTAMP,
expired_at TIMESTAMP,
metadata JSON
);
-- Vector similarity index (HNSW)
CREATE INDEX idx_episodes_embedding ON episodes USING HNSW (embedding);
-- Standard indices for common query patterns
CREATE INDEX idx_episodes_created_at ON episodes (created_at DESC);
CREATE INDEX idx_episodes_group_id ON episodes (group_id);
CREATE INDEX idx_episodes_valid_at ON episodes (valid_at);
CREATE INDEX idx_episodes_expired_at ON episodes (expired_at);
CREATE INDEX idx_episodes_source ON episodes (source);
nomic-embed-text, 768 dimensions)Three search modes, selectable via the search_mode parameter:
content and name fields. No embedding required — works even when the embeddings server is down.All modes support additional filters:
created_at, valid_at, expired_at rangesWhen a search query is received in vector or hybrid mode, the query text is embedded and results are ranked by array_cosine_similarity(). If embedding generation fails (e.g., the embeddings server is down), vector search falls back to chronological ordering and hybrid degrades to keyword-only.
Every stored vector is stamped with the model that produced it (embedding_model column on episodes, entities, and knowledge). A row is stale when its embedding is missing (the embedding server was down at write time) or was produced by a model other than the one currently configured — both silently degrade vector search because different models occupy different vector spaces.
Engram warns at startup when stale embeddings exist and exposes POST /api/v1/admin/reembed to regenerate them asynchronously in place. Embeddings are pure derived data, so the pass never touches episode content; it is idempotent and resumable (keyset pagination, per-row failures are skipped and retried on the next run). {"force": true} regenerates every row regardless of provenance. Progress is observable via GET /api/v1/admin/reembed and /api/v1/status.
A periodic batch process that reads episodes and builds entity/relationship structures. Not currently implemented. The episode store alone with semantic search provides the majority of the value.
When built:
Go service using the official MCP SDK, exposing tools over SSE:
| Tool | Description | LLM Required |
|---|---|---|
add_memory |
Store a new episode | No |
search |
Semantic + temporal + tag search | No |
get_episodes |
Retrieve by time range, source, or group | No |
update_episode |
Modify metadata/tags/expiration | No |
get_status |
Health check | No |
Episodes can be marked as expired but not deleted. This prevents accidental memory loss.
Engram uses a server-first architecture to avoid DuckDB’s single-writer file lock:
engram serve (default) — HTTP server owning the DuckDB database, exposing MCP over SSE at /mcp/sse, REST API at /api/v1/*, health probes at /health and /ready. This is the only process that touches the database.engram stdio — Thin stateless proxy that bridges stdin/stdout JSON-RPC to the server via SSE. For clients that don’t support SSE natively (e.g., Claude Desktop). Uses mcp-go/client/transport.SSE for robust endpoint discovery and session management.SSE is the primary transport. Clients that support it (Cursor, Claude Code) connect directly to http://localhost:3490/mcp/sse. The stdio proxy is a compatibility shim for clients that only speak stdio.
/v1/embeddings server — LM Studio, Ollama, vLLM, llama.cpp, or hosted providers; local generation means no external API costsENGRAM_PORT)Native binary:
Single executable + DuckDB file. Run engram serve as a background service. See MCP Integration Guide for platform-specific instructions.
Docker container:
Multi-stage build using Debian Bookworm (glibc compatibility). See the Dockerfile.
Kubernetes:
Deployment with PersistentVolume for the .duckdb file. Requires ingress configuration for SSE support (no buffering, long timeouts).
group_id supports multiple users/contextsFLOAT[768] (tied to nomic-embed-text)