Skip to content

Connect to a vector database

View as Markdown

Find the endpoint and API keys on the database’s Overview tab, then connect from the Qdrant dashboard, the Python client, or HTTP.

You need a database in the Running state and a role with Read permission on Vector Database. For the Python client, you also need Python 3.8 or later. An instance in the project can run it.

  1. In Manage Vector Database, select the database’s row, then open Overview.
  2. Copy the Endpoint URL. This is the hostname of your database.
  3. Show API Key or Read-only API Key and copy it.

The API Key gives full read and write access. The Read-only API Key gives read-only access, so give it to client applications that only query data. Store both keys somewhere safe, such as environment variables, and keep them out of version control and client-side code.

Clients reach the database on port 6333 for REST, and on port 6334 for gRPC. Send the API key with each request.

In the list, select the database’s name, or select Connect in its row. Both open the Qdrant dashboard once the database is Running. Enter your API Key and select Apply.

The dashboard has these sections:

  • Collections: create, view and delete collections, browse points, see collection details and visualize vectors.
  • Console: run Qdrant API commands, and browse the commands available.
  • Tutorial: Qdrant’s interactive guide to its API.
  • Datasets: sample data to experiment with.

Use Console to try an API call before you add it to your application.

In the list, select Commands in the database’s row. The Python samples install the client, connect, create and list collections, add vectors, search, and close the connection. Your endpoint is filled in; type your API key where the sample asks.

pip install qdrant-client

<your-endpoint-url> is the Endpoint URL and <your-api-key> is your API key.

from qdrant_client import QdrantClient
from qdrant_client.http.models import Distance, VectorParams
client = QdrantClient(host="<your-endpoint-url>", port=6333, https=True, api_key="<your-api-key>")
client.create_collection(
collection_name="my_collection",
vectors_config=VectorParams(size=4, distance=Distance.COSINE),
shard_number=1,
replication_factor=3,
)

To connect over gRPC, use port 6334 and turn the gRPC option on:

client = QdrantClient(
host="<your-endpoint-url>", port=6334, https=True, api_key="<your-api-key>", prefer_grpc=True
)

Create the same collection with cURL:

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

Add points and search them as in Get started with Vector Database. To feed the database from LangChain or LlamaIndex, see Use Qdrant with LangChain and Use Qdrant with LlamaIndex. If a connection fails, see Troubleshooting Vector Database.