Hebbian memory for AI agents — memories that fire together wire together.
Project description
hebbmem
Hebbian memory for AI agents — memories that fire together wire together.
Install
pip install hebbmem
For higher-quality semantic embeddings:
pip install hebbmem[ml]
Quick Start
from hebbmem import HebbMem
mem = HebbMem()
# Store memories
mem.store("Python is great for data science", importance=0.8)
mem.store("JavaScript runs in the browser", importance=0.5)
mem.store("Neural networks learn from data", importance=0.7)
# Time passes, memories decay
mem.step(5)
# Recall activates related memories through the graph
results = mem.recall("machine learning with Python", top_k=3)
for r in results:
print(f"{r.content} (score={r.score:.3f})")
How It Works
hebbmem replaces flat vector storage with three neuroscience mechanisms:
Decay — Memories fade over time unless reinforced, following the Ebbinghaus forgetting curve. Recent and frequently accessed memories stay strong.
Hebbian Learning — Memories recalled together strengthen their connections. "Neurons that fire together wire together." Over time, the graph learns which memories are related through usage, not just embedding similarity.
Spreading Activation — Recalling one memory activates related ones through the graph, surfacing connections that keyword or vector search alone would miss.
Persistence
Save and restore memory state across sessions:
mem.save("agent_memory.hebb")
# Later...
mem = HebbMem.load("agent_memory.hebb", encoder="hash")
Uses SQLite internally — single file, zero dependencies, crash-safe.
Configuration
from hebbmem import HebbMem, Config
config = Config(
activation_decay=0.9, # how fast activation fades (0-1)
strength_decay=0.999, # how fast long-term strength fades (0-1)
hebbian_lr=0.2, # learning rate for co-activation (0-1)
spread_factor=0.5, # energy spread per hop (0-1)
max_hops=3, # BFS depth for spreading activation
scoring_weights={ # recall ranking formula
"activation": 0.4,
"similarity": 0.35,
"strength": 0.15,
"importance": 0.1,
},
)
mem = HebbMem(encoder="hash", config=config)
Batch Store
ids = mem.store_batch(
["memory one", "memory two", "memory three"],
importances=[0.9, 0.5, 0.3],
)
Thread Safety
All public methods are thread-safe (protected by threading.RLock). Safe to use from multiple threads in agent frameworks.
Logging
hebbmem uses stdlib logging. Enable debug output:
import logging
logging.basicConfig(level=logging.DEBUG)
Examples
See examples/ for runnable scripts:
basic_usage.py— store, decay, recall, forgetagent_integration.py— using hebbmem as an agent's memory backendcustom_config.py— tuning decay, Hebbian learning, and scoring weights
Links
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
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 hebbmem-0.2.0.tar.gz.
File metadata
- Download URL: hebbmem-0.2.0.tar.gz
- Upload date:
- Size: 135.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 |
739cf932e8397728ffdb40fc2b80f1270bc11c5a702c7f31abe4dd906bde42a5
|
|
| MD5 |
f714f0c9d3e3153d5a421130ba62a00f
|
|
| BLAKE2b-256 |
21677fff166015fcba052bae89ac35b12f9ffe760216d7f0aede963c96421c11
|
Provenance
The following attestation bundles were made for hebbmem-0.2.0.tar.gz:
Publisher:
publish.yml on codepawl/hebbmem
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hebbmem-0.2.0.tar.gz -
Subject digest:
739cf932e8397728ffdb40fc2b80f1270bc11c5a702c7f31abe4dd906bde42a5 - Sigstore transparency entry: 1236005350
- Sigstore integration time:
-
Permalink:
codepawl/hebbmem@722b658bb2ec520abd35fc87729e2dc627d6c1ac -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/codepawl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@722b658bb2ec520abd35fc87729e2dc627d6c1ac -
Trigger Event:
push
-
Statement type:
File details
Details for the file hebbmem-0.2.0-py3-none-any.whl.
File metadata
- Download URL: hebbmem-0.2.0-py3-none-any.whl
- Upload date:
- Size: 18.3 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 |
a0b84b2e8e3d27b3c66c37b08e534b66c9d997833fda699db161323bc80d4ff6
|
|
| MD5 |
11c8088fec79e3945951cd935528baea
|
|
| BLAKE2b-256 |
a294f0573be036b6ff0ddc9b5bde376c87de58c4b88cca7a063045bd202868b9
|
Provenance
The following attestation bundles were made for hebbmem-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on codepawl/hebbmem
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hebbmem-0.2.0-py3-none-any.whl -
Subject digest:
a0b84b2e8e3d27b3c66c37b08e534b66c9d997833fda699db161323bc80d4ff6 - Sigstore transparency entry: 1236005351
- Sigstore integration time:
-
Permalink:
codepawl/hebbmem@722b658bb2ec520abd35fc87729e2dc627d6c1ac -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/codepawl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@722b658bb2ec520abd35fc87729e2dc627d6c1ac -
Trigger Event:
push
-
Statement type: