WeaviateEx.API.Tenants (WeaviateEx v0.7.4)

View Source

Multi-tenancy operations with gRPC support.

Provides complete tenant management:

  • CRUD operations (list, get, create, update, delete)
  • Activity status management (HOT, COLD, FROZEN)
  • Tenant isolation and filtering
  • Batch operations

Uses gRPC for list/get operations when available for optimal performance. Create, update, and delete operations use HTTP as they're not available via gRPC.

Summary

Functions

Activate tenant (set to HOT status).

Returns the batch size used for batch operations.

Updates tenants in batches of 100 (matching Python client behavior).

Count total tenants for a collection.

Deactivate tenant (set to COLD status).

Delete one or more tenants.

Ensures a tenant exists and is active (HOT).

Freeze tenant (set to FROZEN status).

Get specific tenant information.

List all tenants for a collection.

List only active (HOT) tenants.

List only inactive (COLD/FROZEN) tenants.

Offload tenant (set to OFFLOADED status).

Update tenant(s) activity status.

Updates multiple tenants' status in a single batch.

Types

activity_status()

@type activity_status() :: :active | :inactive | :hot | :cold | :frozen | :offloaded

collection_name()

@type collection_name() :: String.t()

opts()

@type opts() :: keyword()

tenant_name()

@type tenant_name() :: String.t()

tenant_names()

@type tenant_names() :: tenant_name() | [tenant_name()]

Functions

activate(client, collection_name, tenant_names)

@spec activate(WeaviateEx.Client.t(), collection_name(), tenant_names()) ::
  {:ok, [map()]} | {:error, WeaviateEx.Error.t()}

Activate tenant (set to HOT status).

Examples

{:ok, _} = Tenants.activate(client, "Article", "TenantA")
{:ok, _} = Tenants.activate(client, "Article", ["TenantA", "TenantB"])

Returns

  • {:ok, [map()]} - Updated tenants
  • {:error, Error.t()} - Error if update fails

batch_size()

@spec batch_size() :: pos_integer()

Returns the batch size used for batch operations.

Examples

100 = Tenants.batch_size()

batch_update(client, collection_name, tenants)

@spec batch_update(WeaviateEx.Client.t(), collection_name(), [map()]) ::
  {:ok, [map()]} | {:error, WeaviateEx.Error.t()}

Updates tenants in batches of 100 (matching Python client behavior).

This is useful for updating large numbers of tenants efficiently without overwhelming the server with a single large request.

Examples

tenants = [
  %{name: "tenant1", activity_status: :hot},
  %{name: "tenant2", activity_status: :cold}
]
{:ok, results} = Tenants.batch_update(client, "Article", tenants)

Returns

  • {:ok, [map()]} - All updated tenants combined
  • {:error, Error.t()} - Error from first failed batch

count(client, collection_name)

@spec count(WeaviateEx.Client.t(), collection_name()) ::
  {:ok, integer()} | {:error, WeaviateEx.Error.t()}

Count total tenants for a collection.

Examples

{:ok, 5} = Tenants.count(client, "Article")

Returns

  • {:ok, integer()} - Number of tenants
  • {:error, Error.t()} - Error if request fails

create(client, collection_name, tenant_names, opts \\ [])

@spec create(WeaviateEx.Client.t(), collection_name(), tenant_names(), opts()) ::
  {:ok, [map()]} | {:error, WeaviateEx.Error.t()}

Create one or more tenants.

Examples

{:ok, _} = Tenants.create(client, "Article", "TenantA")
{:ok, _} = Tenants.create(client, "Article", ["TenantA", "TenantB"])
{:ok, _} = Tenants.create(client, "Article", "TenantA", activity_status: :cold)

Returns

  • {:ok, [map()]} - Created tenants
  • {:error, Error.t()} - Error if creation fails

deactivate(client, collection_name, tenant_names)

@spec deactivate(WeaviateEx.Client.t(), collection_name(), tenant_names()) ::
  {:ok, [map()]} | {:error, WeaviateEx.Error.t()}

Deactivate tenant (set to COLD status).

Examples

{:ok, _} = Tenants.deactivate(client, "Article", "TenantA")

Returns

  • {:ok, [map()]} - Updated tenants
  • {:error, Error.t()} - Error if update fails

delete(client, collection_name, tenant_name)

@spec delete(WeaviateEx.Client.t(), collection_name(), tenant_names()) ::
  {:ok, map()} | {:error, WeaviateEx.Error.t()}

Delete one or more tenants.

Examples

{:ok, _} = Tenants.delete(client, "Article", "TenantA")
{:ok, _} = Tenants.delete(client, "Article", ["TenantA", "TenantB"])

Returns

  • {:ok, map()} - Empty map on success
  • {:error, Error.t()} - Error if deletion fails

ensure_active(client, collection_name, tenant_name)

@spec ensure_active(WeaviateEx.Client.t(), collection_name(), tenant_name()) ::
  :ok | {:error, WeaviateEx.Error.t()}

Ensures a tenant exists and is active (HOT).

Creates the tenant if it doesn't exist (when auto-creation is not enabled). Activates the tenant if it's not HOT.

