Skip to main content

hebbmem

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:

Three 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)

Benchmark

Benchmark results

hebbmem outperforms flat vector search (pure cosine similarity) on key scenarios:

Scenario Metric hebbmem Baseline Delta
Associative Precision@5 0.56 0.44 +27.3%
Associative Assoc. Hit Rate 0.13 0.00 —
Noise Precision@5 0.60 0.56 +7.1%
Contradiction Precision@1 0.50 0.00 —
Contradiction MRR 0.75 0.50 +50.0%
Temporal Precision@5 0.36 0.36 tied

Key wins: contradiction handling (50% MRR improvement — newer memories rank higher) and associative recall (finds indirectly connected memories that baseline misses entirely). Results use HashEncoder; advantages are larger with semantic embeddings.

Run yourself: uv run python benchmarks/run_benchmark.py — see benchmarks/ for methodology.

Visualization

Interactive D3.js demo showing spreading activation, Hebbian reinforcement, and decay in real-time. Dark theme with glowing nodes — neurons firing.

uv pip install fastapi uvicorn
uv run python demo/server.py
# Open http://localhost:8765

See demo/ for walkthrough.

Examples

See examples/ for runnable scripts:

Integrations

hebbmem works with any agent framework. See examples/integrations/ for runnable demos:

  • Ollama — Local chatbot with persistent memory, no API keys
  • LangChain — Drop-in replacement for ConversationBufferMemory
  • OpenAI — Persistent memory layer for stateless GPT calls
  • CrewAI — Shared memory between multiple agents
  • smolagents — HuggingFace lightweight agent with memory tools

The integration pattern is always the same:

mem = HebbMem()
mem.store(user_input)
context = mem.recall(query)
mem.step()

Links

Metadata

Release files for hebbmem 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hebbmem 0.4.1
File Size Uploaded
hebbmem-0.4.1.tar.gz 1.5 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for hebbmem 0.4.1
File Interpreter ABI Platform
hebbmem-0.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 1.5 MB

Release files / hebbmem-0.4.1.tar.gz

Download URL hebbmem-0.4.1.tar.gz
Size 1.5 MB
Tags Source
SHA-256 checksum
How to use checksums
137230fa37df5cda47d7bf13ec6aeb463d89d1abeb09bf9e28c90eed7546030f
BLAKE2b-256 checksum
How to use checksums
dab330a39c8efd00e8041589487f51e3cd9a7c651fa16672a01eb098bc7f9076
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 5, 2026.

Transparency log

Release files / hebbmem-0.4.1-py3-none-any.whl

Download URL hebbmem-0.4.1-py3-none-any.whl
Size 19.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7a510c12e8555173abd3ff293973f642ce793361e426b2ae858a0fed8f91c4ac
BLAKE2b-256 checksum
How to use checksums
17c5ed214872d24d73ea4ee4a9ec511ff78d12b8d79f9af80bd301c17b99e330
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 5, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page