Satori implements a robust multi-tenant architecture that ensures complete data isolation between tenants and their end users. This page explains how isolation works and why it matters for your application.
Here’s how isolation is enforced at the database level:
Copy
CREATE TABLE memories ( id UUID PRIMARY KEY, clerk_user_id TEXT NOT NULL, -- Tenant identifier user_id TEXT NOT NULL, -- End-user identifier content TEXT NOT NULL, embedding VECTOR(1536), metadata JSONB, created_at TIMESTAMP, updated_at TIMESTAMP);-- Composite index for fast tenant + user queriesCREATE INDEX memories_tenant_user_idxON memories (clerk_user_id, user_id);
Every query automatically includes both identifiers:
Copy
// When you search memoriesconst memories = await db .select() .from(memories) .where( and( eq(memories.clerkUserId, 'user_372Icb...'), // Your tenant eq(memories.userId, 'alice') // Specific user ) );
It’s impossible to query memories without both identifiers, ensuring complete isolation.
// ❌ NEVER DO THISconst tools = memoryTools({ apiKey: process.env.SATORI_API_KEY!, baseUrl: process.env.SATORI_URL!, userId: 'shared-user', // All users share memories!});
Consider namespacing for complex scenarios
If you have multiple contexts per user, use namespaced IDs:
Copy
// Different workspaces for the same useruserId: `${user.id}:workspace:${workspaceId}`// Example: "user_123:workspace:acme-corp"// Different conversation threadsuserId: `${user.id}:thread:${threadId}`// Example: "user_123:thread:support-2024-01"
Document your user ID strategy
Keep a record of how you generate user IDs for consistency:
export async function POST(req: Request) { // Get authenticated user from your auth system const session = await getSession(req); if (!session?.userId) { return new Response('Unauthorized', { status: 401 }); } // Use the authenticated user's ID const tools = memoryTools({ apiKey: process.env.SATORI_API_KEY!, baseUrl: process.env.SATORI_URL!, userId: session.userId, // Verified by your auth system });}
Never trust user IDs from client requests. Always verify the user’s identity through your authentication system.