WeaviateEx.Config.AutoTenant (WeaviateEx v0.7.4)

View Source

Auto-tenant configuration for multi-tenant collections.

Weaviate supports automatic tenant management that can:

  • Automatically create tenants when inserting data for non-existent tenants
  • Automatically activate tenants (set to HOT) on first operation
  • Automatically delete empty tenants after a specified period

Usage

# Enable auto-tenant creation
auto_tenant = WeaviateEx.Config.AutoTenant.enable()

# Enable with auto-deletion of empty tenants
auto_tenant = WeaviateEx.Config.AutoTenant.enable(auto_delete_timeout: 86400)

# Enable with auto-creation and auto-activation
auto_tenant = WeaviateEx.Config.AutoTenant.new(
  auto_creation: true,
  auto_activation: true
)

# Include in collection creation
WeaviateEx.Collections.create(client, "MyClass", %{
  properties: [...],
  multi_tenancy: %{enabled: true},
  auto_tenant: auto_tenant
})

# Disable auto-tenant
WeaviateEx.Collections.update("MyClass", %{
  auto_tenant: WeaviateEx.Config.AutoTenant.disable()
})

Summary

Functions

Disable auto-tenant functionality.

Enable auto-tenant creation.

Create an auto-tenant config from a map (e.g., from API response).

Create a fully automatic tenant configuration.

Create an auto-tenant config with custom settings.

Convert an auto-tenant config struct to a map for the Weaviate API.

Create a configuration with auto-tenant activation enabled.

Create a configuration with auto-tenant creation enabled.

Types

t()

@type t() :: %WeaviateEx.Config.AutoTenant{
  auto_activation: boolean(),
  auto_creation: boolean(),
  auto_delete_timeout: non_neg_integer() | nil,
  enabled: boolean()
}

Functions

disable()

@spec disable() :: t()

Disable auto-tenant functionality.

Use this when updating a collection to turn off automatic tenant management.

Examples

WeaviateEx.Collections.update("MyClass", %{
  auto_tenant: WeaviateEx.Config.AutoTenant.disable()
})

enable(opts \\ [])

@spec enable(keyword()) :: t()

Enable auto-tenant creation.

When enabled, Weaviate will automatically create tenants when data is inserted for a tenant that doesn't exist yet.

Options

  • :auto_creation - Enable auto-creation of tenants (default: true when using enable/1)
  • :auto_activation - Enable auto-activation of tenants (default: false)
  • :auto_delete_timeout - Time in seconds after which empty tenants are automatically deleted. If not specified, auto-deletion is disabled.

Examples

# Just enable auto-creation
WeaviateEx.Config.AutoTenant.enable()

# Enable with auto-deletion after 24 hours of inactivity
WeaviateEx.Config.AutoTenant.enable(auto_delete_timeout: 86400)

# Enable with auto-activation
WeaviateEx.Config.AutoTenant.enable(auto_activation: true)

# Enable both auto-creation and auto-activation
WeaviateEx.Config.AutoTenant.enable(auto_creation: true, auto_activation: true)

from_map(map)

@spec from_map(map()) :: t()

Create an auto-tenant config from a map (e.g., from API response).

Examples

iex> map = %{"enabled" => true, "autoDeleteTimeout" => 3600}
iex> WeaviateEx.Config.AutoTenant.from_map(map)
%WeaviateEx.Config.AutoTenant{enabled: true, auto_creation: false, auto_activation: false, auto_delete_timeout: 3600}

iex> map = %{"autoTenantCreation" => true, "autoTenantActivation" => true}
iex> WeaviateEx.Config.AutoTenant.from_map(map)
%WeaviateEx.Config.AutoTenant{enabled: false, auto_creation: true, auto_activation: true, auto_delete_timeout: nil}

fully_automatic()

@spec fully_automatic() :: t()

Create a fully automatic tenant configuration.

This enables both auto-tenant creation and activation.

Examples

WeaviateEx.Config.AutoTenant.fully_automatic()
# => %WeaviateEx.Config.AutoTenant{enabled: true, auto_creation: true, auto_activation: true}

new(opts)

@spec new(keyword()) :: t()

Create an auto-tenant config with custom settings.

Options

  • :enabled - Enable auto-tenant features (default: false)
  • :auto_creation - Enable auto-creation of tenants (default: false)
  • :auto_activation - Enable auto-activation of tenants (default: false)
  • :auto_delete_timeout - Time in seconds after which empty tenants are automatically deleted. If not specified, auto-deletion is disabled.

Examples

# Custom configuration with auto-deletion
WeaviateEx.Config.AutoTenant.new(enabled: true, auto_delete_timeout: 3600)

# Enable auto-creation and auto-activation
WeaviateEx.Config.AutoTenant.new(auto_creation: true, auto_activation: true)

# Full configuration
WeaviateEx.Config.AutoTenant.new(
  enabled: true,
  auto_creation: true,
  auto_activation: true,
  auto_delete_timeout: 86400
)

to_map(config)

@spec to_map(t()) :: map()

Convert an auto-tenant config struct to a map for the Weaviate API.

Examples

iex> config = WeaviateEx.Config.AutoTenant.enable(auto_delete_timeout: 3600)
iex> WeaviateEx.Config.AutoTenant.to_map(config)
%{
  "enabled" => true,
  "autoTenantCreation" => true,
  "autoTenantActivation" => false,
  "autoDeleteTimeout" => 3600
}

iex> config = WeaviateEx.Config.AutoTenant.new(auto_creation: true, auto_activation: true)
iex> WeaviateEx.Config.AutoTenant.to_map(config)
%{
  "enabled" => false,
  "autoTenantCreation" => true,
  "autoTenantActivation" => true
}

with_auto_activation()

@spec with_auto_activation() :: t()

Create a configuration with auto-tenant activation enabled.

When auto-tenant activation is enabled, inactive tenants are automatically activated (set to HOT) when they are accessed.

Examples

WeaviateEx.Config.AutoTenant.with_auto_activation()
# => %WeaviateEx.Config.AutoTenant{enabled: true, auto_creation: false, auto_activation: true}

with_auto_creation()

@spec with_auto_creation() :: t()

Create a configuration with auto-tenant creation enabled.

When auto-tenant creation is enabled, tenants are automatically created when data is first inserted for a non-existent tenant.

Examples

WeaviateEx.Config.AutoTenant.with_auto_creation()
# => %WeaviateEx.Config.AutoTenant{enabled: true, auto_creation: true, auto_activation: false}