Examples

:ok = Tenants.ensure_active(client, "Articles", "tenant1")

Returns

  • :ok - Tenant is now active
  • {:error, Error.t()} - Error if operation fails

exists?(client, collection_name, tenant_name)

@spec exists?(WeaviateEx.Client.t(), collection_name(), tenant_name()) ::
  {:ok, boolean()}

Check if tenant exists.

Examples

{:ok, true} = Tenants.exists?(client, "Article", "TenantA")
{:ok, false} = Tenants.exists?(client, "Article", "NonExistent")

Returns

  • {:ok, boolean()} - True if exists, false otherwise

freeze(client, collection_name, tenant_names)

@spec freeze(WeaviateEx.Client.t(), collection_name(), tenant_names()) ::
  {:ok, [map()]} | {:error, WeaviateEx.Error.t()}

Freeze tenant (set to FROZEN status).

Frozen tenants have their data persisted but are not loaded into memory. This is more aggressive than COLD status.

Examples

{:ok, _} = Tenants.freeze(client, "Article", "TenantA")
{:ok, _} = Tenants.freeze(client, "Article", ["TenantA", "TenantB"])

Returns

  • {:ok, [map()]} - Updated tenants
  • {:error, Error.t()} - Error if update fails

get(client, collection_name, tenant_name)

@spec get(WeaviateEx.Client.t(), collection_name(), tenant_name()) ::
  {:ok, map()} | {:error, WeaviateEx.Error.t()}

Get specific tenant information.

Uses gRPC when available for optimal performance, falls back to HTTP otherwise.

Examples

{:ok, tenant} = Tenants.get(client, "Article", "TenantA")

Returns

  • {:ok, map()} - Tenant information
  • {:error, Error.t()} - Error if not found

list(client, collection_name)

@spec list(WeaviateEx.Client.t(), collection_name()) ::
  {:ok, [map()]} | {:error, WeaviateEx.Error.t()}

List all tenants for a collection.

Uses gRPC when available for optimal performance, falls back to HTTP otherwise.

Examples

{:ok, tenants} = Tenants.list(client, "Article")

Returns

  • {:ok, [map()]} - List of tenants
  • {:error, Error.t()} - Error if request fails

list_active(client, collection_name)

@spec list_active(WeaviateEx.Client.t(), collection_name()) ::
  {:ok, [map()]} | {:error, WeaviateEx.Error.t()}

List only active (HOT) tenants.

Examples

{:ok, active_tenants} = Tenants.list_active(client, "Article")

Returns

  • {:ok, [map()]} - List of active tenants
  • {:error, Error.t()} - Error if request fails

list_inactive(client, collection_name)

@spec list_inactive(WeaviateEx.Client.t(), collection_name()) ::
  {:ok, [map()]} | {:error, WeaviateEx.Error.t()}

List only inactive (COLD/FROZEN) tenants.

Examples

{:ok, inactive_tenants} = Tenants.list_inactive(client, "Article")

Returns

  • {:ok, [map()]} - List of inactive tenants
  • {:error, Error.t()} - Error if request fails

offload(client, collection_name, tenant_names)

@spec offload(WeaviateEx.Client.t(), collection_name(), tenant_names()) ::
  {:ok, [map()]} | {:error, WeaviateEx.Error.t()}

Offload tenant (set to OFFLOADED status).

Offloaded tenants are moved to cold storage. This is the most aggressive deactivation option and may take longer to reactivate.

Examples

{:ok, _} = Tenants.offload(client, "Article", "TenantA")
{:ok, _} = Tenants.offload(client, "Article", ["TenantA", "TenantB"])

Returns

  • {:ok, [map()]} - Updated tenants
  • {:error, Error.t()} - Error if update fails

update(client, collection_name, tenant_name, opts)

@spec update(WeaviateEx.Client.t(), collection_name(), tenant_names(), opts()) ::
  {:ok, [map()]} | {:error, WeaviateEx.Error.t()}

Update tenant(s) activity status.

Examples

{:ok, _} = Tenants.update(client, "Article", "TenantA", activity_status: :cold)
{:ok, _} = Tenants.update(client, "Article", ["TenantA", "TenantB"], activity_status: :hot)

Returns

  • {:ok, [map()]} - Updated tenants
  • {:error, Error.t()} - Error if update fails

update_many(client, collection_name, updates, opts \\ [])

@spec update_many(WeaviateEx.Client.t(), collection_name(), [map()], keyword()) ::
  :ok | {:error, WeaviateEx.Error.t()}

Updates multiple tenants' status in a single batch.

Batches updates into groups of 100 (Weaviate limit). This is an alias for batch_update/3 with additional options support.

Examples

# Activate multiple tenants
Tenants.update_many(client, "Articles", [
  %{name: "tenant1", status: :hot},
  %{name: "tenant2", status: :hot}
])

# Deactivate tenants
Tenants.update_many(client, "Articles", [
  %{name: "tenant1", status: :cold}
])

# With custom batch size
Tenants.update_many(client, "Articles", updates, batch_size: 50)

Returns

  • :ok - All updates succeeded
  • {:error, Error.t()} - Error from first failed batch