Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions examples/serverless_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""
Example of using the Qdrant Serverless client.

**In development — do not use yet.** This client is experimental and unstable;
it may change without notice and is not ready for production or general use.

Collection management uses the simplified serverless API; point operations
(query, upsert, ...) work exactly like in the regular client.
"""

from qdrant_client.models import PointStruct
from qdrant_client.serverless.models import DenseVectorConfig, Distance, KeywordIndex
from qdrant_client.serverless import QdrantServerless


def main() -> None:
client = QdrantServerless(
url="https://serverless.plush-volt.aws.development-cloud.qdrant.io",
api_key="<your api key>",
)

# make the example rerunnable: creating an existing collection raises ALREADY_EXISTS
if client.collection_exists("my-collection"):
client.delete_collection("my-collection")

# serverless-specific collection management: no quantization, wal,
# segment number etc. - the serverless manager decides those
print(client.create_collection(
"my-collection",
dense_vectors=DenseVectorConfig(size=4, distance=Distance.COSINE),
payload_indexes={"color": KeywordIndex()},
))

print(client.get_collections())
print(client.get_collection("my-collection"))

# point operations, same as in the regular client
client.upsert(
"my-collection",
points=[
PointStruct(id=1, vector=[0.1, 0.2, 0.3, 0.4], payload={"color": "red"}),
PointStruct(id=2, vector=[0.4, 0.3, 0.2, 0.1], payload={"color": "blue"}),
],
)
print(client.query_points("my-collection", query=[0.1, 0.2, 0.3, 0.4]))

client.delete_collection("my-collection")
client.close()


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[mypy]
ignore_missing_imports = True
follow_imports = skip
exclude = qdrant_client/grpc|qdrant_client/http|tests|venv
exclude = qdrant_client/grpc|qdrant_client/serverless/grpc|qdrant_client/http|tests|venv|examples
28 changes: 28 additions & 0 deletions qdrant_client/serverless/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Client for Qdrant Serverless.

**In development — do not use yet.** This API is experimental and unstable;
it may change without notice and is not ready for production or general use.

Point-level operations (query, upsert, ...) behave like the regular client;
collection management uses the simplified, tenant-facing serverless API.

Usage:

from qdrant_client.serverless import QdrantServerless
from qdrant_client.serverless.models import DenseVectorConfig, Distance

client = QdrantServerless(url="https://...", api_key="...")
client.create_collection(
"my-collection",
dense_vectors=DenseVectorConfig(size=1536, distance=Distance.COSINE),
)
client.query_points("my-collection", query=[0.1, 0.2, ...])
"""

from qdrant_client.serverless.async_client import AsyncQdrantServerless
from qdrant_client.serverless.client import QdrantServerless

__all__ = [
"AsyncQdrantServerless",
"QdrantServerless",
]
Loading