RagLeap
Blog

How to add long-term memory to an LLM app with SQLite and trust labels (ragleap-memory, alpha)

Short answer: install ragleap-memory, create a SQLiteStore, and give every call a Scope from ragleap-security. Entries have a type and a trust label, search finds them by keyword (SQLite FTS5), and supersede replaces a fact that changed while keeping its history. This guide follows the README and changelog of ragleap-memory 0.1.0, which is alpha and not independently audited.

What do you need?

  • Python 3.10 or newer.
  • A SQLite build with FTS5. The store refuses to start without it.
  • ragleap-security 0.1.0 or newer, which provides Scope. It is the only dependency.

How do you store and find a memory?

pip install ragleap-memory

This is the README example, unchanged:

from ragleap_memory import SQLiteStore
from ragleap_security import Scope

store = SQLiteStore("memory.db")
alice = Scope("acme", subject="alice")

old = store.add(alice, "Alice prefers email", trust="owner")
new = store.supersede(alice, old.id, "Alice prefers phone calls", trust="owner")

for hit in store.search(alice, "how should we contact alice", k=3, min_trust="model"):
    print(hit.entry.trust, hit.entry.text)

How are users or tenants kept apart?

Every call takes a Scope and is filtered by it inside the SQL. Single-tenant use is simply one fixed Scope. How scopes work is in the ragleap-security guide.

What are trust labels for?

Each entry is an episode, a fact or a summary, with a trust label of untrusted (the default for new entries), model or owner. search can require a minimum label. The store only labels trust; it does not decide what to do with retrieved text. Code that puts memory into a prompt must treat anything below owner as untrusted input.

How do you change or delete a memory?

supersede is for facts that change, and history is kept. The README also lists forget, export, erase (removes the text from the file) and sweep_expired. After erase(), a byte-level search of the database file and its journal found no trace of the deleted text, on the two SQLite builds tested.

What is not available?

  • Embeddings and vector search: search is keyword search, and its quality has not been measured on any benchmark.
  • Consolidation and retention policies, importance-based ranking, Postgres, encryption at rest, a review queue and the ragleap-agents adapter. These are planned (issue 900) and not available.
  • An independent audit. Read the threat model before relying on it.

What has been verified?

From the 0.1.0 changelog: 89 tests pass on Python 3.10 and 3.12, the CI test job passes on 3.10, 3.11 and 3.12, and all 27 deliberate breaks of a protection are caught by the mutation check.

Sources

ragleap-memory on PyPI, the README, the changelog, the library page and the tests page.

Back to the blog