DEV Community

Razmik Ayvazyan
Razmik Ayvazyan

Posted on

I Built an Open-Source Brain for AI Models — Here's How Engram Works

Every AI tool I use forgets everything the moment a session ends. I tell Claude Code about my tech stack, switch to Ollama the next day, and start from zero.

So I built Engram — a persistent memory layer that gives any AI model human-like memory.


What is Engram?

Engram is a universal AI brain. It stores what your AIs learn, retrieves the right memories at the right time, and presents them as context — automatically.

Connect it once and every AI you use shares a single, growing brain.


How it works

When an AI connected to Engram receives a query:

  1. Embeds the query into a 384-dim vector (locally, via ONNX — no API, no cost)
  2. Searches the vector index for similar past memories
  3. Expands via the knowledge graph to related concepts
  4. Scores by similarity + recency + importance + access frequency
  5. Checks for contradictions with existing memories
  6. Injects assembled context into the AI's prompt

The AI responds with full awareness of everything it has ever learned.


Three memory types

Engram mirrors the human brain:

Type What it stores Example
Episodic Events, conversations "User asked about deployment on March 15"
Semantic Facts, knowledge graph concept: TypeScript → "typed superset of JS"
Procedural Patterns, skills "When asked about DB migrations → use drizzle-kit"

The features that set it apart

Memory decay — Uses the Ebbinghaus forgetting curve. Memories that aren't accessed fade over time. Important ones get consolidated from episodes into semantic facts — like sleep consolidation in the brain.

Contradiction detection — When you store "we use PostgreSQL" but there's already a memory saying "we use MongoDB," Engram detects it and offers resolution strategies (keep newest, keep most important, keep both, etc.).

Knowledge graph — Memories aren't just vectors. They form a graph with typed edges (is_a, causes, contradicts, relates_to, etc.). Recall traverses this graph to find context pure vector search would miss.

Plugin system — 6 lifecycle hooks (onStore, onRecall, onForget, onDecay, onStartup, onShutdown). Build extensions without touching core code.


Quick start

# Install the CLI
npm i -g @engram-ai-memory/cli

# Store a memory
engram store "User prefers TypeScript" --type semantic

# Ask the brain
engram recall "What language does the user prefer?" --raw
Enter fullscreen mode Exit fullscreen mode

Claude Code integration

Add to ~/.claude/settings.json:

{
  "mcpServers": {
    "engram": {
      "command": "node",
      "args": ["/path/to/engram/packages/mcp/dist/server.js"],
      "env": {
        "ENGRAM_DB_PATH": "/path/to/engram.db"
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

18 tools appear automatically — store_memory, recall_context, check_contradictions, decay_sweep, and more.


The 3D dashboard

Engram ships with a React Three Fiber visualization dashboard with 5 view modes.

Memories appear as glowing neurons, connections as edges, contradictions in orange. You can store, delete, tag, search, and resolve contradictions directly from the UI.


Architecture

  • @engram-ai-memory/core — The brain engine (NeuralBrain, embeddings, graph, retrieval)
  • @engram-ai-memory/mcp — 18 MCP tools for Claude Code
  • @engram-ai-memory/cli — Terminal interface
  • @engram-ai-memory/vis — 3D visualization helpers

SQLite by default (zero config), PostgreSQL optional for teams.


Performance

Metric Value
Recall latency (100 memories) ~18ms
Store throughput ~120 mem/s
Embedding 8ms/text (local ONNX)
Cached startup (1k memories) ~45ms

Links


MIT licensed. Star it if you find it useful.

PRs welcome — especially new adapters for LM Studio, llama.cpp, and other AI tools.

Top comments (0)