Skip to main content

Encrypted, portable agent-memory engine — Python bindings

Project description

Memory Nemo (MNemo) — Python bindings

Repository overview: root README · landing page: index.html.

Python bindings for Memory Nemo (MNemo), the encrypted single-file agent-memory engine. The package is a thin PyO3 wrapper over the Rust core in the sibling mnemo/ crate — the storage engine, AES-256-GCM encryption, the write-ahead log, the IVF+PQ index, snapshots, and the agent-memory model all run as compiled Rust; Python only sees a small, ergonomic surface.

Distribution name on PyPI: mnemo-engine (both mnemo and mnemo-db were already taken by unrelated projects). The import name stays mnemo, so pip install mnemo-engine then import mnemo is the full setup.

For AI agents

An agent that's been handed a .mnemo file and its passphrase can become productive in two calls — no external documentation required:

import mnemo, os

db = mnemo.open("agent.mnemo", os.environ["MNEMO_PASSPHRASE"])

# The file introduces itself: returns memories tagged metadata.area="onboarding",
# manifest first. Each entry tells you the embedder, agent_id convention,
# project metadata, and any other context the file's author recorded.
for entry in db.about():
    print(entry["content"])

Creating a new database? It's self-describing from creation:

db = mnemo.open("new.mnemo", "passphrase", dimensions=384)
db.insert_default_manifest()    # same scaffold that `mnemo init` adds
db.flush()

The scaffold tells the next agent what to do: replace it with one that records your real embedder and conventions. See the main README for the full pattern.

Build & install

The bindings build with maturin:

pip install maturin
cd mnemo-python
maturin build --release          # produces a wheel in target/wheels/
pip install target/wheels/mnemo-*.whl

maturin develop installs straight into the active virtualenv during development. The extension is built against the stable ABI (abi3-py38), so a single wheel works on CPython 3.8 and newer.

Usage

import mnemo

# Open an existing database, or create one (dimensions required to create).
db = mnemo.open("agent.mnemo", "passphrase", dimensions=4)

# Store typed memories. memory_type is one of:
# "episodic", "semantic", "procedural", "working".
db.remember(
    "the user prefers concise answers",
    "procedural",
    [0.1, 0.2, 0.3, 0.4],
    importance=0.8,
    agent_id="assistant",
    metadata={"source": "onboarding"},
)

# Multi-signal recall — similarity blended with recency, importance, frequency.
for hit in db.recall([0.1, 0.2, 0.3, 0.4], top_k=5):
    print(hit["score"], hit["content"])

db.flush()
db.close()

mnemo.open returns a Mnemo object that is also a context manager — with mnemo.open(...) as db: flushes automatically on exit.

Sessions

A Session wraps the database for one conversation: it records each turn as working memory and, when closed, consolidates those turns into durable episodic memory.

db = mnemo.open("agent.mnemo", "passphrase", dimensions=4)

with db.session("assistant") as chat:
    chat.add_turn(mnemo.Turn.user("my flight is Friday", [1.0, 0.0, 0.0, 0.0]))
    chat.add_turn(mnemo.Turn.assistant("noted", [0.9, 0.1, 0.0, 0.0]))
    context = chat.recall([1.0, 0.0, 0.0, 0.0], top_k=5)
    # leaving the block consolidates the turns into episodic memory

# or, explicitly:
chat = db.session("assistant")
chat.add_turn(mnemo.Turn("system", "be concise", [0.0, 0.0, 0.0, 1.0]))
chat.close()      # consolidate working -> episodic
# chat.discard()  # alternative: throw the turns away

mnemo.Turn has Turn.user(...), Turn.assistant(...), Turn.system(...), and Turn(role, content, vector). A Session's recall is always scoped to its own agent.

API

mnemo.open(path, passphrase, dimensions=None) -> Mnemo

Mnemo methods:

