Skip to main content
Membrane

Membrane

The programmable memory layer for AI agents.

PyPI Python License


What is Membrane?

Membrane is a programmable memory runtime for AI agents.

Memory should be managed like a computational resource, not retrieved like a document collection.

Traditional RAG is usually:

query → embed → vector search → context

Membrane is:

query / event
      ↓
memory controller
      ↓
read · write · update · forget
      ↓
memory query planner
      ↓
memory router
      ↓
structured · semantic · temporal · graph · KV · episodic
      ↓
rank · merge · budget · explain
      ↓
working context

The core is LLM-optional. Deterministic memory management works locally without an API key or mandatory vector database.

Package

PyPI

Install the package from PyPI.

Quickstart

pip install membrane-memory
from membrane import Memory

memory = Memory()

memory.remember(
    "The user prefers concise technical explanations.",
    user_id="alice_123",
)

result = memory.recall(
    "How should I communicate with this user?",
    user_id="alice_123",
)

print(result.memories[0].content)

SQLite is the default local substrate.

By default, Memory() uses an in-memory SQLite database for zero-configuration, ephemeral memory. For memory that survives process restarts, pass a persistent database path:

memory = Memory(db_path="membrane.db")

The CLI uses ./membrane.db by default, so membrane remember ... and membrane recall ... persist across separate command invocations.


Architecture

Membrane Architecture

The architecture separates the memory control plane from the memory data plane.

flowchart TB
    Q[User Query q_t]
    X[New Information x_t]
    C[Context c_t]
    O[Outcome / Feedback]

    Q --> G
    X --> G
    C --> G
    O --> G

    subgraph G[Memory Cell / LSTM-inspired Controller]
        F[Forget Gate f_t]
        I[Write Gate i_t]
        M[Candidate Memory M_tilde]
        U[Update Gate u_t]
        R[Read Gate o_t]
    end

    G --> P[Memory Query Planner]
    P --> RT[Memory Router]

    RT --> S[Structured]
    RT --> V[Semantic]
    RT --> T[Temporal]
    RT --> GR[Graph]
    RT --> K[KV / Working]
    RT --> E[Episodic]

    S --> W[Working Context]
    V --> W
    T --> W
    GR --> W
    K --> W
    E --> W

    W --> A[Agent / LLM]
    A --> O

Critical design distinction

The LSTM-inspired component is a memory controller, not an LSTM-shaped database.

A vanilla LSTM has a dense cell state. Membrane uses a compact controller state to produce policies over external, heterogeneous memory.

This makes the LSTM analogy useful without pretending SQL rows, graph nodes, and vector records are literally an LSTM cell tensor.


Memory Gates

Define:

z_t = [q_t ; x_t ; c_t ; h_{t-1}]

Forget gate

f_t = σ(W_f z_t + b_f)

Controls retention, decay, expiration, and removal from active memory.

Write gate

i_t = σ(W_i z_t + b_i)

Controls admission of new observations.

Candidate memory

M̃_t = φ(W_m z_t + b_m)

Represents proposed new memory.

Update gate

u_t = σ(W_u z_t + b_u)

Controls revision and supersession.

LSTM-inspired state update

M̄_t = f_t ⊙ M_{t-1} + i_t ⊙ M̃_t

M_t = (1-u_t) ⊙ M_{t-1} + u_t ⊙ M̄_t

Read gate

o_t = σ(W_o [h_t ; q_t] + b_o)

R_t = o_t ⊙ Retrieve(Plan(q_t, c_t), M)

The read gate controls how much selected memory enters working context.


Memory Lifecycle

CANDIDATE
    │
    ├── accepted ───────► ACTIVE
    │                       │
    │                       ├── revised ──► UPDATED / SUPERSEDED
    │                       ├── stale ────► ARCHIVED
    │                       └── expired ──► FORGOTTEN
    │
    └── unsafe ─────────► QUARANTINED

Every transition is intended to be auditable rather than silently destructive.


Memory Query Planner

Not every memory query is semantic search.

