Engram is a cognitive memory system for AI agents, inspired by neuroscience (CogMem, A-MEM, claude-engram) and modern retrieval architectures (claude-mem, Memori). It replaces simple markdown-based memory with a scalable LibSQL-backed system featuring native vector search, FTS5, Zettelkasten-style knowledge graphs, and biologically-inspired sleep consolidation.
Target user: AI agent (via CLI) operating within the Antigravity IDE environment.
- Runtime: Node.js 20+
- Database: LibSQL (
@libsql/client) β native vectors (DiskANN), FTS5, SQL - Embeddings: BGE-M3 (
Xenova/bge-m3) via@huggingface/transformersv4 (WASM; WebGPU N/A in Node.js) - Reranker: BGE-reranker-base (
Xenova/bge-reranker-base) β cross-encoder for precision scoring - CLI: Commander.js
- Testing: Node.js built-in test runner (
node:test+node:assert) - LLM (optional): LM Studio API at localhost:1234 (for Extract step in consolidation β not yet implemented)
- Store memories with types: reflex, episode, fact, preference, decision, session_summary
- Each memory has: title, content, embedding (1024-dim), importance, strength (decay), tags
- FTS5 full-text search index synced with main table via triggers
- DiskANN vector index for semantic search
- Exact dedup: same type + title β skip insert, bump access count (0ms, SQL check)
- Semantic merge: cosine > 0.92 with same type β append content to existing memory, re-embed, bump strength
- Auto-link: cosine > 0.70 β create
related_tolink (configurable threshold) - Eliminates most need for sleep-merge; the "think slower, never sleep" approach
- Link memories with typed relations: related_to, caused_by, evolved_from, contradicts, supersedes
- Traverse graph to find related clusters (multi-hop expansion)
- Tags system for categorization
- Semantic search via vector_top_k() + cosine distance
- Full-text search via FTS5 + BM25 ranking
- Hybrid mode: Reciprocal Rank Fusion combining both
- Optional cross-encoder reranking (BGE-reranker-base) for higher precision
- Multi-hop retrieval: follow graph links N hops from search results
- Temporal filter:
--since 1h/1d/7d/30dfor time-bounded queries
- Dynamic context assembly for each query
- Rank by: relevance Γ importance Γ strength Γ recency (composite score)
- Noise gate: composite score < 0.001 dropped; fallback to top-K if gate kills all results
- Token budget control (default 4000 tokens)
- Session context integration
- Memories tagged
permanentare exempt from decay and pruning --permanentflag inaddcommand auto-adds the tag- Recommended for reflexes and user preferences
- Ebbinghaus-inspired forgetting curves (strength decay based on
last_consolidation_at) - Dead memory pruning (strength < 5%, excludes permanent)
- Semantic duplicate merging (cosine > 0.92)
- Pattern extraction via LLM (planned, not yet implemented)
- Active memory boosting (frequently accessed, β₯1 day cooldown)
- Idempotent: safe to run multiple times (decay uses relative timestamps, boost has cooldown)
- Track conversation sessions
- Auto-generate session summaries with embeddings
- Access logging for decay calculations
engram addβ add memory (with dedup/merge)engram getβ get memory by IDengram deleteβ delete memoryengram searchβ semantic/FTS/hybrid search (with --rerank, --hops, --since)engram recallβ Focus of Attention (smart context assembly)engram ingestβ batch-add from JSON (stdin, file, or argument)engram linkβ link two memoriesengram markβ toggle permanent flagengram tagβ add/remove/list tagsengram statsβ memory statisticsengram diagnosticsβ weakest memories, duplicate candidatesengram sessionβ start/end/list sessionsengram sleepβ run consolidation (with --dry-run)engram exportβ export to JSON or Markdownengram migrateβ import from markdown skill artifacts
- Import existing markdown memories (reflexes.md, episodes.md, preferences.md, project_graph.md)
- Auto-embed and auto-tag
- SKILL.md for Antigravity integration
- Auto-load context at session start (session-start.ps1)
- Semantic search during session
- Save workflow on /remember (remember.ps1)
- Batch ingest for efficient multi-memory writes
- Performance: Embedding generation ~500ms per text on CPU. Search < 100ms. Reranker ~35ms per pair
- Storage: Single .db file, < 100MB for typical usage
- Testing: Unit tests for every module using node:test
- Portability: Windows-first (i5-14600KF, DDR5 32GB), works on macOS/Linux
- Privacy: Fully local, no cloud dependencies