Skip to main content

Neuroscience-grounded memory system for AI agents with semantic search and auto-fallback

Project description

Engram AI ๐Ÿง 

Neuroscience-grounded memory for AI agents โ€” ACT-R activation, Hebbian learning, cognitive consolidation

License Python PyPI

Give your AI agent a brain that actually remembers, associates, and forgets like a human.

Available in 3 runtimes:

Runtime Package Use When
๐Ÿ Python engramai on PyPI Python agents, MCP server, Claude Desktop
๐Ÿฆ€ Rust engramai on crates.io โ€” GitHub Performance-critical, embedded, zero-dependency
๐Ÿ“ฆ TypeScript engram-ts/ Node.js agents, OpenClaw
๐Ÿ”Œ OpenClaw Plugin openclaw-plugin/ Drop-in replacement for OpenClaw's default context engine

What is Engram?

Most AI agents use a dumb FIFO window for context โ€” keep the last N messages, throw away the rest. Engram replaces this with a cognitive memory system based on how human brains actually work:

  • ๐Ÿง  ACT-R Activation โ€” Memories strengthen with use, decay with time (not a fixed window)
  • ๐Ÿ”— Hebbian Learning โ€” "Neurons that fire together, wire together" โ€” related memories auto-associate
  • ๐Ÿ’ค Consolidation โ€” Periodic forgetting + strengthening cycles (like sleep)
  • ๐ŸŽฏ Working Memory โ€” Miller's Law 7ยฑ2 chunks, automatic topic-change detection
  • ๐ŸŒ Cross-Language Search โ€” Recall memories across 50+ languages
  • ๐Ÿ’ฐ Zero Cost โ€” Heuristic capture + prompt caching = $0 additional spend

๐Ÿ”Œ OpenClaw Context Engine Plugin

The fastest way to use Engram โ€” replace OpenClaw's default FIFO context with cognitive scoring in one config line:

# openclaw.yaml
plugins:
  slots:
    contextEngine: engram
  entries:
    engram:
      autoCapture: true

Instead of keeping the last N messages, Engram scores every message by ACT-R activation ร— Hebbian association ร— content importance, then packs the most cognitively relevant ones into the token budget. Long-term memories persist across sessions automatically.

Default (Legacy) Engram
Strategy Keep last N messages (FIFO) Score by cognitive relevance
Long-term memory None ACT-R + Hebbian
Cross-session Compaction summaries (LLM cost) Persistent recall (zero cost)
Topic awareness None Working memory + topic detection
Auto-capture None Preferences, facts, decisions, corrections
Cost LLM summarization tokens Zero (heuristic)

โ†’ Full plugin docs | Source


๐Ÿ† Battle-Tested in Production

Real numbers from a live AI agent running 24/7:

Metric Value
Memories stored 3,846
Recalls served 230,103
Hebbian links formed 12,510 (automatic)
Consolidation layers 320 working โ†’ 224 core โ†’ 3,302 archive
Database size 48 MB
Recall latency ~90ms
Additional cost $0 (prompt caching absorbs overhead)

Quick Start

Python

pip install engramai
from engram import Memory

memory = Memory("./my-agent.db")

# Store
memory.add("User prefers detailed explanations", type="relational", importance=0.8)
memory.add("Project deadline: Feb 10", type="factual")

# Recall (ACT-R activation + Hebbian association + semantic similarity)
results = memory.recall("user preferences", limit=5)

# Consolidate (Ebbinghaus forgetting + strengthening)
memory.consolidate(days=1.0)

TypeScript

import { Memory } from 'neuromemory-ai';

const memory = new Memory('./my-agent.db');

memory.add("User prefers TypeScript over JavaScript", { type: "preference", importance: 0.8 });

const results = memory.recall("user language preferences", { limit: 5 });

Rust

use engramai::Memory;

let mut memory = Memory::new("./my-agent.db", None)?;

memory.add("User prefers Rust for systems programming", "preference", 0.8, None)?;

let results = memory.recall("user preferences", 5, None, None)?;

MCP Server (Claude Desktop, etc.)

export ENGRAM_DB_PATH=./my-agent.db
python3 -m engram.mcp_server

Core Concepts

๐Ÿง  ACT-R Activation

Every memory has an activation level that decays over time but strengthens with each access:

activation = base_level + spreading + importance_boost

base_level = ln(ฮฃ tแตข^(-d))    # frequency ร— recency decay
spreading  = ฮฃ wโฑผ ร— Sโฑผแตข       # context similarity

This means frequently-accessed, recent memories surface first โ€” but old important memories can still be recalled if they're relevant to the current context.

๐Ÿ”— Hebbian Learning

Memories that are recalled together form automatic associations:

ฮ”W = ฮท ร— aแตข ร— aโฑผ    # co-activation strengthens links

Ask about "Docker" and "deployment" in the same conversation โ†’ they become linked. Next time you ask about deployment, Docker memories get boosted automatically.

