The Inference API allows you to create embeddings seamlessly. For local inference on CPU, install the fastembed extra:
pip install qdrant-client[fastembed]
To enable GPU support (mutually exclusive with fastembed):
pip install 'qdrant-client[fastembed-gpu]'
Usage Example:
Use models.Document to wrap text and a model name. The client handles embedding generation and uploading.
from qdrant_client import QdrantClient, models
client = QdrantClient(":memory:")
model_name = "sentence-transformers/all-MiniLM-L6-v2"
# Prepare documents
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]
# Create collection with correct vector size
client.create_collection(
"demo_collection",
vectors_config=models.VectorParams(size=client.get_embedding_size(model_name), distance=models.Distance.COSINE)
)
# Upload documents (embeddings are generated locally)
client.upload_collection(
collection_name="demo_collection",
vectors=docs,
ids=ids,
payload=payload,
)
# Query using a document
search_result = client.query_points(
collection_name="demo_collection",
query=models.Document(text="This is a query document", model=model_name)
).points
from qdrant_client import QdrantClient, models
client = QdrantClient(":memory:")
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)