DevTurtle logo DevTurtle

Qdrant – The vector database guide

In some of our previous articles we have already discussed what embeddings are, how they are used in machine learning applications and we have also seen how to generate them. Now it's time to see how to save and use them. In this post we will explore the features of Qdrant, one of the most popular vector databases.

What is Qdrant?

Qdrant is an open-source vector database designed for efficient management and searching of high-dimensional data. Unlike traditional relational databases, which store data in structured tables, Qdrant stores data as vectors, which are numerical representations of complex data such as text, images, or audio. This type of data structure is ideal for artificial intelligence (AI) applications that require finding similarities between high-dimensional data, such as similar image search, product recommendation, and text analysis.

How to install Qdrant on Docker

In this tutorial we will see how to install Qdrant using a Docker engine (in particular the free version of Rancher Desktop).

Once docker has been installed on your machine, to download the Qdrant image simply launch the command in the console:

docker pull qdrant/qdrant

Once the download is complete, to run the image you need to run the command:

docker run -p 6333:6333 qdrant/qdrant

Port 6333 is the one on which the web console is displayed while 6334 is necessary to allow any connections from the outside.

Use the Web-UI

After launching the Docker image, you can connect to the web dashboard which is exposed at the following URL:

http://localhost:6333/dashboard

By navigating through the left menu it will be possible to access the “Console” which allows you to execute commands by invoking the HTTP API. For example, it is possible to create a new collection by executing the following request:

PUT collections/cities
{
  "vectors": {
    "size": 4,
    "distance": "Dot"
  }
}

To execute the command, simply click on the “RUN” link that appears at the top above the instruction.

In doing so we defined:

  • the name of the collection which is indicated in the endpoint path (“test_collection”)
  • the size of the vectors that we are going to save (4)
  • the distance metric type (“Dot”).

The distance metric can take on different values (“Dot“, “Cosine“, “Euclid“, “Manhattan“) and indicates the algorithm that will be used to calculate the distance between two vectors.

Once the collection has been created, we can start inserting the first vectors. Example:

PUT collections/cities/points
{
  "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"}
    }
  ]
}
Qdrant console Web UI
Qdrant console Web UI

By navigating to the “Collections” tab we will find the collection we just created. By selecting it and then clicking on the “VISUALIZE” tab it will be possible to launch a query and graphically view the results.

For example, you can run a very simple query that only puts a limit on the number of vectors displayed:

{
  "limit": 500
}
Qdrant - visualize
Qdrant – visualize

This functionality can be very useful because it allows you to have a graphic and intuitive representation of the data collected.