Python client for Qdrant vector database. Supports local and cloud modes, FastEmbed integration, async operations, and both REST and gRPC protocols.
A comprehensive Python client for the Qdrant vector search engine. This skill helps you integrate Qdrant into your applications for semantic search, similarity matching, and vector operations with support for local development, cloud deployment, and embedded inference.
This skill enables you to:
Install the base client:
```bash
pip install qdrant-client
```
For local embedding generation with FastEmbed (CPU):
```bash
pip install qdrant-client[fastembed]
```
For GPU-accelerated embeddings:
```bash
pip install qdrant-client[fastembed-gpu]
```
**Local mode (in-memory, perfect for development/testing):**
```python
from qdrant_client import QdrantClient
client = QdrantClient(":memory:")
client = QdrantClient(path="path/to/db")
```
**Connect to Qdrant server:**
```python
client = QdrantClient(host="localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
```
**Connect to Qdrant Cloud:**
```python
client = QdrantClient(
url="https://your-cluster.cloud.qdrant.io:6333",
api_key="<your-api-key>",
)
```
**Enable gRPC for faster uploads:**
```python
client = QdrantClient(host="localhost", grpc_port=6334, prefer_grpc=True)
```
Define your vector space with size and distance metric:
```python
from qdrant_client.models import Distance, VectorParams
client.create_collection(
collection_name="my_collection",
vectors_config=VectorParams(
size=100, # Dimension of your vectors
distance=Distance.COSINE # or Distance.EUCLID, Distance.DOT
),
)
```
Upload vectors with optional metadata payloads:
```python
import numpy as np
from qdrant_client.models import PointStruct
vectors = np.random.rand(100, 100) # 100 vectors of dimension 100
client.upsert(
collection_name="my_collection",
points=[
PointStruct(
id=idx,
vector=vector.tolist(),
payload={"color": "red", "category": idx % 10}
)
for idx, vector in enumerate(vectors)
]
)
```
Basic similarity search:
```python
query_vector = np.random.rand(100)
hits = client.query_points(
collection_name="my_collection",
query=query_vector,
limit=5 # Return top 5 matches
)
for hit in hits.points:
print(f"ID: {hit.id}, Score: {hit.score}, Payload: {hit.payload}")
```
Apply metadata filters to narrow results:
```python
from qdrant_client.models import Filter, FieldCondition, Range
hits = client.query_points(
collection_name="my_collection",
query=query_vector,
query_filter=Filter(
must=[
FieldCondition(
key='category',
range=Range(gte=3, lte=7) # category between 3 and 7
)
]
),
limit=5
)
```
Generate embeddings automatically without external APIs:
```python
from qdrant_client import QdrantClient, models
client = QdrantClient(":memory:")
model_name = "sentence-transformers/all-MiniLM-L6-v2"
client.create_collection(
"demo_collection",
vectors_config=models.VectorParams(
size=client.get_embedding_size(model_name),
distance=models.Distance.COSINE
)
)
payload = [
{"document": "Qdrant has Langchain integrations", "source": "Langchain-docs"},
{"document": "Qdrant also has Llama Index integrations", "source": "LlamaIndex-docs"},
]
docs = [models.Document(text=data["document"], model=model_name) for data in payload]
client.upload_collection(
collection_name="demo_collection",
vectors=docs,
ids=[1, 2],
payload=payload,
)
search_result = client.query_points(
collection_name="demo_collection",
query=models.Document(text="This is a query document", model=model_name)
).points
```
**Enable GPU acceleration:**
```python
docs = [
models.Document(
text="Your text here",
model=model_name,
options={"cuda": True}
)
]
```
For async applications (requires async runtime):
```python
import asyncio
from qdrant_client import AsyncQdrantClient, models
async def main():
client = AsyncQdrantClient(url="http://localhost:6333")
await client.create_collection(
collection_name="async_collection",
vectors_config=models.VectorParams(size=10, distance=models.Distance.COSINE),
)
await client.upsert(
collection_name="async_collection",
points=[
models.PointStruct(id=i, vector=np.random.rand(10).tolist())
for i in range(100)
],
)
res = await client.query_points(
collection_name="async_collection",
query=np.random.rand(10).tolist(),
limit=10,
)
print(res)
asyncio.run(main())
```
Use cloud-hosted models (paid plans only):
```python
client = QdrantClient(
url="https://your-cluster.cloud.qdrant.io:6333",
api_key="<your-api-key>",
cloud_inference=True, # Enable remote inference
)
```
1. **Development workflow**: Use local mode (`:memory:` or `path`) for prototyping, then switch to server/cloud for production
2. **Batch uploads**: Use `upload_collection()` or `upload_points()` for large datasets to avoid payload size limits
3. **gRPC for performance**: Enable gRPC with `prefer_grpc=True` for significantly faster bulk operations
4. **Distance metrics**: Choose `COSINE` for normalized vectors, `EUCLID` for absolute distances, `DOT` for pre-normalized vectors
5. **Filter efficiency**: Structure payloads with filterable fields to enable fast metadata-based searches
6. **Async for scale**: Use `AsyncQdrantClient` in async applications to handle concurrent requests efficiently
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/qdrant-vector-search-client/raw