Hi everyone,
I am working on a multi-tenant setup where each tenant can have multiple projects (collections) in Weaviate. For example:
- Tenant 1: Collection A, Collection B, etc.
- Tenant 2: Collection D, Collection E, etc.
Ideally, it would be more manageable if I could structure it as follows:
- Under Tenant 1: Collection A, Collection B, …
- Under Tenant 2: Collection D, Collection E, …
However, Weaviate currently supports multiple tenants under a collection, but not multiple collections under tenants.
What would be the best way to handle this structure efficiently within the current capabilities of Weaviate? Any suggestions or best practices would be greatly appreciated!
Thank you!
hi @rakend_dubba !!
Welcome to our community!
Not sure I got this part right:
However, Weaviate currently supports multiple tenants under a collection, but not multiple collections under tenants.
Consider this code:
from weaviate.classes.config import Configure, Property, DataType
collections = ["CollectionA", "CollectionB", "CollectionD", "CollectionE"]
for c in ["CollectionA", "CollectionB", "CollectionD", "CollectionE"]:
client.collections.delete(c)
client.collections.create(
name=c,
vectorizer_config=Configure.Vectorizer.none(),
multi_tenancy_config=Configure.multi_tenancy(enabled=True, auto_tenant_activation=True),
properties=[
Property(name="text", data_type=DataType.TEXT)
]
)
from weaviate.classes.tenants import Tenant
client.collections.get("CollectionA").tenants.create(["tenant1"])
client.collections.get("CollectionA").tenants.get()
tenant1_col_a = client.collections.get("CollectionA").with_tenant("tenant1")
tenant1_col_a.data.insert({"text": "data1 in col_a tenant1"})
tenant1_col_b = client.collections.get("CollectionB").with_tenant("tenant1")
tenant1_col_a.data.insert({"text": "data2 in col_b tenant1"})
You will endup with isolated data for tenant1 in both collections.
Let me know if this helps.
Thanks!
Hi,
Thanks for your response and the detailed code example.
If we are only using one tenant per collection, it seems redundant to enable multi-tenancy. The current multi-tenancy in Weaviate works well if the schema is the same for each tenant. However, if each tenant has a different schema for their projects, we need to create different collections for each project.
However, Weaviate currently supports multiple tenants under a collection, but not multiple collections under tenants.
What I mean is that Weaviate has a strict hierarchy where we can have multiple tenants under a collection, but we cannot create multiple collections under a tenant.
The current multi-tenancy feature is helpful when all tenants share the same schema, which is often the case. However, if each project has a different schema, the current structure does not support this use case effectively.
Thank you!
If you use multi tenancy, even on that scenario, you can load and offload your tenants, potentially saving on memory usage.
Of course, number of tenants and dataset size needs to be taken in consideration too.
Also, it will isolate a tenant data, even keep all data from the same tenant as “together” as possible.
Indeed, that feature is most helpful as you described.
Thanks!