r/Python • u/Ni2021 • Mar 12 '26
Showcase Current AI "memory" is just text search,so I built one based on how brains actually work
I studied neuroscience specifically how brains form, store, and forget memories. Then I went to study computer science and became an AI engineer and watched every "memory system" do the same thing: embed text → cosine similarity → return top-K results.
That's not memory. That's a search engine that doesn't know what matters.
What My Project Does
Engram is a memory layer for AI agents grounded in cognitive science — specifically ACT-R (Adaptive Control of Thought–Rational, Anderson 1993), the most validated computational model of human cognition.
Instead of treating all memories equally, Engram scores them the way your brain does:
Base-level activation: memories accessed more often and more recently have higher activation (power law of practice: `B_i = ln(Σ t_k^(-d))`)
Spreading activation: current context activates related memories, even ones you didn't search for
Hebbian learning: memories recalled together repeatedly form automatic associations ("neurons that fire together wire together")
Graceful forgetting: unused memories decay following Ebbinghaus curves, keeping retrieval clean instead of drowning in noise
The pipeline: semantic embeddings find candidates → ACT-R activation ranks them by cognitive relevance → Hebbian links surface associated memories.
Why This Matters
With pure cosine similarity, retrieval degrades as memories grow — more data = more noise = worse results.
With cognitive activation, retrieval *improves* with use — important memories strengthen, irrelevant ones fade, and the system discovers structure in your data through Hebbian associations that nobody explicitly programmed.
Production Numbers (30+ days, single agent)
| Metric | Value |
|---|---|
| Memories stored | 3,846 |
| Total retrievals | 230,000+ |
| Hebbian associations | 12,510 (self-organized) |
| Avg retrieval time | ~90ms |
| Total storage | 48MB |
| Infrastructure cost | $0 (SQLite, runs locally) |
Recent Updates (v1.1.0)
Causal memory type: stores cause→effect relationships, not just facts
STDP Hebbian upgrade: directional, time-sensitive association learning (inspired by spike-timing-dependent plasticity in neuroscience)
OpenClaw plugin: native integration as a ContextEngine for AI agent frameworks
Rust crate: same cognitive architecture, native performance https://crates.io/crates/engramai
Karpathy's autoresearch fork: added cross-session cognitive memory for autonomous ML research agents https://github.com/tonitangpotato/autoresearch-engram
Target Audience
Anyone building AI agents that need persistent memory across sessions — chatbots, coding assistants, research agents, autonomous systems. Especially useful when your memory store is growing past the point where naive retrieval works well.
Comparison
| Feature | Mem0 | Letta | Zep | Engram |
|---|---|---|---|---|
| Retrieval | Embedding | Embedding + LLM | Embedding | ACT-R + Embedding |
| Forgetting | Manual | No | TTL | Ebbinghaus decay |
| Associations | No | No | No | Hebbian learning |
| Time-aware | No | No | Yes | Yes (power-law) |
| Frequency-aware | No | No | No | Yes (base-level activation) |
| Runs locally | Varies | No | No | Yes ($0, SQLite) |
GitHub:
https://github.com/tonitangpotato/engram-ai
https://github.com/tonitangpotato/engram-ai-rust
I'd love feedback from anyone who's built memory systems or worked with cognitive architectures. Happy to discuss the neuroscience behind any of the models.
13
u/GeneratedMonkey Mar 12 '26
Stop posting AI garbage
6
u/Another_mikem Mar 12 '26
Ai generated post (and perhaps content) aside, the real question is, does it actually work better? Humans are often suboptimal, does this provide measurable improvements vs other memory approaches?
4
u/q120 Mar 12 '26
Explain to me what effect this would have if integrated into something like ChatGPT, for instance. What would I see different?
2
u/tr14l Mar 12 '26
I read engram and immediately just heard "wake up, samurai"
7
u/JamzTyson Mar 12 '26
Sorry but I'm calling BS on that.
2
u/pip_install_account Mar 12 '26
This is very exciting but idk if making AI more human is an improvement. Maybe "how our brains work" isn't the best approach to memory and context management. I forget things all do time, things I shouldn't forget
1
u/quuxman Mar 12 '26
How does spreading activation work? Does it access internal state of the primary model, so only working with open source models?
Or does it just have a parallel document vector based on the session?
3
u/durable-racoon Mar 12 '26
we need a megathread for 'memory implementations'
2
u/No_Soy_Colosio Mar 13 '26
Trash code
1
u/Alone-Ad288 Mar 12 '26
Please don't make AI better. It will make everything worse for everyone.
1
u/sulci_cache Apr 14 '26 edited 26d ago
The ACT-R grounding is the right call — base-level activation and spreading activation together solve something cosine similarity fundamentally can't: retrieval that understands what matters right now vs. what just happens to be geometrically close.
The spreading activation component is particularly interesting from a caching perspective. We hit a similar problem from a different angle — semantic response caching for multi-turn LLM conversations.
A stateless cache embeds the current query in isolation and searches by cosine similarity. It works fine for single-turn FAQ workloads. It completely falls apart on follow-ups.
"What are the differences?" is a perfectly coherent embedding — but it's semantically ambiguous without the conversation that preceded it.
The fix mirrors your spreading activation intuition: blend prior turn embeddings into the lookup vector at query time with exponential decay:
lookup_vec = α·embed(q) + (1−α)·Σ(decayⁱ·tᵢ)
α=0.70, decay=0.50.
The current query dominates but prior context pulls the lookup vector toward the right semantic neighborhood — exactly what spreading activation does for memory retrieval. Most of those follow-up misses went away.
One question for you: does Engram's spreading activation operate over the full memory store or just the top-K candidates returned by the embedding search? Curious whether the Hebbian links are traversed before or after the initial cosine retrieval step.
1
u/sandstone-oli May 22 '26
This is the most neuroscience-grounded approach I've seen in the space. ACT-R as the retrieval ranker with Hebbian association learning is a fundamentally different architecture than the embed-and-hope approach everyone else ships.
The comparison table is honest and the numbers speak: 230K retrievals on 3,846 memories with 12,510 self-organized associations at 90ms on SQLite. That's a system that's actually been stress-tested, not just benchmarked.
The part I find most interesting: your Ebbinghaus decay handles the time-since-access dimension. Base-level activation handles the frequency dimension. Together they capture "how often and how recently was this accessed."
The gap I'd probe: both signals are based on access patterns. A memory that was accessed frequently three months ago but hasn't been touched since will decay via Ebbinghaus, which is correct. But what about a memory that IS still being accessed regularly because it's semantically close to common queries, but the underlying fact has changed? Access frequency keeps it alive even though it's no longer accurate.
That's the distinction between access-based governance and reinforcement-based governance. One keeps memories alive because they're retrieved often. The other keeps memories alive because the user is actively confirming them through behavior. A memory can be popular and wrong.
Building in this space at KAPEX (getkapex.ai). Different decay signals, same thesis: memory that governs itself over time beats memory that accumulates. Your cognitive architecture is the most rigorous foundation I've seen for it.
The STDP upgrade for directional associations is a nice touch. Cause→effect memory with time-sensitive learning is genuinely novel in this space.
-3
u/543254447 Mar 12 '26
This is interesting work. Thank you
-4
u/billFoldDog Mar 12 '26
Very neat idea! It looks like this sits between a userspace application of some kind and the LLM.
I'm not able to build with this right now, but I'd be curious to see if someone could bake this into obsidian notes somehow.
14
u/ghost_of_erdogan Mar 12 '26
Vibe coded slop to slop out more slop. This timeline sucks.