Skip to content

Context Memory API

The Context Memory API retrieves and updates the persistent context memory associated with the current user.

Overview

Context memory stores a user-specific document that assistants can use across conversations. Each user has one context memory resource containing:

  • The memory scope and content identifiers
  • The stored document
  • The last update timestamp

Methods

unique_sdk.ContextMemory.retrieve - Retrieve context memory

Retrieve the context memory for the current user.

Parameters:

  • user_id (str, required) - User identifier
  • company_id (str, required) - Company identifier

Returns:

Returns a ContextMemory object.

Example:

memory = unique_sdk.ContextMemory.retrieve(
    user_id=user_id,
    company_id=company_id,
)

print(memory.document)

A missing context memory results in a 404 Not Found API error.

unique_sdk.ContextMemory.modify - Update context memory

Replace the context memory document for the current user.

Parameters:

  • user_id (str, required) - User identifier
  • company_id (str, required) - Company identifier
  • document (str, required) - New context memory document. An empty string clears the document.

Returns:

Returns the updated ContextMemory object.

Example - Update memory:

memory = unique_sdk.ContextMemory.modify(
    user_id=user_id,
    company_id=company_id,
    document="The user prefers concise answers in English.",
)

Example - Clear memory:

memory = unique_sdk.ContextMemory.modify(
    user_id=user_id,
    company_id=company_id,
    document="",
)

Async Methods

Both methods have async variants with an _async suffix:

  • retrieve_async
  • modify_async
memory = await unique_sdk.ContextMemory.modify_async(
    user_id=user_id,
    company_id=company_id,
    document="The user prefers concise answers in English.",
)

Return Types

ContextMemory

The ContextMemory object represents a user's persistent context memory

Fields:

  • scopeId (str) - Scope containing the context memory
  • contentId (str) - Content identifier of the stored memory
  • document (str) - Context memory document
  • updatedAt (str) - Last update timestamp in ISO 8601 format
  • object (Literal["context-memory"]) - Object type identifier

Returned by: ContextMemory.retrieve(), ContextMemory.modify()