tenant_id
and sub_tenant_id
is crucial for implementing proper data isolation and access control.
Understanding Tenant Hierarchy
Tenant ID (tenant_id
) - Your Organization
The tenant_id is like your company’s main identifier. It represents the primary organizational unit - typically your main enterprise client or organization. This is the top-level identifier that provides the broadest scope of data isolation.
Think of it as: The company name or organization ID that completely separates your data from all other organizations using Cortex.
Sub-Tenant ID (sub_tenant_id
) - Your Department/Team
The sub_tenant_id represents a subdivision within a tenant - such as departments, teams, or individual customers within an enterprise. This enables hierarchical data organization and more granular access control.
Think of it as: The department or team name within your company (like “Engineering”, “Sales”, or “HR”).
Default Sub-Tenant Behavior
Important: When you create a tenant, Cortex automatically creates a DEFAULT sub-tenant that acts as a global space for that tenant.- If you don’t specify a
sub_tenant_id
when using any API, your data will be stored in this default sub-tenant - This means if you upload documents with just a
tenant_id
and leavesub_tenant_id
empty, they’ll go to the default sub-tenant - The default sub-tenant is perfect for organization-wide data that should be accessible across all departments
Creating Additional Sub-Tenants
No Explicit API Required: Cortex doesn’t require a separate API call to create sub-tenants. Sub-tenants are created automatically when you first use a newsub_tenant_id
that doesn’t exist yet.
How Sub-Tenant Creation Works
- Automatic Creation: When you upload a document, text, or any content with a
sub_tenant_id
that doesn’t exist, Cortex automatically creates that sub-tenant - First Upload Triggers Creation: The first API call with a new
sub_tenant_id
will create the sub-tenant and then process your content - Immediate Availability: Once created, the sub-tenant is immediately available for all subsequent operations
engineering_team_alpha
doesn’t exist as a sub-tenant under acme_corp
, Cortex will:
- ✅ Create the new sub-tenant
engineering_team_alpha
- ✅ Upload and process the document
- ✅ Make the sub-tenant available for future operations
Sub-Tenant ID Best Practices
Recommended Naming Conventions
For User-Based Sub-Tenants (B2C):Best Practices for Sub-Tenant IDs
- Use Consistent Naming: Establish a clear naming convention across your application
- Include Prefixes: Use prefixes like
user_
,dept_
,project_
to make the purpose clear - Avoid Special Characters: Stick to alphanumeric characters and underscores
- Keep It Descriptive: Make sub-tenant IDs self-explanatory
- Consider Hierarchies: For complex organizations, consider hierarchical naming like
dept_engineering_team_alpha
Multi-Tenant Architecture
What it is:Cortex’s multi-tenant system creates completely isolated workspaces at both the tenant and sub-tenant levels. All documents, search results, embeddings, and AI memories are isolated per tenant/sub-tenant combination, ensuring zero cross-contamination of data. Key Benefits:
- Complete Data Isolation: Zero cross-contamination between tenants and sub-tenants
- Scalable B2B Architecture: Serve unlimited organizations and their subdivisions
- Granular Access Control: Control data access at organization and department levels
- Performance Optimization: Tenant-scoped searches for faster results
- Compliance Ready: Meet enterprise security and privacy requirements
Real-World Use Cases
1. Enterprise SaaS Platform
Scenario: You’re building an AI knowledge assistant for multiple enterprise clients.- Each enterprise client gets their own
tenant_id
- Each department within the enterprise gets their own
sub_tenant_id
- Documents uploaded by Acme’s Engineering team are only accessible to Acme Corporation (
tenant_id: "acme_corp"
) and specifically to the Engineering department (sub_tenant_id: "engineering"
)
2. Consulting Firm with Multiple Clients
Scenario: A consulting firm serving multiple clients with project-based work.- Your consulting firm is the main
tenant_id
- Each client project gets its own
sub_tenant_id
- Client Alpha’s documents are completely isolated from Client Beta’s data
- Internal firm knowledge can be kept separate from client work
3. Educational Platform
Scenario: An AI-powered learning platform serving multiple schools.- Each university is a separate
tenant_id
- Each department/school is a
sub_tenant_id
- Research papers and course materials are isolated by institution and department
4. Multi-Brand E-commerce
Scenario: A company managing multiple brands with different customer bases.- The parent company is the
tenant_id
- Each brand is a
sub_tenant_id
- Customer data, product catalogs, and support documents are brand-specific
API Implementation
When making API calls, always include both identifiers:Default Behavior
- If
sub_tenant_id
is not provided, it automatically uses the DEFAULT sub-tenant created when the tenant was set up - This means the search/operation applies to the default sub-tenant scope (organization-wide data)
- For tenant-wide operations, you can omit
sub_tenant_id
and your data will be stored in the default sub-tenant - The default sub-tenant acts as a global space where organization-wide documents and data are stored
Security and Isolation
Data Isolation Guarantees
- Tenant Level: No data can ever cross tenant boundaries
- Sub-Tenant Level: Data is isolated within sub-tenants unless explicitly queried at tenant level
- Search Scope: All searches are automatically scoped to the specified tenant/sub-tenant
- Memory Isolation: AI memories are completely isolated per tenant/sub-tenant combination
Access Patterns
- Tenant-Wide Access: Use same value for both
tenant_id
andsub_tenant_id
- Sub-Tenant Specific: Use specific
sub_tenant_id
within atenant_id
- Cross Sub-Tenant: Not supported - maintains strict isolation