From 30788edbd566191af63153be1c38944241c5b68c Mon Sep 17 00:00:00 2001 From: generall Date: Mon, 16 Oct 2023 18:55:55 +0200 Subject: [PATCH] update async readme --- README.md | 42 ++++++++++++++++++++++++++++++--------- qdrant_client/__init__.py | 1 + 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index af7dc98c..2793aa53 100644 --- a/README.md +++ b/README.md @@ -223,23 +223,47 @@ client = QdrantClient(host="localhost", grpc_port=6334, prefer_grpc=True) ## Async client -Async methods are available in raw autogenerated clients. -Usually, you don't need to use them directly, but if you need extra performance, you can access them directly. +Starting from version 1.6.1, all python client methods are available in async version. -### Async gRPC - -Example of using raw async gRPC client: +To use it, just import `AsyncQdrantClient` instead of `QdrantClient`: ```python -from qdrant_client import QdrantClient, grpc +from qdrant_client import AsyncQdrantClient, models +import numpy as np +import asyncio -client = QdrantClient(prefer_grpc=True, timeout=3.0) +async def main(): + # Your async code using QdrantClient might be put here + client = AsyncQdrantClient(url="http://localhost:6333") -grpc_collections = client.async_grpc_collections + await client.create_collection( + collection_name="my_collection", + vectors_config=models.VectorParams(size=10, distance=models.Distance.COSINE), + ) -res = await grpc_collections.List(grpc.ListCollectionsRequest(), timeout=1.0) + await client.upsert( + collection_name="my_collection", + points=[ + models.PointStruct( + id=i, + vector=np.random.rand(10).tolist(), + ) + for i in range(100) + ], + ) + + res = await client.search( + collection_name="my_collection", + query_vector=np.random.rand(10).tolist(), # type: ignore + limit=10, + ) + + print(res) + +asyncio.run(main()) ``` +Both, gRPC and REST API are supported in async mode. More examples can be found [here](./tests/test_async_qdrant_client.py). ### Development diff --git a/qdrant_client/__init__.py b/qdrant_client/__init__.py index 062b40d7..5aaa4c3d 100644 --- a/qdrant_client/__init__.py +++ b/qdrant_client/__init__.py @@ -1 +1,2 @@ +from .async_qdrant_client import AsyncQdrantClient as AsyncQdrantClient from .qdrant_client import QdrantClient as QdrantClient