Storing a Memory
Callclient.remember() to persist a piece of information tied to a specific user and agent. Each memory is embedded automatically and stored with its importance score, memory type, and optional expiry.
Parameter Reference
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
content | str | ✅ | — | The text to store as a memory |
user_id | str | ✅ | — | Identifier for the end user |
agent_id | str | ✅ | — | Identifier for the agent |
memory_type | str | — | "episodic" | One of episodic, semantic, summary |
importance | float | — | 0.5 | Priority score from 0.0 to 1.0 |
ttl_days | int | None | — | None | Days until the memory auto-expires; None = permanent |
Memory Types
episodic
Things that happened. Use for events, interactions, and complaints. “User reported a slow delivery on 2024-11-03.”
semantic
Facts about the user. Use for preferences, attributes, and goals. “User prefers concise bullet points.”
summary
Compressed older memories. Auto-generated by MemLayer to save space while preserving context.
Auto-Deduplication
MemLayer checks every incoming memory against existing ones using cosine similarity. If a near-identical memory (similarity ≥ 0.95 by default) already exists, the store is silently skipped — no duplicate is created. If you want to check before committing to a store — for example, to skip an API call entirely — useis_duplicate():
remember() already performs deduplication internally. Use is_duplicate() only when you want to avoid the round-trip entirely, such as in high-throughput pipelines.Setting a TTL
Passttl_days to automatically expire a memory after a set number of days. MemLayer deletes it in the background — no manual cleanup needed.
ttl_days is provided (the default), the memory is stored permanently until you explicitly delete it or the user resets their data.
Searching Memories
Useclient.recall() to run a semantic search against a user’s memories. Results are ranked by a hybrid score combining semantic similarity, recency, and importance.
Hybrid Scoring
MemLayer blends three signals to rank results so the most useful memories always surface first:| Signal | Weight | What it captures |
|---|---|---|
| Semantic similarity | 70% | How closely the memory matches the query |
| Recency | 20% | How recently the memory was created or accessed |
| Importance | 10% | The importance score you assigned at store time |
min_score to control recall precision. A threshold of 0.70 is a good default; lower it toward 0.50 for broader results, raise it toward 0.85 for high-precision retrieval.
Updating a Memory
When a fact changes — a user moves cities, updates a preference, or corrects information — useclient.update() to replace the content in place. The memory keeps its original UUID, and MemLayer automatically re-embeds the new content.
Deleting a Memory
Delete a Single Memory
Useclient.forget() when a specific piece of information is no longer accurate or relevant:
Wipe All Memories
Useclient.forget_all() to permanently erase every memory for a user+agent pair. This is the right tool for GDPR deletion requests and account resets:
