Skip to main content

Multi-tenancy operations

LICENSE Weaviate on Stackoverflow badge Weaviate issues on GitHub badge Weaviate version badge Weaviate total Docker pulls badge Go Report Card

Enable multi-tenancy

Multi-tenancy availability
  • Multi-tenancy available from version v1.20
  • (Experimental) Tenant activity status setting available from version v1.21

Multi-tenancy is disabled by default. To enable it, set the multiTenancyConfig variable in the class definition as shown below:

{
"class": "MultiTenancyClass",
"multiTenancyConfig": {"enabled": true}
}

Class operations

Add tenant(s)

To add tenants to a class, you must provide the tenant names to the Weaviate class. From 1.21 onwards, you can also optionally specify whether the tenant is to be active (HOT, default), or inactive (COLD).

Allowable tenant names

A tenant name can only contain alphanumeric characters (a-z, A-Z, 0-9), underscore (_), and hyphen (-), with a length of 4 to 64 characters.

Code examples are shown below in which the tenants tenantA and tenantB are added to the class MultiTenancyClass:

from weaviate import Tenant

client.schema.create_class({
'class': 'MultiTenancyClass',
'multiTenancyConfig': {'enabled': True}
})

client.schema.add_class_tenants(
class_name='MultiTenancyClass', # The class to which the tenants will be added
tenants=[Tenant(name='tenantA'), Tenant(name='tenantB')]
)

List tenant(s)

To list existing tenants in a class, you must provide the Weaviate class name.

Code examples are shown below for listing the existing tenants in the MultiTenancyClass class:

tenants = client.schema.get_class_tenants(
class_name='MultiTenancyClass' # The class from which the tenants will be retrieved
)

Delete tenant(s)

You can delete one or more existing tenants in a class by providing the Weaviate class name.

If a tenant specified for deletion doesn't belong to the class, it is ignored.

client.schema.remove_class_tenants(
class_name='MultiTenancyClass', # The class from which the tenants will be removed
tenants=['tenantB', 'tenantX'] # The tenants to be removed. tenantX will be ignored.
)

Update tenant(s)

Available from version v1.21

You can update one or more existing tenants' activity status to active ("HOT") or inactive ("COLD").

Client code examples coming soon

For now, please send a PUT request through the REST API endpoint to update the tenant activity status.

Object operations

CRUD operations

If multi-tenancy is enabled, you must provide the tenant name to Weaviate in each CRUD operation.

Code examples are shown below for creating an object in the MultiTenancyClass class:

object_id = client.data_object.create(
class_name='MultiTenancyClass', # The class to which the object will be added
data_object={
'question': 'This vector DB is OSS & supports automatic property type inference on import'
},
tenant='tenantA' # The tenant to which the object will be added
)

Search queries

Get and Aggregate queries support multi-tenancy operations. (Explore queries do not support multi-tenancy operations at this point.)

If multi-tenancy is enabled, you must provide the tenant name to Weaviate in each search query.

Code examples are shown below for fetching one object in the MultiTenancyClass class from the tenant tenantA:

result = (
client.query.get('MultiTenancyClass', ['question'])
.with_tenant('tenantA')
.do()
)

Cross-references

If multi-tenancy is enabled, you must provide the tenant name to Weaviate while creating, updating or deleting cross-references.

You can establish a cross-reference from a multi-tenancy class object to:

  • A non-multi-tenancy class object, or
  • A multi-tenancy class object belonging to the same tenant.

The example below creates a cross-reference between two objects. It links an object in the MultiTenancyClass class that belongs to tenantA, to an object in the JeopardyCategory class:

# Add the cross-reference property to the multi-tenancy class
client.schema.property.create('MultiTenancyClass', {
'name': 'hasCategory',
'dataType': ['JeopardyCategory'],
})

client.data_object.reference.add(
from_uuid=object_id, # MultiTenancyClass object id (a Jeopardy question)
from_class_name='MultiTenancyClass',
from_property_name='hasCategory',
tenant='tenantA',
to_class_name='JeopardyCategory',
to_uuid=category_id
)

As described above, the JeopardyCategory class object can be either:

  • A non-multi-tenancy object or
  • A multi-tenancy object belonging to tenantA.

More Resources

For additional information, try these sources.

  1. Frequently Asked Questions
  2. Weaviate Community Forum
  3. Knowledge base of old issues
  4. Stackoverflow
  5. Weaviate slack channel