Query Preferred substrate
What does the user prefer? Semantic
What is the current price? Structured / KV
What changed last week? Temporal
Who is connected to this project? Graph
What happened during the previous run? Episodic
What is the latest state? KV / Structured
Why was this decision made? Hybrid + Provenance

The planner produces an inspectable plan before execution.


Memory Substrates

Substrate Purpose Example
Structured exact facts and attributes SQLite / PostgreSQL
Semantic conceptual similarity Qdrant / pgvector
Temporal history and point-in-time state SQL / event log
Graph relationships and causal links Neo4j
KV / Working current state and fast lookup Redis / SQLite
Episodic events and artifacts object store / filesystem

Membrane does not require all substrates to be installed.


Temporal Memory

Current truth and historical truth are different queries.

memory.remember(
    "SKU 123 price is $10",
    structured={"entity": "sku_123", "attribute": "price", "value": 10},
)

memory.remember(
    "SKU 123 price is $12",
    structured={"entity": "sku_123", "attribute": "price", "value": 12},
)

memory.recall("current price", entity="sku_123")
memory.timeline("sku_123")

The current record can supersede the previous record while the historical record remains recoverable.


Provenance and Outcome Memory

Membrane tracks the path:

source
  ↓
observation
  ↓
memory candidate
  ↓
gate decision
  ↓
stored / superseded memory
  ↓
retrieval plan
  ↓
working context
  ↓
agent decision
  ↓
outcome

This enables outcome-based reinforcement:

decision → action → outcome → utility → memory policy update

Security

Memory is an attack surface.

Untrusted instruction-like observations should be isolated:

untrusted observation
        ↓
   trust / policy gate
       / \
      /   \
 trusted  suspicious
   ↓          ↓
 ACTIVE   QUARANTINED

Policies can control tenant isolation, source trust, retention, write permissions, sensitive fields, and retrieval scope.


Research Direction

The central research question is:

Can an AI system dynamically manage heterogeneous memory as a computational resource?

Potential research dimensions:

  • learned memory gating
  • temporal contradiction resolution
  • adaptive forgetting
  • consolidation
  • outcome-based reinforcement
  • substrate routing
  • context-budget optimization
  • LLM-free memory control
  • replay

A future MemoryBench should measure retrieval quality, temporal correctness, contradiction rate, write/forget precision, consolidation quality, latency, storage growth, and token consumption.

Design Principles

  1. Memory is not RAG. Semantic retrieval is only one mechanism.
  2. Control and storage are separate.
  3. Exact facts should remain structured.
  4. History should be preserved.
  5. Memory should be budget-aware.
  6. LLMs are optional infrastructure.
  7. Important decisions should be explainable.

Contributing

git clone https://github.com/dcsgod/membrane.git
cd membrane
pip install -e ".[dev]"
pytest

License

Apache 2.0.

Metadata

Release files for membrane-memory 0.1.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 membrane-memory 0.1.1
File Size Uploaded Provenance
membrane_memory-0.1.1.tar.gz 52.0 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for membrane-memory 0.1.1
File Interpreter ABI Platform
membrane_memory-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 103.6 kB

Release files / membrane_memory-0.1.1.tar.gz

Download URL membrane_memory-0.1.1.tar.gz
Size 52.0 kB
Tags Source
SHA-256 checksum
How to use checksums
cbd1d5e051b736a920b83cb755ecd7b522f5e9e627365588c79672ee3571e737
BLAKE2b-256 checksum
How to use checksums
d3397d7487bb0fb2f794115aff9509a6d30ac2e28361c72704db92181e4b112b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 4, 2026.

Transparency log

Release files / membrane_memory-0.1.1-py3-none-any.whl

Download URL membrane_memory-0.1.1-py3-none-any.whl
Size 51.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1abd8127c07027cc298f018da203f93b12223ff4d2f0bb60ce872d9ea579d6be
BLAKE2b-256 checksum
How to use checksums
9c098359c3e270b60897d6199d123c3f31a8e8a532feb657e2776031e788a36c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 4, 2026.

Transparency log

Security for membrane-memory 0.1.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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for membrane_memory-0.1.1.tar.gz

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 Oct 4, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

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