Skip to main content

Persistent, queryable AI memory for any Python app — local-first, zero API cost

Project description

retainr

CI

Persistent, queryable memory for any Python AI app — local-first, zero API cost.

PyPI version License: MIT Python 3.10+


What is it?

retainr gives any AI app a long-term memory layer — without needing an API key, a cloud service, or a database server.

Store things. Recall them semantically. Forget them. All locally.

from memoryos import Memory

mem = Memory(user_id="arjun")

mem.remember("I prefer dark mode and use VS Code")
mem.remember("Currently building a job application assistant")
mem.remember("I like concise answers over long explanations")

results = mem.recall("what tools does the user prefer?")
for r in results:
    print(f"[{r['score']:.3f}] {r['text']}")
[0.412] I prefer dark mode and use VS Code
[0.289] I like concise answers over long explanations

CLI Demo

alt text

Stats

alt text


Install

pip install retainr

Features

  • 🧠 Semantic recall — finds memories by meaning, not exact keywords
  • 📉 Memory decay — old memories fade in relevance automatically
  • Importance scoring — weight memories by how significant they are
  • 🏷️ Tags — organize memories into namespaces
  • 🗑️ Forget & clear — GDPR-friendly deletion
  • 💾 Local-first — uses FAISS + SQLite, no external services
  • 🆓 Zero cost — no API keys, no cloud, runs on your machine

API Reference

Memory(user_id, db_path)

mem = Memory(user_id="alice", db_path="memory.db")
Param Default Description
user_id "default" Isolates memories per user
db_path "memory.db" SQLite file path. Use ":memory:" for in-RAM (tests)

remember(text, tags, importance, decay_days)

Store a memory.

mid = mem.remember(
    "User just got promoted to SDE-2",
    tags=["career", "milestone"],
    importance=0.9,   # 0.0–1.0, default 0.5
    decay_days=90,    # score halves every 90 days, 0 = no decay
)

Returns: str — the memory ID (use it to forget() later)


recall(query, top_k)

Find the most semantically relevant memories.

results = mem.recall("what is the user's job status?", top_k=3)
# [{"id": ..., "text": ..., "score": 0.87, "tags": [...], ...}]

forget(memory_id)

Delete a specific memory.

mem.forget(mid)

clear()

Wipe all memories for this user.

mem.clear()

export(filepath)

Backup all memories to JSON.

mem.export("my_memories.json")

How it works

  1. remember() → text is embedded using sentence-transformers (all-MiniLM-L6-v2, runs locally) → vector stored in FAISS, metadata in SQLite
  2. recall() → query is embedded → FAISS finds top-k nearest vectors → SQLite returns the original text
  3. Scoring → final score = cosine similarity × (0.7 + 0.3 × decayed importance)

Why not mem0 / Zep / etc.?

retainr mem0 Zep
Local-first
API key needed
Cost Free Paid tiers Paid tiers
Memory decay
pip install

Stack


License

MIT © Devarajan

Project details


Download files

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

Source Distribution

retainr-0.2.2.tar.gz (204.7 kB view details)

Uploaded Source

Built Distribution

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

retainr-0.2.2-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file retainr-0.2.2.tar.gz.

File metadata

  • Download URL: retainr-0.2.2.tar.gz
  • Upload date:
  • Size: 204.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.9

File hashes

Hashes for retainr-0.2.2.tar.gz
Algorithm Hash digest
SHA256 893016db27a69f3731f5227c2583f20f4e6169537be2c2e5b236d2e6c003d529
MD5 a508a23a91d253e71a5ddc2f72308d7a
BLAKE2b-256 984ca845e197a1e0f1286973272cbf857290443e07018b6bcafd55bd69688abc

See more details on using hashes here.

File details

Details for the file retainr-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: retainr-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.9

File hashes

Hashes for retainr-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 557a6f6736cac4fce64c850ddf00e4f55fff5ced5b25cb2493c77a64581ae4da
MD5 20431c58bb8edcdd7c7d38c3877bc943
BLAKE2b-256 19425c3bed9c2e5bf2d9919d05d22ecb25e745f36784546456b98f18fcb5a99d

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