Skip to main content

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


Download files

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

Source Distribution

openmem_engine-0.2.0.tar.gz (310.5 kB view details)

Uploaded Source

Built Distribution

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

openmem_engine-0.2.0-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file openmem_engine-0.2.0.tar.gz.

File metadata

  • Download URL: openmem_engine-0.2.0.tar.gz
  • Upload date:
  • Size: 310.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for openmem_engine-0.2.0.tar.gz
Algorithm Hash digest
SHA256 bccf5fa6244a63af03a9eee0fbf3ba434dfcf323edee0f4266bd80d5888beb06
MD5 ee00a3d4731df13505b77f0bfd2c5c0a
BLAKE2b-256 9f322fefe0964b4159830a1a8aadb4a812efcecde634edcd55c74b501d3ed65c

See more details on using hashes here.

Provenance

The following attestation bundles were made for openmem_engine-0.2.0.tar.gz:

Publisher: publish.yml on dunkinfrunkin/OpenMem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file openmem_engine-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: openmem_engine-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 15.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for openmem_engine-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bed3fc74d2ff9d9dd0cfb10bfcaac509e28b368bcc9fe986ab9e58f3893c96f1
MD5 d9e4fb397cdb3463ea4fc2581cfbf709
BLAKE2b-256 d60e7d02bde5e7cebdd9d4ca618addeea1e56d4e4e2229ad7ec1c59cb07e76c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for openmem_engine-0.2.0-py3-none-any.whl:

Publisher: publish.yml on dunkinfrunkin/OpenMem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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