Skip to content

Commit bc85c04

Browse files
new: Propagate timeout to grpc default options
new: Added missing timeouts
1 parent f8cd2d1 commit bc85c04

File tree

4 files changed

+31
-30
lines changed

4 files changed

+31
-30
lines changed

qdrant_client/async_qdrant_remote.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ def __init__(
134134
self._rest_args["limits"] = limits
135135
if self._timeout is not None:
136136
self._rest_args["timeout"] = self._timeout
137+
if self._grpc_options:
138+
self._grpc_options["timeout"] = self._timeout
139+
else:
140+
self._grpc_options = {"timeout": self._timeout}
137141
if self._auth_token_provider is not None:
138142
if self._scheme == "http":
139143
warnings.warn("Auth token provider is used with an insecure connection.")
@@ -393,7 +397,7 @@ async def search(
393397
sparse_indices=sparse_indices,
394398
shard_key_selector=shard_key_selector,
395399
),
396-
timeout=timeout if timeout is None else self._timeout,
400+
timeout=timeout if timeout is not None else self._timeout,
397401
)
398402
return [GrpcToRest.convert_scored_point(hit) for hit in res.result]
399403
else:
@@ -436,8 +440,6 @@ async def query_points(
436440
types.Query,
437441
types.NumpyArray,
438442
types.Document,
439-
types.Image,
440-
types.InferenceObject,
441443
None,
442444
] = None,
443445
using: Optional[str] = None,
@@ -497,7 +499,7 @@ async def query_points(
497499
shard_key_selector=shard_key_selector,
498500
read_consistency=consistency,
499501
),
500-
timeout=timeout if timeout is None else self._timeout,
502+
timeout=timeout if timeout is not None else self._timeout,
501503
)
502504
scored_points = [GrpcToRest.convert_scored_point(hit) for hit in res.result]
503505
return models.QueryResponse(points=scored_points)
@@ -605,8 +607,6 @@ async def query_points_groups(
605607
types.Query,
606608
types.NumpyArray,
607609
types.Document,
608-
types.Image,
609-
types.InferenceObject,
610610
None,
611611
] = None,
612612
using: Optional[str] = None,
@@ -674,7 +674,7 @@ async def query_points_groups(
674674
shard_key_selector=shard_key_selector,
675675
read_consistency=consistency,
676676
),
677-
timeout=timeout if timeout is None else self._timeout,
677+
timeout=timeout if timeout is not None else self._timeout,
678678
)
679679
).result
680680
return GrpcToRest.convert_groups_result(result)
@@ -1429,7 +1429,7 @@ async def scroll(
14291429
shard_key_selector=shard_key_selector,
14301430
timeout=timeout,
14311431
),
1432-
timeout=timeout if timeout is None else self._timeout,
1432+
timeout=timeout if timeout is not None else self._timeout,
14331433
)
14341434
return (
14351435
[GrpcToRest.convert_retrieved_point(point) for point in res.result],
@@ -1488,7 +1488,7 @@ async def count(
14881488
shard_key_selector=shard_key_selector,
14891489
timeout=timeout,
14901490
),
1491-
timeout=timeout if timeout is None else self._timeout,
1491+
timeout=timeout if timeout is not None else self._timeout,
14921492
)
14931493
).result
14941494
return GrpcToRest.convert_count_result(response)
@@ -1755,7 +1755,7 @@ async def retrieve(
17551755
shard_key_selector=shard_key_selector,
17561756
timeout=timeout,
17571757
),
1758-
timeout=timeout if timeout is None else self._timeout,
1758+
timeout=timeout if timeout is not None else self._timeout,
17591759
)
17601760
).result
17611761
assert result is not None, "Retrieve returned None result"
@@ -2188,7 +2188,7 @@ async def update_collection_aliases(
21882188
return (
21892189
await self.grpc_collections.UpdateAliases(
21902190
grpc.ChangeAliases(timeout=timeout, actions=change_aliases_operation),
2191-
timeout=self._timeout,
2191+
timeout=timeout if timeout is not None else self._timeout,
21922192
)
21932193
).result
21942194
change_aliases_operation = [
@@ -2336,7 +2336,7 @@ async def update_collection(
23362336
quantization_config=quantization_config,
23372337
sparse_vectors_config=sparse_vectors_config,
23382338
),
2339-
timeout=self._timeout,
2339+
timeout=timeout if timeout is not None else self._timeout,
23402340
)
23412341
).result
23422342
if isinstance(optimizers_config, grpc.OptimizersConfigDiff):
@@ -2372,7 +2372,8 @@ async def delete_collection(
23722372
if self._prefer_grpc:
23732373
return (
23742374
await self.grpc_collections.Delete(
2375-
grpc.DeleteCollection(collection_name=collection_name), timeout=self._timeout
2375+
grpc.DeleteCollection(collection_name=collection_name),
2376+
timeout=timeout if timeout is not None else self._timeout,
23762377
)
23772378
).result
23782379
result: Optional[bool] = (
@@ -2543,6 +2544,7 @@ def _upload_collection(
25432544
"metadata": self._grpc_headers,
25442545
"wait": wait,
25452546
"shard_key_selector": shard_key_selector,
2547+
"options": self._grpc_options,
25462548
}
25472549
else:
25482550
updater_kwargs = {
@@ -2948,7 +2950,7 @@ async def create_shard_key(
29482950
placement=placement or [],
29492951
),
29502952
),
2951-
timeout=self._timeout,
2953+
timeout=timeout if timeout is not None else self._timeout,
29522954
)
29532955
).result
29542956
else:
@@ -2984,7 +2986,7 @@ async def delete_shard_key(
29842986
timeout=timeout,
29852987
request=grpc.DeleteShardKey(shard_key=shard_key),
29862988
),
2987-
timeout=self._timeout,
2989+
timeout=timeout if timeout is not None else self._timeout,
29882990
)
29892991
).result
29902992
else:

