Table of Contents
Introduction #
In this tutorial, you’ll learn how to delete entire collections from Qdrant Vector DB. This is a crucial operation when you need to clear out data, especially during development or testing.
1. Initialize the Qdrant Client #
Before performing a deletion, we need to establish a connection with the Qdrant server. Our script will determine if a local Qdrant server is running. If not, it will connect to the Qdrant server in the cloud using stored API key and URL values.
# Check if local server is running
if check_local_server_running():
client = QdrantClient(url="http://localhost:6333")
print("Connected to local Qdrant server.")
else:
url = open_file('./qdrant_url.txt')
api_key = open_file('./qdrant_api_key.txt')
client = QdrantClient(url=url, api_key=api_key)
print("Connected to cloud Qdrant server.")
2. Delete Collection #
Once we’ve established a connection, we can instruct Qdrant to delete an entire collection. Be cautious when performing this action as it’s irreversible, and all data in the collection will be lost.
collection_name_to_delete = "<<ENTER COLLECTION NAME>>" # replace with your collection's name
client.delete_collection(collection_name=collection_name_to_delete)