# Import necessary libraries
import os
import shutil
import numpy as np
import tiledb.vector_search as vs
# Set the index URI for this tutorial
= os.path.expanduser("~/deletes")
index_uri
# Clean up previous data
if os.path.exists(index_uri):
shutil.rmtree(index_uri)
Deletions
We recommend running this tutorial, as well as the other various tutorials in the Tutorials section, inside TileDB Cloud. This will allow you to quickly experiment avoiding all the installation, deployment, and configuration hassles. Sign up for the free tier, spin up a TileDB Cloud notebook with a Python kernel, and follow the tutorial instructions. If you wish to learn how to run tutorials locally on your machine, read the Tutorials: Running Locally tutorial.
This tutorial shows you how to delete from a vector index, either by deleting vectors one by one, or deleting multiple vectors in a batch.
For more background theory on how TileDB-Vector-Search implements deletions, read the Key Concepts: Updates section.
Setup
First, import the appropriate libraries, set the index URI, and delete any previously created data.
Next, create an empty IVF_FLAT
index.
Query the index and note that TileDB-Vector-Search returns no results, as you haven’t inserted any vectors yet.
Now, add a set of vectors to the index:
Query the index again, and observe the three nearest neighbors (2, 3, and 1) to the original query vector:
Delete single vectors
You can delete vectors as follows:
Query the index again and observe that the three nearest neighbors are now 3, 4, and 0.
Batch deletes
You can delete vectors in bulk using the .delete_batch()
method. Delete the remaining three vectors from the index.
Query the index again and observe that the result is empty again, as there are no vectors in the index.
Clean up
Clean up in the end by removing the index:
What’s next?
You can learn how to perform updates in your vector index. If you are searching for more advanced tutorials, you should learn about: