Browse docs

SDK
Tap to expand
SDKUpdated 2026-05-30

User and Session Memory

Store, retrieve, and manage memory for users and conversations with the SDK.

Use user memory for long-term personalization and session memory for a specific conversation or workflow.

Remember a fact

ts
await db.user("user_123").remember("User prefers TypeScript examples.");

Remember a conversation

ts
await db.user("user_123").remember([
  { role: "user", content: "I use Next.js App Router." },
  { role: "assistant", content: "Got it." }
]);

The SDK extracts useful user-provided content from the messages.

Retrieve context

ts
const { context, raw } = await db
  .user("user_123")
  .getContext("What framework does this user use?");

Use context in your system prompt. Use raw when you need scores or result metadata.

Use it in a model call

ts
const { context } = await db
  .user("user_123")
  .getContext("How should I answer this billing question?");

const messages = [
  {
    role: "system",
    content: `Use this user memory when relevant:\n${context}`
  },
  {
    role: "user",
    content: "Can you explain billing retries?"
  }
];

Scope to a session

ts
const session = db.user("user_123").session("session_abc");

await session.remember("User is debugging webhook retries.");

const { context } = await session.getContext("What is the current issue?");

Forget a memory

ts
await db.user("user_123").forget("mem_...");

Best practices

  • Use your own stable userId and sessionId.
  • Store user-provided facts, preferences, instructions, and events.
  • Retrieve before the model call; remember after the turn.
  • Keep API keys server-side.

Next: Agent task API.

Was this page useful?

Your feedback helps us make the product easier to ship with.