Privacy-first memory API for LLMs
Project description
rec0 — memory for any LLM
Give your AI a permanent memory in 3 lines of code.
Install
Python:
pip install rec0
JavaScript / TypeScript:
npm install @rec0ai/rec0
See the JavaScript SDK docs for JS/TS usage.
Quickstart
from rec0 import Memory
# Works immediately - connects to production API
mem = Memory(
api_key="r0_live_sk_...", # Get your key at https://rec0.vercel.app
user_id="user_123"
)
mem.store("User prefers dark mode")
results = mem.recall("user preferences")
print(results)
That's it. context returns a bullet-list string ready to prepend to any system prompt.
Custom API Endpoint
The SDK defaults to the production API at https://memorylayer-production.up.railway.app.
For development or self-hosted instances:
from rec0 import Memory
mem = Memory(
api_key="r0_dev_...",
user_id="user_123",
base_url="http://localhost:8000" # Development server
)
Why rec0
| rec0 | Mem0 | |
|---|---|---|
| Privacy | Data never leaves your servers | Processed externally |
| Cost | $0.002 / 1K ops | ~$0.10 / 1K ops |
| Setup | 3 lines | OAuth + config |
| LLM support | Any model | OpenAI-first |
| GDPR | 1 API call | Manual |
- Privacy-first: embeddings and summaries run on YOUR infrastructure — no user data touches third-party APIs
- LLM-agnostic: works with OpenAI, Anthropic, Gemini, Llama, Mistral — anything that takes a string
- Memory lifecycle: automatic importance scoring, recall-count boosting, and time-based decay
- GDPR compliant: right-to-erasure in one call (
mem.delete_user())
Multi-app isolation with app_id
app_id is a free-text namespace string (default "default"). Memories are isolated per (user_id, app_id) pair — recall and list only return memories matching the exact app_id you query with.
Use this when one account runs multiple products, bots, or environments and you need their memories to be fully isolated:
from rec0 import Memory
# Slack bot — isolated namespace
mem_slack = Memory(user_id="user_123", app_id="slack-bot", api_key=key)
mem_slack.store("Prefers Slack DMs over channel mentions")
# Website chat — completely separate namespace
mem_web = Memory(user_id="user_123", app_id="website-chat", api_key=key)
mem_web.store("Browses on mobile primarily")
# These never appear in each other's recall() results
slack_results = mem_slack.recall("communication preferences") # no website memories
web_results = mem_web.recall("device preferences") # no slack memories
See the full multi-tenancy guide for more detail.
Full API reference
Memory(user_id, api_key, app_id, base_url)
| Parameter | Type | Default | Description |
|---|---|---|---|
user_id |
str |
required | Your end-user identifier |
api_key |
str |
$REC0_API_KEY |
Your rec0 API key |
app_id |
str |
"default" |
Namespace for multi-app isolation |
base_url |
str |
prod URL | Override for self-hosting |
Methods
mem.store(content) → MemoryObject
Store a new memory. Auto-generates embedding and summary server-side.
m = mem.store("User is building a SaaS product in Python")
print(m.id) # UUID
print(m.importance) # starts at 1.0, increases with each recall
mem.context(query, limit=25) → str
The most-used method. Returns a bullet-list string to inject into your LLM prompt.
context = mem.context("what does the user like", limit=25)
# "- User prefers Python and dark mode\n- User is building a SaaS product"
# Typical usage with OpenAI:
messages = [
{"role": "system", "content": f"User context:\n{context}"},
{"role": "user", "content": user_message},
]
mem.recall(query, limit=25) → List[MemoryObject]
Returns memories ranked by semantic similarity. Use when you need scores or metadata.
memories = mem.recall("programming preferences", limit=3) # limit=25 default
for m in memories:
print(f"{m.content} (score: {m.relevance_score})")
mem.list(limit=20, offset=0) → List[MemoryObject]
All active memories for this user, ordered by creation time. Supports pagination.
page1 = mem.list(limit=20, offset=0)
page2 = mem.list(limit=20, offset=20)
mem.delete(memory_id) → None
Soft-delete a specific memory (retained for audit trail).
mem.delete_user(permanent=False) → dict
GDPR right-to-erasure. Removes all memories for this user.
# Soft-delete (recoverable, default)
mem.delete_user()
# Hard-delete — irreversible, destroys all memory rows permanently
mem.delete_user(permanent=True)
Warning:
permanent=Truecannot be undone.
mem.export() → dict
GDPR data export. Returns all memory data as a dictionary.
mem.ping() → bool
Connectivity check. Returns True if the API is reachable.
if not mem.ping():
print("rec0 API unreachable — check your key")
Error handling
from rec0 import Memory, Rec0Error, AuthError, RateLimitError, NotFoundError
mem = Memory(api_key="r0_xxx", user_id="user_123")
try:
mem.store("User loves rec0")
except AuthError:
print("Invalid API key — check REC0_API_KEY")
except RateLimitError as e:
print(f"Rate limited — retry in {e.retry_after}s")
except NotFoundError:
print("Memory not found")
except Rec0Error as e:
print(f"Unexpected error: {e}")
Rate limits are handled automatically: rec0 will wait retry_after seconds and retry once before raising.
Async usage
Every method has an async equivalent via AsyncMemory:
import asyncio
from rec0 import AsyncMemory
async def main():
mem = AsyncMemory(api_key="r0_xxx", user_id="user_123")
await mem.store("User is a night-owl developer")
context = await mem.context("when does the user work")
print(context)
asyncio.run(main())
AsyncMemory uses httpx under the hood and is safe to use in FastAPI, Django async views, and any asyncio application.
Environment variables
| Variable | Description |
|---|---|
REC0_API_KEY |
Your rec0 API key (used automatically if api_key= not passed) |
REC0_BASE_URL |
Override the API base URL (optional, for self-hosting) |
export REC0_API_KEY=r0_your_key_here
# api_key is now auto-loaded — no need to hardcode it
mem = Memory(user_id="user_123")
MemoryObject fields
| Field | Type | Description |
|---|---|---|
id |
str |
UUID |
content |
str |
The original memory text |
summary |
str | None |
Auto-generated summary |
importance |
float |
1.0–3.0; increases ~5% per recall (capped at 3.0×), updated asynchronously |
recall_count |
int |
Times this memory was recalled |
relevance_score |
float | None |
Similarity score (recall only) |
created_at |
datetime |
When stored |
is_active |
bool |
False if deleted |
Self-hosting
rec0 is open-source. Deploy your own instance on Railway, Fly, or any server:
git clone https://github.com/patelyash2511/memorylayer
# See README for Railway deployment instructions
Then point the SDK at your instance:
mem = Memory(
api_key="your_key",
user_id="user_123",
base_url="https://your-instance.up.railway.app",
)
rec0.vercel.app · npm · PyPI
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file memorylayer_py-1.1.0.tar.gz.
File metadata
- Download URL: memorylayer_py-1.1.0.tar.gz
- Upload date:
- Size: 12.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b20b9357811067b24ce9f7ba55342c9d6dcb9e8c834dfbfca560ffebd5c482e4
|
|
| MD5 |
15b401cf860bd6fd78107f262e3dc0cd
|
|
| BLAKE2b-256 |
157ea59bbbed340c0243341515685523991e1c5de65c80f34a267409503a341e
|
File details
Details for the file memorylayer_py-1.1.0-py3-none-any.whl.
File metadata
- Download URL: memorylayer_py-1.1.0-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c250e1e2573e7805debc3b2746f86f29b5d1b172a9f43252d2a337f6f66e8c6c
|
|
| MD5 |
486f87370f2a1a54702ab9f56b750b1f
|
|
| BLAKE2b-256 |
21f960947fa87af14212a80d0e821137fe6a04c0c0039d3ae6c5e8da595a05bc
|