How to beginner · 3 min read

How to create a Qdrant collection

Quick answer
Use the qdrant-client Python SDK to create a Qdrant collection by initializing a QdrantClient and calling create_collection() with your collection name and vector size. This sets up the collection schema for storing and searching vectors efficiently.

PREREQUISITES

  • Python 3.8+
  • pip install qdrant-client
  • Access to a running Qdrant instance (local or cloud)

Setup

Install the official qdrant-client Python package and ensure you have access to a Qdrant server, either locally or hosted. Set the connection parameters accordingly.

bash
pip install qdrant-client

Step by step

This example shows how to create a Qdrant collection named my_collection with 128-dimensional vectors and default distance metric Cosine.

python
from qdrant_client import QdrantClient
from qdrant_client.http.models import Distance

# Connect to local Qdrant instance
client = QdrantClient(host="localhost", port=6333)

# Create collection with vector size and distance metric
client.recreate_collection(
    collection_name="my_collection",
    vector_size=128,
    distance=Distance.COSINE
)

print("Collection 'my_collection' created successfully.")
output
Collection 'my_collection' created successfully.

Common variations

  • Use Distance.EUCLID or Distance.DOT for different similarity metrics.
  • Connect to a remote Qdrant server by specifying api_key and https parameters.
  • Use create_collection() instead of recreate_collection() to avoid overwriting existing collections.
python
from qdrant_client import QdrantClient
from qdrant_client.http.models import Distance

# Connect to remote Qdrant with API key
client = QdrantClient(
    url="https://your-qdrant-host",
    api_key=os.environ["QDRANT_API_KEY"]
)

# Create collection with Euclidean distance
client.create_collection(
    collection_name="euclid_collection",
    vector_size=256,
    distance=Distance.EUCLID
)

print("Collection 'euclid_collection' created.")
output
Collection 'euclid_collection' created.

Troubleshooting

  • If you get a connection error, verify Qdrant server is running and accessible at the specified host and port.
  • Use recreate_collection() carefully as it deletes existing data in the collection.
  • Check vector size matches your embeddings dimension to avoid errors on insert.

Key Takeaways

  • Use the official qdrant-client Python SDK to manage collections programmatically.
  • Specify vector size and distance metric when creating collections to optimize similarity search.
  • Use recreate_collection() to reset collections but beware it deletes existing data.
  • Ensure your Qdrant server is running and accessible before creating collections.
  • Adjust connection parameters for local or remote Qdrant instances including API keys.
Verified 2026-04
Verify ↗