Shodh-Memory
Persistent memory for AI agents. Single package. Local-first. Runs offline.
Give your AI agents memory that persists across sessions, learns from experience, and runs entirely on your hardware.
Installation
pip install shodh-memory
That's it. No additional setup required. Models and runtime are bundled.
Quick Start
from shodh_memory import Memory
# Create memory (data stored locally)
memory = Memory(storage_path="./my_agent_data")
# Store memories
memory.remember("User prefers dark mode", memory_type="Decision")
memory.remember("JWT tokens expire after 24h", memory_type="Learning")
memory.remember("Deployment failed due to missing env var", memory_type="Error")
# Search semantically
results = memory.recall("user preferences", limit=5)
for r in results:
print(f"{r['content']} (importance: {r['importance']:.2f})")
# Get context summary for LLM bootstrap
summary = memory.context_summary()
print(summary["decisions"]) # Recent decisions
print(summary["learnings"]) # Recent learnings
Features
- Zero setup — Everything bundled. No API keys, no cloud, no Docker
- Semantic search — MiniLM embeddings for meaning-based retrieval
- Hebbian learning — Connections strengthen when memories are used together
- Activation decay — Unused memories fade naturally
- Idempotent — Content-hash dedup prevents duplicate memories
- Entity extraction — TinyBERT NER extracts people, orgs, locations
- 100% offline — Works on air-gapped systems
Memory Types
Different types get different importance weights:
| Type | Weight | Use for |
|---|---|---|
| Decision | +0.30 | Choices, preferences, conclusions |
| Learning | +0.25 | New knowledge acquired |
| Error | +0.25 | Mistakes to avoid |
| Discovery | +0.20 | Findings, insights |
| Pattern | +0.20 | Recurring behaviors |
| Task | +0.15 | Work items |
| Context | +0.10 | General information |
| Conversation | +0.10 | Chat history |
| Observation | +0.05 | Low-priority notes |
API Reference
Core Memory
# Store a memory
memory.remember(
content="...", # Required: the memory content
memory_type="Learning", # Optional: Decision, Learning, Error, etc.
tags=["tag1", "tag2"], # Optional: for filtering
metadata={"key": "val"} # Optional: custom metadata dict
)
# Semantic search
results = memory.recall(
query="...", # Required: search query
limit=10, # Optional: max results (default: 10)
mode="hybrid" # Optional: semantic, associative, hybrid
)
# Search by tags (no embedding needed, fast)
results = memory.recall_by_tags(tags=["preferences", "ui"], limit=20)
# Search by date range
results = memory.recall_by_date(
start="2025-12-01T00:00:00Z",
end="2025-12-20T23:59:59Z",
limit=20
)
# List all memories
memories = memory.list_memories(limit=100, memory_type="Decision")
# Get single memory by ID
mem = memory.get_memory("uuid-here")
# Get statistics
stats = memory.get_stats()
print(f"Total: {stats['total_memories']}")
Proactive Context (for Agent Loops)
# Surface relevant memories for current context
# Use in every agent loop to maintain context awareness
result = memory.proactive_context(
context="User asking about authentication", # Current conversation/task
semantic_threshold=0.65, # Min similarity (0.0-1.0)
max_results=5, # Max memories to return
auto_ingest=True, # Store context as Conversation memory
recency_weight=0.2 # Boost recent memories
)
# Returns surfaced memories with relevance scores
for mem in result["memories"]:
print(f"{mem['content'][:50]} (score: {mem['relevance_score']:.2f})")
Forget Operations
# Delete by ID
memory.forget("memory-uuid")
# Delete old memories
memory.forget_by_age(days=30)
# Delete low-importance memories
memory.forget_by_importance(threshold=0.3)
# Delete by pattern (regex)
memory.forget_by_pattern(r"test.*")
# Delete by tags
memory.forget_by_tags(["temporary", "draft"])
# Delete by date range (ISO 8601 format)
memory.forget_by_date(start="2025-11-01T00:00:00Z", end="2025-11-30T23:59:59Z")
# GDPR: Delete everything
memory.forget_all()
Context & Introspection
# Context summary for LLM bootstrap
summary = memory.context_summary(max_items=5)
# Returns: {"decisions": [...], "learnings": [...], "context": [...], "patterns": [...]}
# 3-tier memory visualization
state = memory.brain_state(longterm_limit=100)
# Returns: {"working_memory": [...], "session_memory": [...], "longterm_memory": [...], "stats": {...}}
# Memory learning activity report
report = memory.consolidation_report(since="2025-12-19T00:00:00Z")
# Returns: strengthening events, decay events, edge formations, pruned associations
# Raw consolidation events
events = memory.consolidation_events(since="2025-12-19T00:00:00Z")
# Knowledge graph statistics
graph = memory.graph_stats()
print(f"Nodes: {graph['node_count']}, Edges: {graph['edge_count']}")
# Flush to disk
memory.flush()
Index Health & Maintenance
# Verify vector index integrity
report = memory.verify_index()
print(f"Healthy: {report['is_healthy']}, Orphaned: {report['orphaned_count']}")
# Repair orphaned memories (re-index missing entries)
result = memory.repair_index()
print(f"Repaired: {result['repaired']}, Failed: {result['failed']}")
# Get detailed index health metrics
health = memory.index_health()
print(f"Vectors: {health['total_vectors']}, Needs rebuild: {health['needs_rebuild']}")
LLM Framework Integration
LangChain
from shodh_memory.integrations.langchain import ShodhMemory
# Use as LangChain memory
memory = ShodhMemory(storage_path="./langchain_data")
LlamaIndex
from shodh_memory.integrations.llamaindex import ShodhLlamaMemory
# Use as LlamaIndex memory
memory = ShodhLlamaMemory(storage_path="./llamaindex_data")
Performance
Measured on Intel i7-1355U (10 cores, 1.7GHz):
| Operation | Latency |
|---|---|
remember() |
55-60ms |
recall() (semantic) |
34-58ms |
recall_by_tags() |
~1ms |
list_memories() |
~1ms |
Architecture
Experiences flow through three tiers based on Cowan's working memory model:
Working Memory ──overflow──> Session Memory ──importance──> Long-Term Memory
(100 items) (500 MB) (RocksDB)
Cognitive processing:
- Spreading activation retrieval
- Activation decay (exponential)
- Hebbian strengthening (co-retrieval strengthens connections)
- Long-term potentiation (frequently-used connections become permanent)
- Memory replay during maintenance
- Interference detection
Platform Support
| Platform | Status |
|---|---|
| Windows x86_64 | Supported |
| Linux x86_64 | Supported |
| macOS ARM64 (Apple Silicon) | Supported |
| macOS x86_64 (Intel) | Supported |
Links
License
Apache 2.0
Metadata
Release files for shodh-memory 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| shodh_memory-0.2.0.tar.gz | 1.1 MB | Without provenance | Details for shodh_memory-0.2.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| shodh_memory-0.2.0-cp38-abi3-win_amd64.whl | CPython 3.8 | abi3 | Windows x86-64 | Details for shodh_memory-0.2.0-cp38-abi3-win_amd64.whl |
| shodh_memory-0.2.0-cp38-abi3-manylinux_2_28_x86_64.whl | CPython 3.8 | abi3 | Linux glibc 2.28+ x86-64 | Details for shodh_memory-0.2.0-cp38-abi3-manylinux_2_28_x86_64.whl |
| shodh_memory-0.2.0-cp38-abi3-macosx_11_0_arm64.whl | CPython 3.8 | abi3 | macOS 11.0+ ARM64 | Details for shodh_memory-0.2.0-cp38-abi3-macosx_11_0_arm64.whl |
| shodh_memory-0.2.0-cp38-abi3-macosx_10_13_x86_64.whl | CPython 3.8 | abi3 | macOS 10.13+ x86-64 | Details for shodh_memory-0.2.0-cp38-abi3-macosx_10_13_x86_64.whl |
Total release size: 178.9 MB
Release files / shodh_memory-0.2.0.tar.gz
| Download URL | shodh_memory-0.2.0.tar.gz |
|---|---|
| Size | 1.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5c777f3129d06de9873a9f1848cede6826c599f35fab11ea9c97b927666b5e45
|
|
BLAKE2b-256 checksum How to use checksums |
3168b514f7096508fce8dee7d4e1aa0f0ee1c4b402bf2c042510f072a2f62c99
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / shodh_memory-0.2.0-cp38-abi3-win_amd64.whl
| Download URL | shodh_memory-0.2.0-cp38-abi3-win_amd64.whl |
|---|---|
| Size | 41.0 MB |
| Tags | CPython 3.8 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
28988ebcbaca26119163ff4798bee0da73bdc58ee768e481b47e16bfa7194e94
|
|
BLAKE2b-256 checksum How to use checksums |
f063150e945c972ae4cbb592ab47edc45a4581020e5063bdb5080076cda957c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / shodh_memory-0.2.0-cp38-abi3-manylinux_2_28_x86_64.whl
| Download URL | shodh_memory-0.2.0-cp38-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 45.0 MB |
| Tags | CPython 3.8 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
76640f23271b72a3181d2f83799fed75ab8dbd62cbb9f2a43164990a2a333612
|
|
BLAKE2b-256 checksum How to use checksums |
082a1a99845338609aa03ca88eeb1ee56d7664950c5ee77ead4b4e56bdfa55f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / shodh_memory-0.2.0-cp38-abi3-macosx_11_0_arm64.whl
| Download URL | shodh_memory-0.2.0-cp38-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 44.7 MB |
| Tags | CPython 3.8 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
1c6a6dd9a457cec4c48ca46e337f2bd25b6d8b96c93873e59b4ece5bf64e225a
|
|
BLAKE2b-256 checksum How to use checksums |
cbafd69aebc0001cd38724ec30c6894e1ff698580c35f54514cd641c32668bff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / shodh_memory-0.2.0-cp38-abi3-macosx_10_13_x86_64.whl
| Download URL | shodh_memory-0.2.0-cp38-abi3-macosx_10_13_x86_64.whl |
|---|---|
| Size | 47.1 MB |
| Tags | CPython 3.8 abi3 macOS 10.13+ x86-64 |
|
SHA-256 checksum How to use checksums |
d7722b69692d3fbd7ebf23d1323759fe73b12dbf58be1749b901ecd726de7532
|
|
BLAKE2b-256 checksum How to use checksums |
55bcac7a8fc864406d4ee85b4e5b373ca4620f2fec619d7215dedd0f7b2db4ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Security for shodh-memory 0.2.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.