๐Ÿ’ค Consolidation

Like human sleep, periodic consolidation:

  1. Decays weak memories (Ebbinghaus forgetting curve)
  2. Strengthens frequently-used ones (move working โ†’ core โ†’ long-term)
  3. Prunes noise (below-threshold memories removed)

๐ŸŽฏ Working Memory (TypeScript / OpenClaw Plugin)

Session-level state based on Miller's Law (7ยฑ2 chunks):

  • Tracks what's "active" in the current conversation
  • Detects topic changes โ†’ triggers full recall
  • Continuous topic โ†’ reuses cached memories (70-80% fewer DB queries)

๐Ÿงฉ Memory Types

Type Use For Example
factual Facts and knowledge "Project uses Python 3.12"
episodic Events "Shipped v2.0 on Jan 15"
preference User preferences "Prefers concise answers"
procedural How-to knowledge "Deploy: run tests first, then push"
semantic Concepts and relationships "Causal inference relates to Pearl"
causal Cause-effect relationships "Rate hikes โ†’ USD strengthens"

Architecture

Query
  โ†“
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Vector Search (semantic)โ”‚  โ† optional embedding provider
โ”‚  FTS5 Search (lexical)   โ”‚  โ† always available, zero-cost
โ”‚  Merge & Dedupe          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
           โ†“
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  ACT-R Activation        โ”‚  โ† frequency ร— recency decay
โ”‚  Hebbian Spreading       โ”‚  โ† association boost from linked memories
โ”‚  Importance Weighting    โ”‚  โ† user-set priority
โ”‚  Confidence Scoring      โ”‚  โ† metacognition layer
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
           โ†“
     Ranked Results

Configuration

Embedding Providers

Engram works without any embedding provider (FTS5 keyword search). Add one for cross-language semantic search:

Provider Cost Setup Best For
None / FTS5 Free Zero config Simple agents, testing
Sentence Transformers Free pip install "engramai[sentence-transformers]" Privacy, offline
Ollama Free Ollama + embedding model Already using Ollama
OpenAI ~$0.0001/query OPENAI_API_KEY Highest quality

Environment Variables

Variable Default Description
ENGRAM_EMBEDDING auto Provider: auto, sentence-transformers, ollama, openai, none
ENGRAM_DB_PATH ./engram.db Database path
ENGRAM_ST_MODEL paraphrase-multilingual-MiniLM-L12-v2 Sentence Transformers model
OPENAI_API_KEY โ€” Required for OpenAI embeddings

CLI

neuromem add "User prefers dark mode" --type preference --importance 0.8
neuromem recall "user preferences"
neuromem stats
neuromem consolidate
neuromem forget --threshold 0.01
neuromem hebbian "dark mode"

๐Ÿ“š Documentation


Development

git clone https://github.com/tonitangpotato/engram-ai.git
cd engram-ai

# Python
pip install -e ".[dev,all]"
pytest

# TypeScript
cd engram-ts && npm install && npm test

# OpenClaw Plugin
cd openclaw-plugin && npm install && npm test

Credits

Built on research from:

  • ACT-R (Adaptive Control of Thought-Rational) โ€” Anderson, Carnegie Mellon
  • Hebbian Learning โ€” Donald Hebb, 1949
  • Memory Consolidation โ€” Walker & Stickgold (sleep research)
  • Forgetting Curve โ€” Hermann Ebbinghaus, 1885
  • Working Memory โ€” Baddeley & Hitch, 1974
  • Miller's Law โ€” George Miller, 1956 ("The Magical Number Seven")

License

AGPL-3.0-or-later โ€” see LICENSE for details. Commercial licensing available, see COMMERCIAL-LICENSE.md.

GitHub ยท PyPI ยท crates.io ยท Issues

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

engramai-1.1.0.tar.gz (117.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

engramai-1.1.0-py3-none-any.whl (97.0 kB view details)

Uploaded Python 3

File details

Details for the file engramai-1.1.0.tar.gz.

File metadata

  • Download URL: engramai-1.1.0.tar.gz
  • Upload date:
  • Size: 117.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for engramai-1.1.0.tar.gz
Algorithm Hash digest
SHA256 32787b5ffaafd808ad755c7b1b98f7980ed4d03fc000a6df021d36723fb02f48
MD5 2719fd027dd54787839e803cb2af9283
BLAKE2b-256 ae1c910d9ce895bd26ca18387b02ef81e5014c4e23b6f88b3247afc64703b4e1

See more details on using hashes here.

File details

Details for the file engramai-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: engramai-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 97.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for engramai-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9378454e7cf7cf076ad66d91448cb16fb767eab651d069556c81045d02869a67
MD5 ff0aa9c8b1cc2529619a5223ac8defdf
BLAKE2b-256 a0177c296a12045ebb6c1157f892fc1a8a24ea4b2799355c26141a026f2c7606

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page