Qdrant β Production Vector DatabaseΒΆ
High-Performance Search with Advanced FilteringΒΆ
Qdrant is a vector similarity search engine built in Rust for speed and reliability. It supports rich payload filtering (structured metadata queries combined with vector search), multiple distance metrics, and horizontal scaling via sharding and replication. Qdrant can run locally in embedded mode (ideal for development) or as a distributed cluster for production workloads. Its filtering capabilities β including range queries, keyword matches, and nested conditions β make it especially powerful for RAG pipelines where you need to restrict retrieval to specific document categories, time ranges, or user permissions.
InstallationΒΆ
The qdrant-client Python package provides both a REST/gRPC client for connecting to a remote Qdrant server and an embedded local mode that stores data on disk without needing a separate process. For learning and prototyping, the local-path mode (shown below) is the fastest way to get started.
# !pip install qdrant-client
from qdrant_client import QdrantClient
from qdrant_client.models import Distance, VectorParams, PointStruct
print('β
Imports successful')
1. Initialize QdrantΒΆ
Passing a path argument to QdrantClient creates a local on-disk instance β no Docker container or remote server required. All data (vectors, payloads, and HNSW indexes) is persisted to the specified directory. For production deployments, you would instead connect to a Qdrant server via QdrantClient(url="http://host:6333").
client = QdrantClient(path="./qdrant_db")
print("β
Client created")
2. Create CollectionΒΆ
A collection in Qdrant requires a VectorParams configuration that specifies the embedding dimensionality (size) and the distance metric (Distance.COSINE, Distance.EUCLID, or Distance.DOT). Qdrant builds an HNSW index on the vectors for fast approximate search. Unlike Chroma, Qdrant does not embed text for you β you must provide pre-computed embedding vectors, giving you full control over which model and preprocessing steps to use.
from qdrant_client.models import VectorParams, Distance
client.create_collection(
collection_name="documents",
vectors_config=VectorParams(size=384, distance=Distance.COSINE)
)
print("β
Collection created")
3. Add VectorsΒΆ
Documents are inserted as PointStruct objects, each containing a unique integer or UUID id, a vector (list of floats), and an optional payload dictionary for metadata. The upsert method inserts new points or updates existing ones with the same ID, making it safe to re-run. Payloads can store any JSON-serializable data and are indexed automatically for filtering during search.
import numpy as np
points = [
PointStruct(
id=1,
vector=np.random.random(384).tolist(),
payload={"text": "ML example"}
)
]
client.upsert(collection_name="documents", points=points)
print("β
Vectors added")
4. SearchΒΆ
The search method takes a query_vector, computes approximate nearest neighbors using the HNSW index, and returns the top limit results ranked by the collectionβs distance metric. Each result includes the pointβs id, score (similarity), and payload. You can optionally pass a query_filter parameter to restrict the search to points whose payload fields match specified conditions β for example, retrieving only documents from a particular category or date range.
query_vector = np.random.random(384).tolist()
results = client.search(
collection_name="documents",
query_vector=query_vector,
limit=3
)
for hit in results:
print(f"Score: {hit.score:.4f} - {hit.payload}")