Per-user memory for a chat product
Give each end user a Space, addressed by your own ID for that user. Conversations you store there are distilled into memories that belong to that Space only, and a search or an answer pinned to it reads nothing else.
Example
import { Mirabase } from "@mirabase/sdk";
const mb = new Mirabase(); // reads MIRABASE_API_KEY
// A client pinned to the user's Space. The Space is created on the first call.
const user = await mb.spaceFor("user-42", { name: "User 42" });
const receipt = await user.conversations.add(
[
{ role: "user", content: "I am vegetarian, and I prefer short answers." },
{ role: "assistant", content: "Noted." },
],
{ sessionId: "chat-42" },
);
await mb.processing.wait(receipt); // until the memories are distilled
const pack = await user.context("What should I keep in mind when suggesting dinner?");
from mirabase import Mirabase
mb = Mirabase() # reads MIRABASE_API_KEY
# A client pinned to the user's Space. The Space is created on the first call.
user = mb.space_for("user-42", name="User 42")
receipt = user.conversations.add(
[
{"role": "user", "content": "I am vegetarian, and I prefer short answers."},
{"role": "assistant", "content": "Noted."},
],
session_id="chat-42",
)
mb.processing.wait(receipt) # until the memories are distilled
pack = user.context("What should I keep in mind when suggesting dinner?")
Over HTTP, PUT https://api.mirabase.io/v2/spaces/ext:user-42 returns that Space or creates it, and ext:user-42 then works wherever a Space ID does. See Choose the Space a call uses.
Limits
- Memory is kept per Space. Metadata does not separate memories, so use a Space per user for a hard wall between users.
- A search, context or answer call that specifies no Space reads every Space the key can read. Use a pinned client, or specify the Space on each call.
- Memories are distilled in the background after the conversation is stored, so they are not yet available when the call returns. Wait for processing, or read them later.
- Distilled memories are
confirmedwhen the caller holdsmemory:confirm; otherwise they arecandidateand stay out of retrieval until reviewed. See Distill memories from a conversation. - An account has a cap on the number of Spaces.
GET /v2/limitsreturns it.