cognitive-memory
Biologically-inspired agent memory with decay, consolidation, and tiered storage.
Python SDK. v0.4.0 brings hybrid retrieval (BM25 + vector), power-law decay, graph expansion, LLM rerank, deferred conflict resolution, multi-tenancy, a pluggable LLMProvider, and a JSONL file adapter. Behavioural parity with the TypeScript SDK.
Install
pip install cognitive-memory
For the OpenAI extractor and embedder:
pip install "cognitive-memory[openai]"
export OPENAI_API_KEY=sk-...
Requires Python 3.10+.
Quick Start
from cognitive_memory import SyncCognitiveMemory
mem = SyncCognitiveMemory(embedder="hash") # zero-dep, deterministic
mem.add("User is allergic to shellfish", category="core", importance=0.95)
response = mem.search("what allergies does the user have?")
for r in response.results:
print(r.memory.content, f"(score: {r.combined_score:.2f})")
For async code, use CognitiveMemory directly (same API, await mem.add(...) / await mem.search(...)).
Production setup
from cognitive_memory import CognitiveMemory, JsonlFileAdapter
mem = CognitiveMemory(
embedder="openai", # OpenAIEmbeddings, reads OPENAI_API_KEY
adapter=JsonlFileAdapter("/var/lib/myapp/mem.jsonl"), # durable, single-process
user_id="alice", # multi-tenant scoping
)
await mem.extract_and_store(conversation_text, session_id="sess-1")
results = await mem.search("UI preferences", deep_recall=True, rerank=True)
extract_and_store(...) runs the LLM extractor; add(...) skips it for pre-extracted facts.
Custom LLM provider
The extractor and conflict-resolver talk to an LLMProvider interface — swap OpenAI for Anthropic, a local model, or a gateway:
from cognitive_memory import CognitiveMemory, LLMProvider
class MyProvider(LLMProvider):
def complete(self, prompt: str, **kwargs) -> str:
... # your model
mem = CognitiveMemory(llm=MyProvider())
Multi-tenancy
user_id namespaces every read and write. Two instances sharing an adapter are fully isolated.
alice = CognitiveMemory(adapter=shared, user_id="alice")
bob = CognitiveMemory(adapter=shared, user_id="bob")
await alice.add("alice's secret")
# bob.search() never returns alice's memories
Adapters
InMemoryAdapter— default, ephemeralJsonlFileAdapter— append-only event log, replay on startup- Custom — implement
MemoryAdapterfromcognitive_memory.adapters - Postgres (pgvector) — planned for 0.4.1
Migration
See MIGRATION.md for the 0.3.0 → 0.4.0 changes (all additive — existing code keeps working).
Docs
Full documentation, guides, concepts, and API reference: planetaryescape.github.io/cognitive-memory.
License
Metadata
Release files for cognitive-memory 0.5.1
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 |
|---|---|---|---|---|
| cognitive_memory-0.5.1.tar.gz | 56.1 kB | Without provenance | Details for cognitive_memory-0.5.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cognitive_memory-0.5.1-py3-none-any.whl | Python 3 | none | any | Details for cognitive_memory-0.5.1-py3-none-any.whl |
Total release size: 103.1 kB
Release files / cognitive_memory-0.5.1.tar.gz
| Download URL | cognitive_memory-0.5.1.tar.gz |
|---|---|
| Size | 56.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
456762ad8f00aa2d20a4313ee02137dd14afe08dd1c631ff270b3664e998f97d
|
|
BLAKE2b-256 checksum How to use checksums |
98d40584f5b0ecaa46f57fa742618ab69fcdfd1bff0827f91850c769ed833e51
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / cognitive_memory-0.5.1-py3-none-any.whl
| Download URL | cognitive_memory-0.5.1-py3-none-any.whl |
|---|---|
| Size | 47.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
916d4996169b24167f044a1eae13298e295222ad01f9bc08bdc026a6c1e0d2fa
|
|
BLAKE2b-256 checksum How to use checksums |
0dae7a596c74037cc3560be9ec79af83ef2853c29581fcfad9607ed433a009c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Security for cognitive-memory 0.5.1
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.