Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed invalid await from grpc async call #785

Merged
merged 2 commits into from
Sep 24, 2024
Merged
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
15 changes: 8 additions & 7 deletions qdrant_client/async_qdrant_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -2765,16 +2765,17 @@ async def create_shard_key(
if self._prefer_grpc:
if isinstance(shard_key, get_args_subscribed(models.ShardKey)):
shard_key = RestToGrpc.convert_shard_key(shard_key)
request = await grpc.CreateShardKey(
shard_key=shard_key,
shards_number=shards_number,
replication_factor=replication_factor,
placement=placement or [],
)
return (
await self.grpc_collections.CreateShardKey(
grpc.CreateShardKeyRequest(
collection_name=collection_name, timeout=timeout, request=request
collection_name=collection_name,
timeout=timeout,
request=grpc.CreateShardKey(
shard_key=shard_key,
shards_number=shards_number,
replication_factor=replication_factor,
placement=placement or [],
),
),
timeout=self._timeout,
)
Expand Down
14 changes: 6 additions & 8 deletions qdrant_client/qdrant_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -3138,18 +3138,16 @@ def create_shard_key(
if isinstance(shard_key, get_args_subscribed(models.ShardKey)):
shard_key = RestToGrpc.convert_shard_key(shard_key)

request = grpc.CreateShardKey(
shard_key=shard_key,
shards_number=shards_number,
replication_factor=replication_factor,
placement=placement or [],
)

return self.grpc_collections.CreateShardKey(
grpc.CreateShardKeyRequest(
collection_name=collection_name,
timeout=timeout,
request=request,
request=grpc.CreateShardKey(
shard_key=shard_key,
shards_number=shards_number,
replication_factor=replication_factor,
placement=placement or [],
),
),
timeout=self._timeout,
).result
Expand Down
22 changes: 22 additions & 0 deletions tests/test_async_qdrant_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,3 +609,25 @@ def auth_token_provider():

await client.unlock_storage()
assert sync_token == "token_2"


@pytest.mark.asyncio
@pytest.mark.parametrize("prefer_grpc", [False, True])
async def test_custom_sharding(prefer_grpc):
client = AsyncQdrantClient(prefer_grpc=prefer_grpc)

if await client.collection_exists(COLLECTION_NAME):
await client.delete_collection(collection_name=COLLECTION_NAME)
await client.create_collection(
collection_name=COLLECTION_NAME,
vectors_config=models.VectorParams(size=DIM, distance=models.Distance.DOT),
sharding_method=models.ShardingMethod.CUSTOM,
)

await client.create_shard_key(collection_name=COLLECTION_NAME, shard_key="cats")
await client.create_shard_key(collection_name=COLLECTION_NAME, shard_key="dogs")

collection_info = await client.get_collection(COLLECTION_NAME)

assert collection_info.config.params.shard_number == 1
# assert collection_info.config.params.sharding_method == models.ShardingMethod.CUSTOM # todo: fix in grpc
Loading