tenants
table on the left-hand side.
From there, click on “Home” (top icon on the left menu), click on “generate credentials” and copy the resulting connection string. You will need it in a sec.
./data
directory.
nile_llamaindex_quickstart.py
and start by importing the necessary dependencies (or follow along with the script mentioned above):
tenant_aware=True
. This is because we want to isolate the documents for each tenant in our vector store.
🔥 NileVectorStore supports both tenant-aware vector stores, that isolates the documents for each tenant and a regular store which is typically used for shared data that all tenants can access.
Below, we’ll demonstrate the tenant-aware vector store.
SimpleDirectoryReader
to load the documents. Because we want to update the documents with the tenant
metadata after loading, we’ll use a separate reader for each tenant.
VectorStoreIndex
. Since we created a tenant-aware NileVectorStore
when we set things up,
Nile will correctly use the tenant_id
field in the metadata to isolate them. Loading documents without tenant_id
to a tenant-aware store will throw a ValueException
.
AIUtils
class, which is responsible for interfacing with the Nile vector store and the OpenAI API.
POST /api/todos
endpoint, we use the AIUtils
instance to generate a time estimate for the todo item, and to store the embedding in the Nile vector store.
AIUtils
class, you’ll see that it is very similar to the simple quickstart example earlier. Except we use Ollama instead of OpenAI.
We initialize the vector store and the index in the __init__
method:
POST /api/todos
handler, you’ll see that we get all the todos for a tenant without needing to do any filtering.
This is because the get_tenant_session
function returns a session for the tenant database:
get_tenant_session
is implemented in db.py
and it is a wrapper around the get_session
function that sets the nile.tenant_id
and nile.use_id
context.
tenant_middleware.py
.