Cognitive memory engine for AI agents — human-inspired retrieval via activation, competition, and reconstruction
Project description
OpenMem
Deterministic memory engine for AI agents. Retrieves context via BM25 lexical search, graph-based spreading activation, and human-inspired competition scoring. SQLite-backed, zero dependencies.
How it works
Query → FTS5/BM25 (lexical trigger)
→ Seed Activation
→ Spreading Activation (graph edges, max 2 hops)
→ Recency + Strength + Confidence weighting
→ Competition (score-based ranking)
→ Context Pack (token-budgeted output)
No vectors, no embeddings, no LLM in the retrieval loop. The LLM is the consumer, not the retriever.
Install
pip install openmem-engine
Or from source:
git clone https://github.com/yourorg/openmem.git
cd openmem
pip install -e ".[dev]"
Quick start
from openmem import MemoryEngine
engine = MemoryEngine() # in-memory, or MemoryEngine("memories.db") for persistence
# Store memories
m1 = engine.add("We chose SQLite over Postgres for simplicity", type="decision", entities=["SQLite", "Postgres"])
m2 = engine.add("Postgres has better concurrent write support", type="fact", entities=["Postgres"])
# Link related memories
engine.link(m1.id, m2.id, "supports")
# Recall
results = engine.recall("Why did we pick SQLite?")
for r in results:
print(f"{r.score:.3f} | {r.memory.text}")
# 0.800 | We chose SQLite over Postgres for simplicity
# 0.500 | Postgres has better concurrent write support
Claude Code plugin
One command to add persistent memory to Claude Code:
uvx openmem-engine install
That's it. Claude now has 7 memory tools (memory_store, memory_recall, memory_link, memory_reinforce, memory_supersede, memory_contradict, memory_stats) it can call automatically across sessions.
Memories persist in ~/.openmem/memories.db by default (override with the OPENMEM_DB env var).
Usage with an LLM agent
engine = MemoryEngine("project.db")
# Agent stores what it learns
engine.add("User prefers TypeScript over JavaScript", type="preference", entities=["TypeScript", "JavaScript"])
engine.add("Auth system uses JWT with 24h expiry", type="decision", entities=["JWT", "auth"])
engine.add("The /api/users endpoint returns 500 on empty payload", type="incident", entities=["/api/users"])
# Before each LLM call, recall relevant context
results = engine.recall("set up authentication", top_k=5, token_budget=2000)
context = "\n".join(r.memory.text for r in results)
prompt = f"""Relevant context from previous work:
{context}
User request: {user_message}"""
API
MemoryEngine(db_path=":memory:", **config)
| Method | Description |
|---|---|
add(text, type="fact", entities=None, confidence=1.0, gist=None) |
Store a memory |
link(source_id, target_id, rel_type, weight=0.5) |
Create an edge between memories |
recall(query, top_k=5, token_budget=2000) |
Retrieve relevant memories |
reinforce(memory_id) |
Boost a memory's strength |
supersede(old_id, new_id) |
Mark a memory as outdated |
contradict(id_a, id_b) |
Flag two memories as contradicting |
decay_all() |
Run decay pass over all memories |
stats() |
Get summary statistics |
Memory types
fact · decision · preference · incident · plan · constraint
Edge types
mentions · supports · contradicts · depends_on · same_as
Retrieval model
Recency — Exponential decay with ~14-day half-life. Recently accessed memories surface first.
Strength — Reinforced on access, decays naturally over time. Frequently recalled memories persist.
Spreading activation — Memories linked by edges activate their neighbors. A query hitting one memory pulls in related context up to 2 hops away.
Competition — Final score combines activation (50%), recency (20%), strength (20%), and confidence (10%). Superseded memories are penalized 50%, contradicted ones 70%.
Conflict resolution — When two contradicting memories both activate, the weaker one (by strength × confidence × recency) gets demoted.
Tests
pip install -e ".[dev]"
pytest tests/ -v
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openmem_engine-0.4.0.tar.gz.
File metadata
- Download URL: openmem_engine-0.4.0.tar.gz
- Upload date:
- Size: 310.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81d835c971fcf5da08912f9c1457bba95981fbed0b68e5890b49c788346a3fb7
|
|
| MD5 |
50be58e2696964cee18f08644d371503
|
|
| BLAKE2b-256 |
054f33609dcecd627b2ea9faf287ae30b63a3b30813d6ed6b2381a8995098121
|
Provenance
The following attestation bundles were made for openmem_engine-0.4.0.tar.gz:
Publisher:
publish.yml on dunkinfrunkin/OpenMem
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openmem_engine-0.4.0.tar.gz -
Subject digest:
81d835c971fcf5da08912f9c1457bba95981fbed0b68e5890b49c788346a3fb7 - Sigstore transparency entry: 962175311
- Sigstore integration time:
-
Permalink:
dunkinfrunkin/OpenMem@16bece69dca1eed64284cb1ccf7fffe197ea02fa -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/dunkinfrunkin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@16bece69dca1eed64284cb1ccf7fffe197ea02fa -
Trigger Event:
release
-
Statement type:
File details
Details for the file openmem_engine-0.4.0-py3-none-any.whl.
File metadata
- Download URL: openmem_engine-0.4.0-py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07429526f5dad767d5975dd8777843bcf91b99767bf341fe06ef9cc6734d6b9b
|
|
| MD5 |
45acdcc8ba225bb7f7f31f4bfba63484
|
|
| BLAKE2b-256 |
5f54e5a7ebc1655a5d59d35bf0e86a004c2b7d1a4f8b8ed9b2f8f26993fc8099
|
Provenance
The following attestation bundles were made for openmem_engine-0.4.0-py3-none-any.whl:
Publisher:
publish.yml on dunkinfrunkin/OpenMem
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openmem_engine-0.4.0-py3-none-any.whl -
Subject digest:
07429526f5dad767d5975dd8777843bcf91b99767bf341fe06ef9cc6734d6b9b - Sigstore transparency entry: 962175314
- Sigstore integration time:
-
Permalink:
dunkinfrunkin/OpenMem@16bece69dca1eed64284cb1ccf7fffe197ea02fa -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/dunkinfrunkin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@16bece69dca1eed64284cb1ccf7fffe197ea02fa -
Trigger Event:
release
-
Statement type: