GitHub
Examples

Multi-Tenant Memory

Strictly isolate data and manage quotas for different organizations or users.

Ops Module
Scenario: Hosting memory for "Springfield High School"

When to Use

If you are building a SaaS where multiple customers (tenants) use your platform, you must ensure Tenant A never sees Tenant B's memories. Perfect for:

  • B2B Applications
  • Managing tiered usage limits (Free vs Pro tiers)
  • Strict data isolation compliance

Key Operations

create()

Provision a new tenant

get_usage()

Check tenant resource consumption

Code Example

Provision a new tenant with specific storage and request quotas.

# 1. Create a Tenant with Quotas
client.memory.tenants.create(
tenant_id="school_district_01",
tenant_name="Springfield High School",
quotas={
"max_storage_mb": 500,
"max_rpm": 100 # Requests per minute
}
)
# 2. Managing Data
# When iterating, pass the tenant_id to ensure isolation
client.memory.episodes.create(
...,
tenant_id="school_district_01"
)
# 3. Check Usage
usage = client.memory.tenants.get_usage("school_district_01")
print(f"Storage Used: {usage['storage_mb']} / 500 MB")

Key Takeaways

  • Logical Isolation: The SDK handles tagging data with tenant_id automatically when provided.
  • Quota Management: Enforce limits to prevent one noisy tenant from affecting others.
  • Supports "Batch Ingest" for tenants to efficiently load their initial data.