# Import necessary libraries
import os
import numpy as np
import tiledb.vector_search as vs
import tiledb
import tiledb.cloud
# You should set the appropriate environment variables with
# your TileDB Cloud token and username.
= os.environ["TILEDB_REST_TOKEN"]
token = os.environ["TILEDB_REST_USERNAME"]
username
# Get the bucket from an environment variable
= os.environ["S3_BUCKET"]
s3_bucket
# Login to TileDB Cloud
=token)
tiledb.cloud.login(token
# Set index URI
= "running_locally"
index_name = "tiledb://" + username + "/" + index_name
index_uri = "tiledb://" + username + "/" + s3_bucket + "/" + index_name
index_reg_uri
# The TileDB Cloud context
= tiledb.cloud.Ctx()
ctx
# Clean up index if it already exists
if tiledb.object_type(index_uri, ctx=ctx) == "group":
=True) tiledb.cloud.asset.delete(index_uri, recursive
Running Locally
This tutorial shows how you can install TileDB-Vector-Search and the TileDB Cloud Python client so that you can use the software from your local machine.
Installation
To install the TileDB-Vector-Search and TileDB Cloud Python client, run the following in bash:
# Install the TileDB Cloud Python client
pip install tiledb-cloud
# Install the TileDB-Vector-Search library
# - Using Pip
pip install tiledb-vector-search
# - Or, using conda
conda install -c conda-forge -c tiledb tiledb-vector-search
Local storage
To create and query vector indexes in local storage, read the Quickstart or Tutorials: Ingestion and Querying tutorials.
Storage on S3
To create and query vector indexes on S3, read the Tutorials: Basic S3 example tutorial.
Storage on TileDB Cloud
Take note of the following when interacting with TileDB Cloud outside of the notebook environments of the TileDB Cloud service:
- You need to create a REST API token from the TileDB Cloud console.
- You need to set the REST API token in an environment variable and login using the token value.
- When creating a new index, you need to use a URI in the form
tiledb://<your_username>/<S3_path>/<index_name>
, whereS3_path
is the location on S3 where you wish to physically store the index. - When referring to the index after creating it (for example, when submitting queries), use a URI in the form
tiledb://<your_username>/<index_name>
(that is, no need to specify the S3 physical path anymore).
Start by importing the necessary libraries, loading the appropriate token and username, logging in, setting up the URIs and cleaning up any previously created index with the same name.
Create the index, using the URI that incorporates the S3 physical path as explained above:
Ingest some vectors.
Submit a query.
Clean up.