qdrant_client/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,18 +201,18 @@ async def intercept_call(
201201

202202

203203
def parse_channel_options(options: Optional[Dict[str, Any]] = None) -> List[Tuple[str, Any]]:
204+
timeout = f'{str(options.copy().pop("timeout", "10"))}s' if options else "10s"
204205
default_options: List[Tuple[str, Any]] = [
205206
("grpc.max_send_message_length", -1),
206207
("grpc.max_receive_message_length", -1),
207-
("grpc.enable_retries", 1),
208208
(
209209
"grpc.service_config",
210210
json.dumps(
211211
{
212212
"methodConfig": [
213213
{
214214
"name": [{}],
215-
"timeout": "10s", # TODO: propagate timeout
215+
"timeout": timeout,
216216
},
217217
]
218218
}

qdrant_client/qdrant_client.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,6 @@ def upsert(
15451545
wait: bool = True,
15461546
ordering: Optional[types.WriteOrdering] = None,
15471547
shard_key_selector: Optional[types.ShardKeySelector] = None,
1548-
timeout: Optional[int] = None,
15491548
**kwargs: Any,
15501549
) -> types.UpdateResult:
15511550
"""
@@ -1603,7 +1602,6 @@ def upsert(
16031602
wait=wait,
16041603
ordering=ordering,
16051604
shard_key_selector=shard_key_selector,
1606-
timeout=timeout,
16071605
**kwargs,
16081606
)
16091607

@@ -1774,7 +1772,6 @@ def delete(
17741772
wait: bool = True,
17751773
ordering: Optional[types.WriteOrdering] = None,
17761774
shard_key_selector: Optional[types.ShardKeySelector] = None,
1777-
timeout: Optional[int] = None,
17781775
**kwargs: Any,
17791776
) -> types.UpdateResult:
17801777
"""Deletes selected points from collection
@@ -1812,7 +1809,6 @@ def delete(
18121809
wait=wait,
18131810
ordering=ordering,
18141811
shard_key_selector=shard_key_selector,
1815-
timeout=timeout,
18161812
**kwargs,
18171813
)
18181814

qdrant_client/qdrant_remote.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ def __init__(
157157

158158
if self._timeout is not None:
159159
self._rest_args["timeout"] = self._timeout
160+
if self._grpc_options:
161+
self._grpc_options["timeout"] = self._timeout
162+
else:
163+
self._grpc_options = {"timeout": self._timeout}
160164

161165
if self._auth_token_provider is not None:
162166
if self._scheme == "http":
@@ -1879,7 +1883,6 @@ def upsert(
18791883
wait: bool = True,
18801884
ordering: Optional[types.WriteOrdering] = None,
18811885
shard_key_selector: Optional[types.ShardKeySelector] = None,
1882-
timeout: Optional[int] = None,
18831886
**kwargs: Any,
18841887
) -> types.UpdateResult:
18851888
if self._prefer_grpc:
@@ -1923,7 +1926,7 @@ def upsert(
19231926
ordering=ordering,
19241927
shard_key_selector=shard_key_selector,
19251928
),
1926-
timeout=timeout if timeout is not None else self._timeout,
1929+
timeout=self._timeout,
19271930
).result
19281931

19291932
assert grpc_result is not None, "Upsert returned None result"
@@ -2237,7 +2240,6 @@ def delete(
22372240
wait: bool = True,
22382241
ordering: Optional[types.WriteOrdering] = None,
22392242
shard_key_selector: Optional[types.ShardKeySelector] = None,
2240-
timeout: Optional[int] = None,
22412243
**kwargs: Any,
22422244
) -> types.UpdateResult:
22432245
if self._prefer_grpc:
@@ -2261,7 +2263,7 @@ def delete(
22612263
ordering=ordering,
22622264
shard_key_selector=shard_key_selector,
22632265
),
2264-
timeout=timeout if timeout is not None else self._timeout,
2266+
timeout=self._timeout,
22652267
).result
22662268
)
22672269
else:
@@ -2534,7 +2536,7 @@ def update_collection_aliases(
25342536
timeout=timeout,
25352537
actions=change_aliases_operation,
25362538
),
2537-
timeout=self._timeout,
2539+
timeout=timeout if timeout is not None else self._timeout,
25382540
).result
25392541

25402542
change_aliases_operation = [
@@ -2680,7 +2682,7 @@ def update_collection(
26802682
quantization_config=quantization_config,
26812683
sparse_vectors_config=sparse_vectors_config,
26822684
),
2683-
timeout=self._timeout,
2685+
timeout=timeout if timeout is not None else self._timeout,
26842686
).result
26852687

26862688
if isinstance(optimizers_config, grpc.OptimizersConfigDiff):
@@ -2719,7 +2721,7 @@ def delete_collection(
27192721
if self._prefer_grpc:
27202722
return self.grpc_collections.Delete(
27212723
grpc.DeleteCollection(collection_name=collection_name),
2722-
timeout=self._timeout,
2724+
timeout=timeout if timeout is not None else self._timeout,
27232725
).result
27242726

27252727
result: Optional[bool] = self.http.collections_api.delete_collection(
@@ -2910,6 +2912,7 @@ def _upload_collection(
29102912
"metadata": self._grpc_headers,
29112913
"wait": wait,
29122914
"shard_key_selector": shard_key_selector,
2915+
"options": self._grpc_options,
29132916
}
29142917
else:
29152918
updater_kwargs = {
@@ -3328,7 +3331,7 @@ def create_shard_key(
33283331
placement=placement or [],
33293332
),
33303333
),
3331-
timeout=self._timeout,
3334+
timeout=timeout if timeout is not None else self._timeout,
33323335
).result
33333336
else:
33343337
result = self.openapi_client.distributed_api.create_shard_key(
@@ -3363,7 +3366,7 @@ def delete_shard_key(
33633366
shard_key=shard_key,
33643367
),
33653368
),
3366-
timeout=self._timeout,
3369+
timeout=timeout if timeout is not None else self._timeout,
33673370
).result
33683371
else:
33693372
result = self.openapi_client.distributed_api.delete_shard_key(

0 commit comments

Comments
 (0)