Skip to main content

MemBlock

Structured memory SDK for AI agents.

Typed blocks · Knowledge graph · Hybrid search · Encryption · Decay engine — all local, all yours.

memblock.xyz

PyPI version License: MIT Python versions


AI agents forget everything between sessions. Vector databases give you search but no structure. Cloud memory APIs lock you in and store your users' data on someone else's servers. MemBlock is the alternative: typed memory blocks, a built-in knowledge graph, hybrid search, encryption, and intelligent decay — all running on your infrastructure with pip install and one line of Python. No Docker, no Neo4j, no subscriptions. Your data never leaves your machine.

Install

pip install memblock

Quick Start

from memblock import MemBlock, BlockType

mem = MemBlock(storage="sqlite:///memory.db")

# Store structured memories
mem.store("User prefers Python", type=BlockType.PREFERENCE)
mem.store("User works at Acme Corp", type=BlockType.FACT, confidence=0.95)

# Query with hybrid search
results = mem.query(text_search="programming", type=BlockType.PREFERENCE)

# Build LLM-ready context
context = mem.build_context(query="user preferences", token_budget=4000)

# Knowledge graph
mem.link(results[0].id, other.id, relation="related_to")

# Tamper detection
mem.verify()

Pluggable classifier (typed decisions on the write path)

Let a local System One model decide type, source, calibrated confidence, encryption level and decay rate for every memory, and gate conflict resolution before the LLM resolver runs:

from memblock import MemBlock
from jevblock import LayaMLXRouterBackend            # or AnthropicBackend / OpenAIBackend / StubBackend
from jevblock.memblock_bridge import MemoryClassifier

mem = MemBlock(storage="sqlite:///memory.db",
               classifier=MemoryClassifier(LayaMLXRouterBackend()),
               extract_provider="anthropic",          # optional: LLM escalation for low-confidence cases
               conflict_resolution=True)

block = mem.store("User prefers Python over JavaScript")   # type=PREFERENCE, confidence calibrated
block.metadata.custom_metadata["_classifier"]               # full audit of the decision

Explicit store() arguments always win over the classifier. See memblock/classifier.py for the contract and CHANGELOG.md for details.

Memory for any chat model

MemorySession sits between your app and the model. Each turn it reads memory into the prompt, calls the model, then commits the finished turn to memory word for word and drops it from the prompt. The prompt stays small; nothing that was said is lost.

from memblock import MemBlock, MemorySession

def model(messages):                 # any model: take the messages, return the reply text
    return my_llm_client.chat(messages)

session = MemorySession(MemBlock(storage="sqlite:///memory.db"), model)

session.chat("My kitten Memmy is three months old.", enable_memory=True)
session.chat("How old is my kitten?")              # answered from memory

session.ingest(long_document)                      # documents go in word for word too
session.save_state("memory.snapshot.json")         # stamped snapshot; restore or fork later

Commits are all-or-nothing and safe to retry (mem.transaction(), receipts). Agents can reuse what earlier runs learned with ExperienceBank and MemorySession(experience="on_trouble"). See memblock/session.py, memblock/transactions.py, memblock/snapshot.py and memblock/experience.py. Sync API only for now.

Async (asyncio)

from memblock import AsyncMemBlock, BlockType

# Native asyncpg path — non-blocking storage I/O
mem = AsyncMemBlock(storage="postgresql+asyncpg://user@host/db")

await mem.store("User prefers Python", type=BlockType.PREFERENCE)
results = await mem.query(text_search="programming", limit=10)

# Multi-tenant isolation: each tenant gets its own Postgres schema.
mem = AsyncMemBlock(
    storage="postgresql+asyncpg://user@host/db",
    schema="tenant_xyz",  # bootstraps + isolates on first use
)

AsyncMemBlock accepts plain postgresql:// URLs too — those use the legacy thread-pool wrapper. Use postgresql+asyncpg:// to opt into the native async backend.

Optional Extras

pip install "memblock[postgres]"            # PostgreSQL backend (sync + async + pgvector)
pip install "memblock[embeddings]"          # Local vector embeddings (FastEmbed)
pip install "memblock[llm]"                 # LLM extraction (OpenAI, Anthropic, Gemini)
pip install "memblock[reranker-cohere]"     # Cohere reranker
pip install "memblock[reranker-cross-encoder]"  # HuggingFace reranker
pip install "memblock[all-cloud]"           # Everything without onnxruntime (Python 3.13+)
pip install "memblock[all]"                 # Everything including local embeddings

Documentation

Full docs, API reference, and examples: memblock.xyz

Contributing

Contributions are welcome! MemBlock is open source and community-driven.

  • Found a bug or have a feature idea? Open an issue.
  • Want to contribute code? Fork the repo, create a branch, and open a pull request.
  • Please make sure tests pass and follow the existing code style.

The main branch is protected, so all changes go through pull requests and review.

License

Released under the MIT License. Copyright (c) 2025-2026 iexcalibur.

Metadata

Release files for memblock 0.15.0

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

Source distribution (sdist)

Source distribution for memblock 0.15.0
File Size Uploaded Provenance Actions
memblock-0.15.0.tar.gz 281.9 kB Without provenance Details for memblock-0.15.0.tar.gz

Built distribution (wheel)

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

Total release size: 479.5 kB

Release files / memblock-0.15.0.tar.gz

Download URL memblock-0.15.0.tar.gz
Size 281.9 kB
Tags Source
SHA-256 checksum
How to use checksums
21b3961777c6a77563d396124402d8e9ec75aa38bf8aec7119b7a068261554ec
BLAKE2b-256 checksum
How to use checksums
610ebd79f2e7005d789780fd027709f92966960f69ce1463f1774f83feca1734
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / memblock-0.15.0-py3-none-any.whl

Download URL memblock-0.15.0-py3-none-any.whl
Size 197.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4dc43824db3b259d00dfaaad414dc3fc106945550cf11fdd1c017f73b3d7f0ba
BLAKE2b-256 checksum
How to use checksums
a38a28dcb1063f4ef7ad3163858be8cdc40975da89331d2906cadc1e5f6a1f5e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Security for memblock 0.15.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.

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