Create a Qdrant vector database in Delhi or Chennai, connect to it from Python, and run your first similarity search. To connect, you need Python 3.8 or later, which an instance in the project can run. A prepaid account also needs credit for the nodes.
Create the database
Section titled “Create the database”- In TIR, open your project. In the side menu, under Storage, select Vector Database.
- Select Create Database, or Launch Database for a project’s first database.
- Keep the Cluster Name TIR fills in, or type your own.
- In Default Collection, keep Cosine for Distance, and set Vector Dimension to the size of the vectors you will store. Keep Shard Number at 1 and Replication Factor at 3.
- Under Select Plan, keep E2E Cluster and choose a plan. Keep Node Count at 3.
- Select Launch.
The database appears in the list as Deploying and becomes Running after a few minutes. See Create a vector database for what each choice means.
Get the connection details
Section titled “Get the connection details”When the database is Running, select its row and open Overview. Copy the Endpoint URL, then show and copy the API Key.
Connect and run a search
Section titled “Connect and run a search”Install the Python client:
pip install qdrant-clientThe script connects, creates a second collection with the same settings as the default one (Cosine
distance, one shard, replication factor 3), and adds six points. It then searches for the three points nearest
to a query vector. Replace <your-endpoint-url> with the Endpoint URL you copied, leaving off the
https:// at the start, and <your-api-key> with the API Key.
from qdrant_client import QdrantClientfrom qdrant_client.http.models import Distance, VectorParams, PointStruct
client = QdrantClient(host="<your-endpoint-url>", port=6333, https=True, api_key="<your-api-key>")
client.create_collection( collection_name="my_first_collection", vectors_config=VectorParams(size=4, distance=Distance.COSINE), shard_number=1, replication_factor=3,)
points = [ PointStruct(id=1, vector=[0.05, 0.61, 0.76, 0.74], payload={"city": "Berlin"}), PointStruct(id=2, vector=[0.19, 0.81, 0.75, 0.11], payload={"city": "London"}), PointStruct(id=3, vector=[0.36, 0.55, 0.47, 0.94], payload={"city": "Moscow"}), PointStruct(id=4, vector=[0.18, 0.01, 0.85, 0.80], payload={"city": "New York"}), PointStruct(id=5, vector=[0.24, 0.18, 0.22, 0.44], payload={"city": "Beijing"}), PointStruct(id=6, vector=[0.35, 0.08, 0.11, 0.44], payload={"city": "Chennai"}),]client.upsert(collection_name="my_first_collection", points=points, wait=True)
results = client.search( collection_name="my_first_collection", query_vector=[0.2, 0.1, 0.9, 0.7], limit=3,)for point in results: print(f"ID: {point.id}, City: {point.payload['city']}, Score: {point.score}")The script prints three lines, one for each of the nearest points, with their scores. To use gRPC instead of REST, connect on port 6334 with the gRPC option turned on:
client = QdrantClient( host="<your-endpoint-url>", port=6334, https=True, api_key="<your-api-key>", prefer_grpc=True)What to do next
Section titled “What to do next”- Connect to a vector database covers the keys, the Qdrant dashboard and the sample commands in the portal.
- Take a snapshot before you scale or change a lot of data.
- Stop or start the database to pause its compute charge, and delete it to stop every charge.
- For the Qdrant documentation, see qdrant.tech.
For help with any message, see Troubleshooting Vector Database.
Was this page helpful?