Multitenancy

Learn how to organize and manage data for multiple tenants in SourceSync.

Overview

SourceSync supports multitenancy through three primary mechanisms:

  1. Native Tenant Support: Using X-Tenant-ID header for automatic tenant isolation
  2. Namespaces: For complete data isolation between tenants
  3. Metadata: For flexible tenant-specific organization within namespaces

Choosing Your Approach

Best for organizations that need:

  • Automatic tenant isolation without infrastructure changes
  • Simple tenant management with header-based control
  • Flexible scaling across tenants
  • Cost-effective multi-tenant deployments

Implementation:

  1. Add the X-Tenant-ID header to your API requests:

    curl -X POST https://api.sourcesync.ai/v1/ingest/text \
      -H "Authorization: Bearer $RAGAAS_API_KEY" \
      -H "X-Tenant-ID: tenant-123" \
      -H "Content-Type: application/json" \
      -d '{
        "namespaceId": "shared-namespace",
        "ingestConfig": {
          "source": "TEXT",
          "config": {
            "text": "Document content..."
          }
        }
      }'
    
  2. Documents are automatically isolated by tenant:

    • Each document is tagged with the tenant ID
    • Search and retrieval automatically scoped to tenant
    • No cross-tenant data access possible
  3. Benefits:

    • No need for separate infrastructure per tenant
    • Automatic tenant isolation in shared namespaces
    • Simplified tenant management
    • Cost-effective scaling

Namespace-Based Isolation

Best for organizations that need:

  • Complete data isolation between tenants
  • Separate infrastructure per tenant
  • Independent scaling and billing
  • Compliance with data residency

Not suitable when:

  • Content sharing between tenants is required
  • Cost optimization is priority
  • Managing many small tenants

Metadata-Based Organization

Best for organizations that need:

  • Shared infrastructure across tenants
  • Flexible content sharing
  • Cost-effective solution
  • Simple tenant management

Not suitable when:

  • Strict data isolation is required
  • Compliance requires separate infrastructure

Implementation

Using Namespaces

Create a dedicated namespace for each tenant:

curl -X POST https://api.sourcesync.ai/v1/namespaces \
  -H "Authorization: Bearer $RAGAAS_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "tenant1-production",
    "fileStorageConfig": {
      "provider": "S3",
      "bucket": "tenant1-docs",
      "region": "us-east-1",
      "credentials": {
        "accessKeyId": "...",
        "secretAccessKey": "..."
      }
    },
    "vectorStorageConfig": {
      "provider": "PINECONE",
      "apiKey": "...",
      "indexHost": "tenant1.pinecone.io"
    },
    "embeddingModelConfig": {
      "provider": "OPENAI",
      "model": "text-embedding-3-small",
      "apiKey": "..."
    }
  }'

Using Metadata

Add tenant information during document ingestion:

curl -X POST https://api.sourcesync.ai/v1/ingest/text \
  -H "Authorization: Bearer $RAGAAS_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "namespaceId": "shared-namespace",
    "ingestConfig": {
      "source": "TEXT",
      "config": {
        "text": "Company policy document...",
        "metadata": {
          "tenantId": "tenant-123",
          "department": "hr",
          "accessLevel": "internal",
          "region": "us-west"
        }
      }
    }
  }'

Filter content by tenant metadata:

curl -X POST https://api.sourcesync.ai/v1/search \
  -H "Authorization: Bearer $RAGAAS_API_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "company policy",
    "namespaceId": "shared-namespace",
    "filter": {
      "metadata": {
        "tenantId": "tenant-123",
        "accessLevel": "internal"
      }
    }
  }'

Examples

Document Search with Tenant Isolation

Search documents within a tenant's scope:

curl -X POST https://api.sourcesync.ai/v1/search \
  -H "Authorization: Bearer $RAGAAS_API_KEY" \
  -H "X-Tenant-ID: tenant-123" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "company policies",
    "namespaceId": "shared-namespace",
    "topK": 10,
    "filter": {
      "metadata": {
        "status": "published"
      }
    }
  }'

Document Management with Tenant Isolation

List documents for a specific tenant:

curl -X POST https://api.sourcesync.ai/v1/documents \
  -H "Authorization: Bearer $RAGAAS_API_KEY" \
  -H "X-Tenant-ID: tenant-123" \
  -H "Content-Type: application/json" \
  -d '{
    "namespaceId": "shared-namespace",
    "filterConfig": {
      "documentTypes": ["PDF", "DOCX"],
      "metadata": {
        "status": "published"
      }
    },
    "pagination": {
      "pageSize": 10
    }
  }'

Best Practices

  1. Organization

    • Use clear naming conventions (e.g., {tenant}-{environment})
    • Define consistent metadata schema
    • Separate production and non-production environments
  2. Security

    • Implement tenant validation in your application
    • Use metadata for access control
    • Consider regulatory requirements
  3. Performance

    • Monitor resource usage per namespace
    • Use appropriate metadata indexing
    • Consider tenant size when choosing approach

Tenant ID Format

  1. Use consistent, URL-safe tenant identifiers:

    • Alphanumeric characters
    • Hyphens and underscores
    • Lowercase recommended
    • Example: tenant-123, org-456-dept-789
  2. Keep tenant IDs short but meaningful:

    • Include organization identifier
    • Add sub-organization if needed