Skip to content

Commit c89f615

Browse files
authored
Allow uuids in interface (#1085)
* new: direct uuid support * tests: add uuid tests * fix: update inspection cache
1 parent 4a4d40e commit c89f615

File tree

11 files changed

+377
-19
lines changed

11 files changed

+377
-19
lines changed

qdrant_client/async_qdrant_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1608,7 +1608,7 @@ async def update_vectors(
16081608
wait: bool = True,
16091609
ordering: Optional[types.WriteOrdering] = None,
16101610
shard_key_selector: Optional[types.ShardKeySelector] = None,
1611-
update_filter: Optional[types.Payload] = None,
1611+
update_filter: Optional[types.Filter] = None,
16121612
**kwargs: Any,
16131613
) -> types.UpdateResult:
16141614
"""Update specified vectors in the collection. Keeps payload and unspecified vectors unchanged.

qdrant_client/conversions/common_types.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from typing_extensions import TypeAlias
1010

1111
from typing import Union, get_args, Sequence
12+
from uuid import UUID
1213

1314
from qdrant_client import grpc
1415
from qdrant_client.http import models as rest
@@ -56,7 +57,7 @@ def get_args_subscribed(tp): # type: ignore
5657
CollectionParamsDiff = Union[rest.CollectionParamsDiff, grpc.CollectionParamsDiff]
5758
WalConfigDiff = Union[rest.WalConfigDiff, grpc.WalConfigDiff]
5859
QuantizationConfig = Union[rest.QuantizationConfig, grpc.QuantizationConfig]
59-
PointId = Union[int, str, grpc.PointId]
60+
PointId = Union[int, str, UUID, grpc.PointId]
6061
PayloadSchemaType = Union[
6162
rest.PayloadSchemaType,
6263
rest.PayloadSchemaParams,

qdrant_client/conversions/conversion.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import uuid
12
from datetime import date, datetime, timezone
23
from typing import Any, Mapping, Optional, Sequence, Union, get_args
34

@@ -3158,6 +3159,8 @@ def convert_context_example_pair(
31583159
def convert_extended_point_id(cls, model: rest.ExtendedPointId) -> grpc.PointId:
31593160
if isinstance(model, int):
31603161
return grpc.PointId(num=model)
3162+
if isinstance(model, uuid.UUID):
3163+
model = str(model)
31613164
if isinstance(model, str):
31623165
return grpc.PointId(uuid=model)
31633166
raise ValueError(f"invalid ExtendedPointId model: {model}") # pragma: no cover

qdrant_client/embed/_inspection_cache.py

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,13 @@
862862
"properties": {
863863
"has_id": {
864864
"description": "ID-based filtering condition",
865-
"items": {"anyOf": [{"type": "integer"}, {"type": "string"}]},
865+
"items": {
866+
"anyOf": [
867+
{"type": "integer"},
868+
{"type": "string"},
869+
{"format": "uuid", "type": "string"},
870+
]
871+
},
866872
"title": "Has Id",
867873
"type": "array",
868874
}
@@ -1854,7 +1860,13 @@
18541860
"properties": {
18551861
"points": {
18561862
"description": "",
1857-
"items": {"anyOf": [{"type": "integer"}, {"type": "string"}]},
1863+
"items": {
1864+
"anyOf": [
1865+
{"type": "integer"},
1866+
{"type": "string"},
1867+
{"format": "uuid", "type": "string"},
1868+
]
1869+
},
18581870
"title": "Points",
18591871
"type": "array",
18601872
},
@@ -1887,6 +1899,7 @@
18871899
{"items": {"items": {"type": "number"}, "type": "array"}, "type": "array"},
18881900
{"type": "integer"},
18891901
{"type": "string"},
1902+
{"format": "uuid", "type": "string"},
18901903
{"$ref": "#/$defs/Document"},
18911904
{"$ref": "#/$defs/Image"},
18921905
{"$ref": "#/$defs/InferenceObject"},
@@ -1901,6 +1914,7 @@
19011914
{"items": {"items": {"type": "number"}, "type": "array"}, "type": "array"},
19021915
{"type": "integer"},
19031916
{"type": "string"},
1917+
{"format": "uuid", "type": "string"},
19041918
{"$ref": "#/$defs/Document"},
19051919
{"$ref": "#/$defs/Image"},
19061920
{"$ref": "#/$defs/InferenceObject"},
@@ -2667,7 +2681,13 @@
26672681
"points": {
26682682
"anyOf": [
26692683
{
2670-
"items": {"anyOf": [{"type": "integer"}, {"type": "string"}]},
2684+
"items": {
2685+
"anyOf": [
2686+
{"type": "integer"},
2687+
{"type": "string"},
2688+
{"format": "uuid", "type": "string"},
2689+
]
2690+
},
26712691
"type": "array",
26722692
},
26732693
{"type": "null"},
@@ -2706,7 +2726,13 @@
27062726
"points": {
27072727
"anyOf": [
27082728
{
2709-
"items": {"anyOf": [{"type": "integer"}, {"type": "string"}]},
2729+
"items": {
2730+
"anyOf": [
2731+
{"type": "integer"},
2732+
{"type": "string"},
2733+
{"format": "uuid", "type": "string"},
2734+
]
2735+
},
27102736
"type": "array",
27112737
},
27122738
{"type": "null"},
@@ -2755,6 +2781,7 @@
27552781
{"items": {"items": {"type": "number"}, "type": "array"}, "type": "array"},
27562782
{"type": "integer"},
27572783
{"type": "string"},
2784+
{"format": "uuid", "type": "string"},
27582785
{"$ref": "#/$defs/Document"},
27592786
{"$ref": "#/$defs/Image"},
27602787
{"$ref": "#/$defs/InferenceObject"},
@@ -2782,6 +2809,7 @@
27822809
"anyOf": [
27832810
{"type": "integer"},
27842811
{"type": "string"},
2812+
{"format": "uuid", "type": "string"},
27852813
{"items": {"type": "number"}, "type": "array"},
27862814
{"$ref": "#/$defs/SparseVector"},
27872815
],
@@ -2792,6 +2820,7 @@
27922820
"anyOf": [
27932821
{"type": "integer"},
27942822
{"type": "string"},
2823+
{"format": "uuid", "type": "string"},
27952824
{"items": {"type": "number"}, "type": "array"},
27962825
{"$ref": "#/$defs/SparseVector"},
27972826
],
@@ -2944,6 +2973,7 @@
29442973
"anyOf": [
29452974
{"type": "integer"},
29462975
{"type": "string"},
2976+
{"format": "uuid", "type": "string"},
29472977
{"items": {"type": "number"}, "type": "array"},
29482978
{"$ref": "#/$defs/SparseVector"},
29492979
{"type": "null"},
@@ -3156,7 +3186,13 @@
31563186
"points": {
31573187
"anyOf": [
31583188
{
3159-
"items": {"anyOf": [{"type": "integer"}, {"type": "string"}]},
3189+
"items": {
3190+
"anyOf": [
3191+
{"type": "integer"},
3192+
{"type": "string"},
3193+
{"format": "uuid", "type": "string"},
3194+
]
3195+
},
31603196
"type": "array",
31613197
},
31623198
{"type": "null"},
@@ -3200,7 +3236,13 @@
32003236
"properties": {
32013237
"ids": {
32023238
"description": "",
3203-
"items": {"anyOf": [{"type": "integer"}, {"type": "string"}]},
3239+
"items": {
3240+
"anyOf": [
3241+
{"type": "integer"},
3242+
{"type": "string"},
3243+
{"format": "uuid", "type": "string"},
3244+
]
3245+
},
32043246
"title": "Ids",
32053247
"type": "array",
32063248
},
@@ -3258,7 +3300,11 @@
32583300
"additionalProperties": False,
32593301
"properties": {
32603302
"id": {
3261-
"anyOf": [{"type": "integer"}, {"type": "string"}],
3303+
"anyOf": [
3304+
{"type": "integer"},
3305+
{"type": "string"},
3306+
{"format": "uuid", "type": "string"},
3307+
],
32623308
"description": "",
32633309
"title": "Id",
32643310
},
@@ -3385,6 +3431,7 @@
33853431
{"items": {"items": {"type": "number"}, "type": "array"}, "type": "array"},
33863432
{"type": "integer"},
33873433
{"type": "string"},
3434+
{"format": "uuid", "type": "string"},
33883435
{"$ref": "#/$defs/Document"},
33893436
{"$ref": "#/$defs/Image"},
33903437
{"$ref": "#/$defs/InferenceObject"},
@@ -3435,6 +3482,7 @@
34353482
{"items": {"items": {"type": "number"}, "type": "array"}, "type": "array"},
34363483
{"type": "integer"},
34373484
{"type": "string"},
3485+
{"format": "uuid", "type": "string"},
34383486
{"$ref": "#/$defs/Document"},
34393487
{"$ref": "#/$defs/Image"},
34403488
{"$ref": "#/$defs/InferenceObject"},
@@ -3506,6 +3554,7 @@
35063554
},
35073555
{"type": "integer"},
35083556
{"type": "string"},
3557+
{"format": "uuid", "type": "string"},
35093558
{"$ref": "#/$defs/Document"},
35103559
{"$ref": "#/$defs/Image"},
35113560
{"$ref": "#/$defs/InferenceObject"},
@@ -3532,6 +3581,7 @@
35323581
},
35333582
{"type": "integer"},
35343583
{"type": "string"},
3584+
{"format": "uuid", "type": "string"},
35353585
{"$ref": "#/$defs/Document"},
35363586
{"$ref": "#/$defs/Image"},
35373587
{"$ref": "#/$defs/InferenceObject"},
@@ -3665,6 +3715,7 @@
36653715
{"items": {"items": {"type": "number"}, "type": "array"}, "type": "array"},
36663716
{"type": "integer"},
36673717
{"type": "string"},
3718+
{"format": "uuid", "type": "string"},
36683719
{"$ref": "#/$defs/Document"},
36693720
{"$ref": "#/$defs/Image"},
36703721
{"$ref": "#/$defs/InferenceObject"},
@@ -3773,6 +3824,7 @@
37733824
"anyOf": [
37743825
{"type": "integer"},
37753826
{"type": "string"},
3827+
{"format": "uuid", "type": "string"},
37763828
{"items": {"type": "number"}, "type": "array"},
37773829
{"$ref": "#/$defs/SparseVector"},
37783830
]
@@ -3792,6 +3844,7 @@
37923844
"anyOf": [
37933845
{"type": "integer"},
37943846
{"type": "string"},
3847+
{"format": "uuid", "type": "string"},
37953848
{"items": {"type": "number"}, "type": "array"},
37963849
{"$ref": "#/$defs/SparseVector"},
37973850
]
@@ -4188,7 +4241,11 @@
41884241
"additionalProperties": False,
41894242
"properties": {
41904243
"id": {
4191-
"anyOf": [{"type": "integer"}, {"type": "string"}],
4244+
"anyOf": [
4245+
{"type": "integer"},
4246+
{"type": "string"},
4247+
{"format": "uuid", "type": "string"},
4248+
],
41924249
"description": "",
41934250
"title": "Id",
41944251
},

qdrant_client/http/models/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3605,7 +3605,7 @@ def __str__(self) -> str:
36053605
]
36063606
ExtendedPointId = Union[
36073607
StrictInt,
3608-
StrictStr,
3608+
Union[StrictStr, UUID],
36093609
]
36103610
FacetValue = Union[
36113611
StrictBool,

qdrant_client/local/async_qdrant_local.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import json
1515
import os
1616
import shutil
17+
import uuid
1718
from copy import deepcopy
1819
from io import TextIOWrapper
1920
from typing import Any, Generator, Iterable, Mapping, Optional, Sequence, Union, get_args
@@ -302,6 +303,8 @@ def _resolve_query_input(
302303

303304
def input_into_vector(vector_input: types.VectorInput) -> types.VectorInput:
304305
if isinstance(vector_input, get_args(types.PointId)):
306+
if isinstance(vector_input, uuid.UUID):
307+
vector_input = str(vector_input)
305308
point_id = vector_input
306309
if point_id not in collection.ids:
307310
raise ValueError(f"Point {point_id} is not found in the collection")
@@ -1024,7 +1027,7 @@ def uuid_generator() -> Generator[str, None, None]:
10241027
collection.upsert(
10251028
[
10261029
rest_models.PointStruct(
1027-
id=point_id,
1030+
id=str(point_id) if isinstance(point_id, uuid.UUID) else point_id,
10281031
vector=(vector.tolist() if isinstance(vector, np.ndarray) else vector) or {},
10291032
payload=payload or {},
10301033
)

qdrant_client/local/local_collection.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ def retrieve(
12171217
with_vectors: Union[bool, Sequence[str]] = False,
12181218
) -> list[models.Record]:
12191219
result = []
1220-
1220+
ids = [str(id_) if isinstance(id_, uuid.UUID) else id_ for id_ in ids]
12211221
for point_id in ids:
12221222
if point_id not in self.ids:
12231223
continue
@@ -2269,6 +2269,8 @@ def _rescore_with_formula(
22692269
return rescored[:limit]
22702270

22712271
def _update_point(self, point: models.PointStruct) -> None:
2272+
if isinstance(point.id, uuid.UUID):
2273+
point.id = str(point.id)
22722274
idx = self.ids[point.id]
22732275
self.payload[idx] = deepcopy(
22742276
to_jsonable_python(point.payload) if point.payload is not None else {}
@@ -2327,6 +2329,9 @@ def _update_point(self, point: models.PointStruct) -> None:
23272329

23282330
def _add_point(self, point: models.PointStruct) -> None:
23292331
idx = len(self.ids)
2332+
if isinstance(point.id, uuid.UUID):
2333+
point.id = str(point.id)
2334+
23302335
self.ids[point.id] = idx
23312336
self.ids_inv.append(point.id)
23322337

@@ -2454,6 +2459,9 @@ def _upsert_point(self, point: models.PointStruct) -> None:
24542459
if not self.vectors and not self.multivectors:
24552460
raise ValueError("Wrong input: Not existing vector name error")
24562461

2462+
if isinstance(point.id, uuid.UUID):
2463+
point.id = str(point.id)
2464+
24572465
if point.id in self.ids:
24582466
self._update_point(point)
24592467
else:
@@ -2534,7 +2542,7 @@ def _update_named_vectors(
25342542

25352543
def update_vectors(self, points: Sequence[types.PointVectors]) -> None:
25362544
for point in points:
2537-
point_id = point.id
2545+
point_id = str(point.id) if isinstance(point.id, uuid.UUID) else point.id
25382546
idx = self.ids[point_id]
25392547
vector_struct = point.vector
25402548
if isinstance(vector_struct, list):
@@ -2587,11 +2595,11 @@ def _selector_to_ids(
25872595
],
25882596
) -> list[models.ExtendedPointId]:
25892597
if isinstance(selector, list):
2590-
return selector
2598+
return [str(id_) if isinstance(id_, uuid.UUID) else id_ for id_ in selector]
25912599
elif isinstance(selector, models.Filter):
25922600
return self._filter_to_ids(selector)
25932601
elif isinstance(selector, models.PointIdsList):
2594-
return selector.points
2602+
return [str(id_) if isinstance(id_, uuid.UUID) else id_ for id_ in selector.points]
25952603
elif isinstance(selector, models.FilterSelector):
25962604
return self._filter_to_ids(selector.filter)
25972605
else:

qdrant_client/local/payload_filters.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from datetime import date, datetime, timezone
22
from typing import Any, Optional, Union, Dict
3+
from uuid import UUID
34

45
import numpy as np
56

@@ -184,7 +185,8 @@ def check_condition(
184185
):
185186
return True
186187
elif isinstance(condition, models.HasIdCondition):
187-
if point_id in condition.has_id:
188+
ids = [str(id_) if isinstance(id_, UUID) else id_ for id_ in condition.has_id]
189+
if point_id in ids:
188190
return True
189191
elif isinstance(condition, models.HasVectorCondition):
190192
if condition.has_vector in has_vector and has_vector[condition.has_vector]:

qdrant_client/local/qdrant_local.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
import os
55
import shutil
6+
import uuid
67
from copy import deepcopy
78
from io import TextIOWrapper
89
from typing import (
@@ -329,6 +330,8 @@ def input_into_vector(
329330
vector_input: types.VectorInput,
330331
) -> types.VectorInput:
331332
if isinstance(vector_input, get_args(types.PointId)):
333+
if isinstance(vector_input, uuid.UUID):
334+
vector_input = str(vector_input)
332335
point_id = vector_input # rename for clarity
333336
if point_id not in collection.ids:
334337
raise ValueError(f"Point {point_id} is not found in the collection")
@@ -1110,7 +1113,7 @@ def uuid_generator() -> Generator[str, None, None]:
11101113
collection.upsert(
11111114
[
11121115
rest_models.PointStruct(
1113-
id=point_id,
1116+
id=str(point_id) if isinstance(point_id, uuid.UUID) else point_id,
11141117
vector=(vector.tolist() if isinstance(vector, np.ndarray) else vector) or {},
11151118
payload=payload or {},
11161119
)

0 commit comments

Comments
 (0)