update async readme

This commit is contained in:
generall
2023-10-16 18:55:55 +02:00
parent 834e40c940
commit 30788edbd5
2 changed files with 34 additions and 9 deletions

View File

@@ -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

View File

@@ -1 +1,2 @@
from .async_qdrant_client import AsyncQdrantClient as AsyncQdrantClient
from .qdrant_client import QdrantClient as QdrantClient