This post explains how to encrypt an export file of LLM memory with ragleap-memory 0.3.1 (released 2026-11-12), and what that encryption does not protect. Everything below comes from the 0.3.1 release notes, checked on 2026-11-15. Status: Released library, additive, with no schema change. No independent security review has happened.
Why encrypt a memory export?
In general, an export file holds what an application remembered about people, and it travels: to a backup, to another machine, to a colleague. Encrypting the file means that losing it does not mean losing the contents.
How do I turn on encryption?
Install the new extra: pip install ragleap-memory[crypto]. It needs ragleap-security 0.2.0 or newer, and the encryption itself (AES-256-GCM) is done by ragleap-security; ragleap-memory only frames the file. Then call export_file(scope, path, encrypt_with=None, passphrase=None, context=None). Use a Key, a KeyRing (for rotation) or a passphrase (scrypt, derived once per file). import_file and import_stream take decrypt_with, passphrase and context. Without the extra nothing else changes, and asking for encryption raises an error that names the extra.
What does import do with encrypted and plain files?
Import refuses an encrypted file (header version 2) when no key or passphrase is given, and refuses a plain file when one is given, so there is no silent downgrade. Import stays the single safe path: the same trust cap, scope check, quotas, one transaction and limits apply after decrypting.
How does it detect tampering?
Each line is bound to a fixed label, the SHA-256 of the exact header line, its position and your context. A wrong key, a wrong context, any changed byte, and a line that is moved, duplicated or taken from another file all fail with line N: cannot decrypt. Dropped or extra lines fail the entry count.
What should I know before upgrading?
Plain export files (format version 1) and every call without the new arguments behave exactly as in 0.3.0. A file whose header says version 2 is now read as an encrypted file; before, it was refused as an unsupported version. The notes also record that the released 0.3.0 refuses a 0.3.1 encrypted file with its unsupported-version message.
What does it not protect?
- It protects the export file, not the SQLite database, and not process memory while exporting or importing.
- The header shows the number of entries, and line lengths show roughly how long each entry is.
- Someone who holds the key can read and forge a file.
- An old file put back in place of a newer one is not noticed.
- A decrypted file is still untrusted input.
- No independent security review has happened.
What was verified, and what was not?
From the release notes (the authors' runs, not ours): GitHub CI passed 55 of 55 checks on the PR head. 532 tests passed on the author's VPS (Python 3.10.12, SQLite 3.37.2, cryptography 50.0.2), and in the sandbox on Python 3.12.3 and 3.10.20 and with cryptography 42.0.0. A mutation check in the sandbox killed 232 of 232. From PyPI, the wheel's Python files are identical to the source at the tag and the tests pass against the installed wheel.
Not verified: the mutation run on the VPS, Windows and macOS, several processes using one file, network file systems and big-endian machines. Timing and memory with very large files are also unmeasured: an import decrypts into memory up to max_bytes (64 MiB by default).
Sources: the ragleap-memory 0.3.1 release notes (design #1294, code PR #1385, date fix PR #1386) and PyPI. Library page: ragleap-memory.
Quick answers
How do I encrypt an LLM memory export in Python?
Install ragleap-memory[crypto], which needs ragleap-security 0.2.0 or newer, and pass encrypt_with (a Key or KeyRing) or passphrase to export_file. Import with decrypt_with or passphrase. The encryption is AES-256-GCM, done by ragleap-security.
Does encrypting the export protect the SQLite database?
No. It protects the export file only, not the SQLite database and not process memory while exporting or importing.
What happens if someone edits or reorders an encrypted export?
Import fails with line N: cannot decrypt for a wrong key or context, any changed byte, or a moved, duplicated or foreign line. Dropped or extra lines fail the entry count.
Can I import a plain file when I give a key?
No. Import refuses an encrypted file without a key or passphrase and refuses a plain file when one is given, so there is no silent downgrade.