Python Client library for the Qdrant vector search engine.
Python Qdrant Client
Client library and SDK for the Qdrant vector search engine.
Library contains type definitions for all Qdrant API and allows to make both Sync and Async requests.
Client allows calls for all Qdrant API methods directly.
It also provides some additional helper methods for frequently required operations, e.g. initial collection uploading.
You can register and use Qdrant Cloud to get a free tier account with 1GB RAM.
Once you have your cluster and API key, you can connect to it like this:
from qdrant_client import QdrantClient
qdrant_client = QdrantClient(
url="https://xxxxxx-xxxxx-xxxxx-xxxx-xxxxxxxxx.us-east.aws.cloud.qdrant.io:6333",
api_key="<your-api-key>",
)
Inference API
Qdrant Client has Inference API that allows to seamlessly create embeddings and use them in Qdrant.
Inference API can be used locally with FastEmbed or remotely with models available in Qdrant Cloud.
Local Inference with FastEmbed
pip install qdrant-client[fastembed]
FastEmbed is a library for creating fast vector embeddings on CPU. It is based on ONNX Runtime and allows to run inference both on CPU and GPU.
Qdrant Client can use FastEmbed to create embeddings and upload them to Qdrant. This allows to simplify API and make it more intuitive.
from qdrant_client import QdrantClient, models
# running qdrant in local mode suitable for experiments
client = QdrantClient(":memory:") # or QdrantClient(path="path/to/db") for local mode and persistent storage
model_name = "sentence-transformers/all-MiniLM-L6-v2"
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]
ids = [42, 2]
client.create_collection(
"demo_collection",
vectors_config=models.VectorParams(
size=client.get_embedding_size(model_name), distance=models.Distance.COSINE)
)
client.upload_collection(
collection_name="demo_collection",
vectors=docs,
ids=ids,
payload=payload,
)
search_result = client.query_points(
collection_name="demo_collection",
query=models.Document(text="This is a query document", model=model_name)
).points
print(search_result)
FastEmbed can also utilise GPU for faster embeddings. To enable GPU support, install
pip install 'qdrant-client[fastembed-gpu]'
In order to set GPU, extend documents from the previous example with options.
models.Document(text="To be computed on GPU", model=model_name, options={"cuda": True})
Note: fastembed-gpu and fastembed are mutually exclusive. You can only install one of them.
If you previously installed fastembed, you might need to start from a fresh environment to install fastembed-gpu.
Remote inference with Qdrant Cloud
Qdrant Cloud provides a set of predefined models that can be used for inference without a need to install any additional libraries or host models locally. (Currently available only on paid plans.)
Inference API is the same as in the local mode, but the client has to be instantiated with cloud_inference=True:
Note: remote inference requires images to be provided as base64 encoded strings or urls
Examples
Create a new collection
from qdrant_client.models import Distance, VectorParams
client.create_collection(
collection_name="my_collection",
vectors_config=VectorParams(size=100, distance=Distance.COSINE),
)
Insert vectors into a collection
import numpy as np
from qdrant_client.models import PointStruct
vectors = np.random.rand(100, 100)
# NOTE: consider splitting the data into chunks to avoid hitting the server's payload size limit# or use `upload_collection` or `upload_points` methods which handle this for you# WARNING: uploading points one-by-one is not recommended due to requests overhead
client.upsert(
collection_name="my_collection",
points=[
PointStruct(
id=idx,
vector=vector.tolist(),
payload={"color": "red", "rand_number": idx % 10}
)
for idx, vector inenumerate(vectors)
]
)
Search for similar vectors with filtering condition
from qdrant_client.models import Filter, FieldCondition, Range
hits = client.query_points(
collection_name="my_collection",
query=query_vector,
query_filter=Filter(
must=[ # These conditions are required for search results
FieldCondition(
key='rand_number', # Condition based on values of `rand_number` field.range=Range(
gte=3# Select only those results where `rand_number` >= 3
)
)
]
),
limit=5# Return 5 closest points
)
Client library for the Qdrant vector search engine
We found that qdrant-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.