HTTP Requests

Qdrant provides a plethora of HTTP request calls to interact with the database. Here we have listed a few to get you started:

Note

You can run these HTTP requests directly from the Qdrant Dashboard console or use any HTTP client like cURL and Postman. All these requests need to be made to your Qdrant database endpoint.

Note

For all the following HTTP requests, you will either get a 200 for a successful operation or you will get some error code with the error stated in the response.

Pre-requisites

You need the URL and API-Key to connect to the Qdrant database.

To get the URL and the API-Key:

  1. Go to TIR and head to the Vector Database section.

  2. There you will find all your Vector Databases.

  3. Click on the Qdrant Database you want to connect to.

  4. You will find your database’s Endpoint URL and the API-Key in the Overview Tab.

Creating a Collection

  • We will create a collection called test_collection.

  • We are going to set the vector size to 4. This means that each vector will have 4 dimensions.

  • We are going to set the distance metric to DOT. The distance between vectors will be calculated using the dot product.

  • We are going to set the shard_number to 6. This means that your data will be sharded into 6 individual shards.

  • We are also going to set the replication_factor to 2. This means 2 shard-replicas will be stored, i.e., 1 additional copy of each of your data will be maintained automatically.

For a more detailed explanation of sharding and replication factors, you can refer to the Basic Terminology section.

curl -X PUT \
-H "api-key: <your-api-key>" \
-H "Content-Type: application/json" \
-d '{
      "vectors": {
          "size": 4,
          "distance": "Dot"
      },
      "shard_number": 6,
      "replication_factor": 2
  }' \
https://<your-endpoint-url>:6333/collections/test_collection

Listing Collections

Now, let us look at all the collections that we have created.

curl -X GET \
-H "api-key: <your-api-key>" \
https://<your-endpoint-url>:6333/collections

Since we’ve only created one collection, it’s the only one visible. If you create additional collections, you’ll see them as well.

Getting detailed info on a Collection

Now that we have confirmed that the collection was created let’s get the detailed information of the collection.

curl -X GET \
-H "api-key: <your-api-key>" \
https://<your-endpoint-url>:6333/collections/test_collection

As a summary, it shows your collection configuration, number of vectors, and more. Feel free to explore it.

Adding Vectors

Now that we have created a collection let’s add some vectors into it.

curl -X PUT \
-H "api-key: <your-api-key>" \
-H "Content-Type: application/json" \
-d '{
  "points": [
    {"id": 1, "vector": [0.05, 0.61, 0.76, 0.74], "payload": {"city": "Berlin"}},
    {"id": 2, "vector": [0.19, 0.81, 0.75, 0.11], "payload": {"city": "London"}},
    {"id": 3, "vector": [0.36, 0.55, 0.47, 0.94], "payload": {"city": "Moscow"}},
    {"id": 4, "vector": [0.18, 0.01, 0.85, 0.80], "payload": {"city": "New York"}},
    {"id": 5, "vector": [0.24, 0.18, 0.22, 0.44], "payload": {"city": "Beijing"}},
    {"id": 6, "vector": [0.35, 0.08, 0.11, 0.44], "payload": {"city": "Mumbai"}}
  ]
}' \
https://<your-endpoint-url>:6333/collections/test_collection/points

Call the GET collection API to see the changes in the collection.

Searching for Vectors

In production scenarios, you will have a model that generates vectors of your data. You use these vectors to perform similarity search operations in your collection.

Note

TIR provides a service where you can convert your text data into vectors. You can check it out in the GenAI API section on TIR.

Now, let’s perform a vector similarity search.

curl -X POST \
-H "api-key: <your-api-key>" \
-H "Content-Type: application/json" \
-d '{
  "vector": [
    0.2, 0.1, 0.9, 0.7
  ],
  "limit": 1
}' \
https://<your-endpoint-url>:6333/collections/test_collection/points/search

Deleting the collection

Now that we have played around with the collection, it’s time to delete it.

curl -X DELETE \
-H "api-key: <your-api-key>" \
https://<your-endpoint-url>:6333/collections/test_collection

What’s Next?

This was a quick start guide to get you started with the Qdrant HTTP client.