Method Purpose
remember(content, memory_type, vector, *, agent_id, importance, session_id, ttl_secs, shared, metadata) Store a memory; returns its id
recall(query, top_k=10, memory_types=None, agent_id=None, track_access=True) Multi-signal ranked retrieval. track_access=False skips access-stat updates (fully read-only recall)
search(query, top_k=10) Exact nearest-neighbour search
get(id) / delete(id) Fetch / soft-delete by id
about() Self-describing onboarding briefing — memories tagged metadata.area="onboarding", manifest first
insert_default_manifest() Insert the canonical scaffold manifest (same one mnemo init adds); returns its id
session(agent_id) Begin a conversation Session
flush() / close() Persist pending changes
verify() Decrypt and re-validate every record
build_index() / drop_index() / has_index() Approximate index control
snapshots() / restore_to(txn_id) / restore_to_time(unix_secs) Point-in-time recovery
set_cache_capacity(pages) / cache_stats() Page-cache tuning
set_max_snapshots(max) Override the snapshot-manifest retention cap (default 256; 0 disables)
stats() Summary statistics
export_encrypted(dest) Copy the (already-encrypted) file elsewhere
len(db) Live memory count

Session methods: add_turn(turn), recall(query, top_k=10, memory_types=None), close(), discard(), id(), agent(), turn_ids(), turn_count(); also a context manager (exiting consolidates).

Memories and results are returned as plain dicts; metadata round-trips as a nested dict.

License

Apache-2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

mnemo_engine-0.3.2-cp38-abi3-win_amd64.whl (418.5 kB view details)

Uploaded CPython 3.8+Windows x86-64

mnemo_engine-0.3.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (557.1 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

mnemo_engine-0.3.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (538.1 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

mnemo_engine-0.3.2-cp38-abi3-macosx_11_0_arm64.whl (504.3 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

mnemo_engine-0.3.2-cp38-abi3-macosx_10_12_x86_64.whl (526.0 kB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file mnemo_engine-0.3.2-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for mnemo_engine-0.3.2-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c203506afb92194374642fc80996f46fa4be32260838394c1679ed7e9cdacde4
MD5 89060e58fb394d83bbd61cd7682504aa
BLAKE2b-256 ffdfa697c67695f92bffa6fefb27a222a9b72475233345e2ac18e72c4fbccc75

See more details on using hashes here.

File details

Details for the file mnemo_engine-0.3.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mnemo_engine-0.3.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d39467afd0889377ebf2c85bac1d0d95c5105f9a5aa2733225cbbcbc8f90f37c
MD5 dd28fc3a901d27e6fc9839d61f1d10c1
BLAKE2b-256 8f3b41b9bc2ce7d4cdb906d3edfb0607b301964c6022f5895e51ee652be2f83d

See more details on using hashes here.

File details

Details for the file mnemo_engine-0.3.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for mnemo_engine-0.3.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 98ca512b85a9b0f5383c368918b489d36cc40adf4ebc95c585358207ab5cdbdf
MD5 503b4e73efde5c6db77ddbfe033b08f1
BLAKE2b-256 5b16d4b79f40b049385d3aeba02646f49d7a22c07bdb47cd8c9cf5c13df62f35

See more details on using hashes here.

File details

Details for the file mnemo_engine-0.3.2-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mnemo_engine-0.3.2-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2545a182449eeb29032aa5fa08aa0b8d30830d2f9584ae669919b57f29020d39
MD5 b807f85d80ee2dbe55673af761664b4c
BLAKE2b-256 672223c8a1b3ed8ac175ef027819c9d4891e70fb3abdbe4959047bf40c448716

See more details on using hashes here.

File details

Details for the file mnemo_engine-0.3.2-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for mnemo_engine-0.3.2-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f7f161ad80e77a2ef199e3965584c6a2a5a126aa998685cbb3bbc8ddacc9908b
MD5 b0a432dcdab083f986e1c4571c333c11
BLAKE2b-256 102f8349ba09a92f629e6d4017830f11c889fbc8311e5f581c61c5bd36e48a08

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page