Multi Tenancy Example
🗂️ Multi-Tenancy in Weaviate
Welcome to this demo notebook! Here, we'll walk you through a small example showcasing the Multi-Tenancy function in Weaviate.
Multi-tenancy is a key feature in Weaviate, allowing for the efficient and secure management of data across multiple users or tenants.
📖 Further Reading:
- Explore the concept in depth in the multi-tenancy blog post.
- Dive into the technical details in our Weaviate developer documentation.
Getting started
Before we dive in, there are a few preliminary steps:
-
Set Up a Weaviate Cluster: This notebook requires a working Weaviate cluster. If you don't have one, fret not! You can set up a free sandbox Weaviate cluster by following our comprehensive guide.
-
Virtual Environment and Dependencies: To ensure smooth execution and prevent potential conflicts with your global Python environment, we recommend running the code in a virtual environment. Later in this notebook, we'll guide you through setting up this environment and installing the necessary dependencies.
With these points in mind, let's get started!
Dependencies
Before proceeding with the notebook content, it's essential to set up an isolated Python environment. This helps avoid any potential package conflicts and ensures that you have a clean workspace.
Virtual Environment Setup:
If you haven't created a virtual environment before, here's how you can do it:
Using virtualenv:
pip install virtualenv
python -m virtualenv venv
Using venv (built-in with Python 3.3+):
python -m venv venv
After creating the virtual environment, you need to activate it:
Windows:
.\venv\Scripts\activate
macOS and Linux:
source venv/bin/activate
Installing Dependencies:
With the virtual environment active, run the following code to install all the required dependencies for this notebook:
Connecting to Your Weaviate Cluster
To interact with our Weaviate cluster, we'll initialize a client object. Once set up, we'll retrieve the current schemas as a way to verify the connection. Since the cluster is newly created, we expect that no schemas will be present.
Setting Up Multi-Tenancy in a Weaviate Collection
In Weaviate, multi-tenancy allows for multiple tenants to securely access and manage data within the same schema. Let's proceed to define a new collection that utilizes this feature:
Define a Multi-Tenancy Enabled Collection:
We'll start by creating a collection named 'MultiTenancyCollection' with the multi-tenancy feature activated.
Add Multiple Tenants to the Class:
After establishing the collection, we'll associate it with two tenants: 'tenantA' and 'tenantB'
Fetching Tenants from a Weaviate Collection
To view the tenants associated with a specific collection, we can retrieve a list of all the tenants linked to it. Let's do this for our previously created collection, 'MultiTenancyCollection':
Assigning Data Objects to Specific Tenants
In Weaviate, data objects can be associated with specific tenants in a multi-tenancy enabled collection. Here, we will demonstrate how to create data objects and link them to their respective tenants:
Performing Tenant-Specific Queries
By leveraging the multi-tenancy functionality, we can conduct queries that are specific to individual tenants. This enables us to fetch data solely associated with a designated tenant.
Removing Tenants from a Weaviate Collection
In situations where specific tenants are no longer required, Weaviate allows us to remove them from a collection. This action will only affect the specified tenants, leaving other associated tenants unaffected.