Skip to content

Commit a64ec15

Browse files
committed
feat: accept PropertyIndexType enum for index_name arguments (#2098)
Adds a PropertyIndexType str-enum (SEARCHABLE, FILTERABLE, RANGE_FILTERS) accepted alongside the IndexName literals on update_property_index, rebuild_property_index, cancel_property_index_task and delete_property_index (backward- compatible widening of the v1.36 signature). The value is normalized to its wire form at the top of each method so paths, params and error messages never render the enum repr. Route-equality mock tests pin that the enum and literal forms hit identical routes, incl. RANGE_FILTERS -> rangeFilters. Read-side status types keep plain literals/str for forward compatibility.
1 parent b3bafa2 commit a64ec15

6 files changed

Lines changed: 120 additions & 24 deletions

File tree

mock_tests/test_property_reindex.py

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
from typing import Generator
2+
from typing import Generator, Union
33

44
import grpc
55
import pytest
@@ -11,6 +11,7 @@
1111
from weaviate.collections.classes.config import (
1212
PropertyIndexState,
1313
PropertyIndexTaskStatus,
14+
PropertyIndexType,
1415
Tokenization,
1516
)
1617
from weaviate.exceptions import (
@@ -393,6 +394,67 @@ def test_get_property_indexes(
393394
weaviate_139_mock.check_assertions()
394395

395396

397+
@pytest.mark.parametrize(
398+
"index_name,wire",
399+
[
400+
(PropertyIndexType.SEARCHABLE, "searchable"),
401+
("searchable", "searchable"),
402+
(PropertyIndexType.RANGE_FILTERS, "rangeFilters"),
403+
("rangeFilters", "rangeFilters"),
404+
],
405+
)
406+
def test_update_property_index_enum_and_literal_hit_same_route(
407+
weaviate_139_mock: HTTPServer,
408+
client_139: weaviate.WeaviateClient,
409+
index_name: Union[PropertyIndexType, str],
410+
wire: str,
411+
) -> None:
412+
"""The enum and literal forms of index_name hit the exact same wire route."""
413+
weaviate_139_mock.expect_request(
414+
f"{SCHEMA_PATH}/properties/name/index/{wire}",
415+
method="PUT",
416+
json={},
417+
).respond_with_json({"taskId": TASK_ID, "status": "STARTED"}, status=202)
418+
419+
task = client_139.collections.use(COLLECTION).config.update_property_index(
420+
"name",
421+
index_name, # type: ignore
422+
)
423+
assert task.status == PropertyIndexTaskStatus.STARTED
424+
weaviate_139_mock.check_assertions()
425+
426+
427+
@pytest.mark.parametrize(
428+
"index_name,wire",
429+
[
430+
(PropertyIndexType.SEARCHABLE, "searchable"),
431+
("searchable", "searchable"),
432+
(PropertyIndexType.RANGE_FILTERS, "rangeFilters"),
433+
("rangeFilters", "rangeFilters"),
434+
],
435+
)
436+
def test_delete_property_index_enum_and_literal_hit_same_route(
437+
weaviate_139_mock: HTTPServer,
438+
client_139: weaviate.WeaviateClient,
439+
index_name: Union[PropertyIndexType, str],
440+
wire: str,
441+
) -> None:
442+
"""The enum and literal forms of index_name hit the exact same wire route."""
443+
weaviate_139_mock.expect_request(
444+
f"{SCHEMA_PATH}/properties/name/index/{wire}",
445+
method="DELETE",
446+
).respond_with_json({}, status=200)
447+
448+
assert (
449+
client_139.collections.use(COLLECTION).config.delete_property_index(
450+
"name",
451+
index_name, # type: ignore
452+
)
453+
is True
454+
)
455+
weaviate_139_mock.check_assertions()
456+
457+
396458
def test_delete_property_index_surfaces_server_message(
397459
weaviate_139_mock: HTTPServer, client_139: weaviate.WeaviateClient
398460
) -> None:

weaviate/classes/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
PQEncoderDistribution,
88
PQEncoderType,
99
Property,
10+
PropertyIndexType,
1011
Reconfigure,
1112
ReferenceProperty,
1213
ReplicationDeletionStrategy,
@@ -37,6 +38,7 @@
3738
"MultiVectorAggregation",
3839
"ReplicationDeletionStrategy",
3940
"Property",
41+
"PropertyIndexType",
4042
"PQEncoderDistribution",
4143
"PQEncoderType",
4244
"ReferenceProperty",

weaviate/collections/classes/config.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,20 @@
117117
]
118118

119119

120+
class PropertyIndexType(str, BaseEnum):
121+
"""The available property index types in Weaviate.
122+
123+
Attributes:
124+
SEARCHABLE: The searchable index, used for keyword (BM25) searches over text properties.
125+
FILTERABLE: The filterable index, used for exact-match filtering.
126+
RANGE_FILTERS: The rangeable index, used for range filtering.
127+
"""
128+
129+
SEARCHABLE = "searchable"
130+
FILTERABLE = "filterable"
131+
RANGE_FILTERS = "rangeFilters"
132+
133+
120134
class ConsistencyLevel(str, BaseEnum):
121135
"""The consistency levels when writing to Weaviate with replication enabled.
122136

weaviate/collections/config/async_.pyi

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ from weaviate.collections.classes.config import (
1010
Property,
1111
PropertyIndexStatus,
1212
PropertyIndexTask,
13+
PropertyIndexType,
1314
ReferenceProperty,
1415
ShardStatus,
1516
ShardTypes,
@@ -93,12 +94,14 @@ class _ConfigCollectionAsync(_ConfigCollectionExecutor[ConnectionAsync]):
9394
async def add_vector(
9495
self, *, vector_config: Union[_VectorConfigCreate, List[_VectorConfigCreate]]
9596
) -> None: ...
96-
async def delete_property_index(self, property_name: str, index_name: IndexName) -> bool: ...
97+
async def delete_property_index(
98+
self, property_name: str, index_name: Union[PropertyIndexType, IndexName]
99+
) -> bool: ...
97100
@overload
98101
async def update_property_index(
99102
self,
100103
property_name: str,
101-
index_name: IndexName,
104+
index_name: Union[PropertyIndexType, IndexName],
102105
*,
103106
tokenization: Optional[Tokenization] = None,
104107
algorithm: Optional[Literal["blockmax"]] = None,
@@ -109,7 +112,7 @@ class _ConfigCollectionAsync(_ConfigCollectionExecutor[ConnectionAsync]):
109112
async def update_property_index(
110113
self,
111114
property_name: str,
112-
index_name: IndexName,
115+
index_name: Union[PropertyIndexType, IndexName],
113116
*,
114117
tokenization: Optional[Tokenization] = None,
115118
algorithm: Optional[Literal["blockmax"]] = None,
@@ -120,7 +123,7 @@ class _ConfigCollectionAsync(_ConfigCollectionExecutor[ConnectionAsync]):
120123
async def rebuild_property_index(
121124
self,
122125
property_name: str,
123-
index_name: IndexName,
126+
index_name: Union[PropertyIndexType, IndexName],
124127
*,
125128
tenants: Union[List[str], str, None] = None,
126129
wait_for_completion: Literal[True],
@@ -129,12 +132,12 @@ class _ConfigCollectionAsync(_ConfigCollectionExecutor[ConnectionAsync]):
129132
async def rebuild_property_index(
130133
self,
131134
property_name: str,
132-
index_name: IndexName,
135+
index_name: Union[PropertyIndexType, IndexName],
133136
*,
134137
tenants: Union[List[str], str, None] = None,
135138
wait_for_completion: Literal[False] = False,
136139
) -> PropertyIndexTask: ...
137140
async def cancel_property_index_task(
138-
self, property_name: str, index_name: IndexName
141+
self, property_name: str, index_name: Union[PropertyIndexType, IndexName]
139142
) -> PropertyIndexTask: ...
140143
async def get_property_indexes(self) -> CollectionPropertyIndexes: ...

weaviate/collections/config/executor.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
PropertyIndexState,
2828
PropertyIndexStatus,
2929
PropertyIndexTask,
30+
PropertyIndexType,
3031
PropertyType,
3132
ReferenceProperty,
3233
ShardStatus,
@@ -670,7 +671,7 @@ async def _execute() -> None:
670671
def delete_property_index(
671672
self,
672673
property_name: str,
673-
index_name: IndexName,
674+
index_name: Union[PropertyIndexType, IndexName],
674675
) -> executor.Result[bool]:
675676
"""Delete a property index from the collection in Weaviate.
676677
@@ -686,6 +687,8 @@ def delete_property_index(
686687
weaviate.exceptions.UnexpectedStatusCodeError: If Weaviate reports a non-OK status.
687688
weaviate.exceptions.WeaviateInvalidInputError: If the property or index does not exist.
688689
"""
690+
if isinstance(index_name, PropertyIndexType):
691+
index_name = cast(IndexName, index_name.value)
689692
_validate_input(
690693
[_ValidateArgument(expected=[str], name="property_name", value=property_name)]
691694
)
@@ -750,7 +753,7 @@ async def _execute() -> PropertyIndexStatus:
750753
def update_property_index(
751754
self,
752755
property_name: str,
753-
index_name: IndexName,
756+
index_name: Union[PropertyIndexType, IndexName],
754757
*,
755758
tokenization: Optional[Tokenization] = None,
756759
algorithm: Optional[Literal["blockmax"]] = None,
@@ -762,7 +765,7 @@ def update_property_index(
762765
def update_property_index(
763766
self,
764767
property_name: str,
765-
index_name: IndexName,
768+
index_name: Union[PropertyIndexType, IndexName],
766769
*,
767770
tokenization: Optional[Tokenization] = None,
768771
algorithm: Optional[Literal["blockmax"]] = None,
@@ -773,7 +776,7 @@ def update_property_index(
773776
def update_property_index(
774777
self,
775778
property_name: str,
776-
index_name: IndexName,
779+
index_name: Union[PropertyIndexType, IndexName],
777780
*,
778781
tokenization: Optional[Tokenization] = None,
779782
algorithm: Optional[Literal["blockmax"]] = None,
@@ -789,7 +792,8 @@ def update_property_index(
789792
790793
Args:
791794
property_name: The property whose index to create or migrate.
792-
index_name: The type of the index, one of `searchable`, `filterable` or `rangeFilters`.
795+
index_name: The type of the index, a `PropertyIndexType` value or one of the literals
796+
`searchable`, `filterable` or `rangeFilters`.
793797
tokenization: The tokenization of the index. Required when creating a `searchable` index;
794798
optional as a change on an existing `searchable` or `filterable` index. Not valid for
795799
`rangeFilters`.
@@ -811,6 +815,8 @@ def update_property_index(
811815
weaviate.exceptions.ReindexCanceledError: If `wait_for_completion=True` and the reindexing task was cancelled.
812816
"""
813817
self.__check_property_reindex_support("Collection config update_property_index")
818+
if isinstance(index_name, PropertyIndexType):
819+
index_name = cast(IndexName, index_name.value)
814820
_validate_input(
815821
[_ValidateArgument(expected=[str], name="property_name", value=property_name)]
816822
)
@@ -878,7 +884,7 @@ async def _execute() -> Union[PropertyIndexTask, PropertyIndexStatus]:
878884
def rebuild_property_index(
879885
self,
880886
property_name: str,
881-
index_name: IndexName,
887+
index_name: Union[PropertyIndexType, IndexName],
882888
*,
883889
tenants: Union[List[str], str, None] = None,
884890
wait_for_completion: Literal[True],
@@ -888,7 +894,7 @@ def rebuild_property_index(
888894
def rebuild_property_index(
889895
self,
890896
property_name: str,
891-
index_name: IndexName,
897+
index_name: Union[PropertyIndexType, IndexName],
892898
*,
893899
tenants: Union[List[str], str, None] = None,
894900
wait_for_completion: Literal[False] = False,
@@ -897,7 +903,7 @@ def rebuild_property_index(
897903
def rebuild_property_index(
898904
self,
899905
property_name: str,
900-
index_name: IndexName,
906+
index_name: Union[PropertyIndexType, IndexName],
901907
*,
902908
tenants: Union[List[str], str, None] = None,
903909
wait_for_completion: bool = False,
@@ -906,7 +912,8 @@ def rebuild_property_index(
906912
907913
Args:
908914
property_name: The property whose index to rebuild.
909-
index_name: The type of the index, one of `searchable`, `filterable` or `rangeFilters`.
915+
index_name: The type of the index, a `PropertyIndexType` value or one of the literals
916+
`searchable`, `filterable` or `rangeFilters`.
910917
tenants: The tenant/list of tenants for which to rebuild the index on a multi-tenant
911918
collection. If not provided, all tenants are affected.
912919
wait_for_completion: Whether to wait until the index reports `ready`. By default False.
@@ -923,6 +930,8 @@ def rebuild_property_index(
923930
weaviate.exceptions.ReindexCanceledError: If `wait_for_completion=True` and the reindexing task was cancelled.
924931
"""
925932
self.__check_property_reindex_support("Collection config rebuild_property_index")
933+
if isinstance(index_name, PropertyIndexType):
934+
index_name = cast(IndexName, index_name.value)
926935
_validate_input(
927936
[_ValidateArgument(expected=[str], name="property_name", value=property_name)]
928937
)
@@ -982,7 +991,7 @@ async def _execute() -> Union[PropertyIndexTask, PropertyIndexStatus]:
982991
def cancel_property_index_task(
983992
self,
984993
property_name: str,
985-
index_name: IndexName,
994+
index_name: Union[PropertyIndexType, IndexName],
986995
) -> executor.Result[PropertyIndexTask]:
987996
"""Cancel the live reindexing task of a property index.
988997
@@ -993,7 +1002,8 @@ def cancel_property_index_task(
9931002
9941003
Args:
9951004
property_name: The property whose reindexing task to cancel.
996-
index_name: The type of the index, one of `searchable`, `filterable` or `rangeFilters`.
1005+
index_name: The type of the index, a `PropertyIndexType` value or one of the literals
1006+
`searchable`, `filterable` or `rangeFilters`.
9971007
9981008
Returns:
9991009
A `PropertyIndexTask` with status `CANCELLED` if a live task was cancelled or `NO_OP` otherwise.
@@ -1004,6 +1014,8 @@ def cancel_property_index_task(
10041014
weaviate.exceptions.UnexpectedStatusCodeError: If Weaviate reports a non-OK status.
10051015
"""
10061016
self.__check_property_reindex_support("Collection config cancel_property_index_task")
1017+
if isinstance(index_name, PropertyIndexType):
1018+
index_name = cast(IndexName, index_name.value)
10071019
_validate_input(
10081020
[_ValidateArgument(expected=[str], name="property_name", value=property_name)]
10091021
)

weaviate/collections/config/sync.pyi

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ from weaviate.collections.classes.config import (
1010
Property,
1111
PropertyIndexStatus,
1212
PropertyIndexTask,
13+
PropertyIndexType,
1314
ReferenceProperty,
1415
ShardStatus,
1516
ShardTypes,
@@ -91,12 +92,14 @@ class _ConfigCollection(_ConfigCollectionExecutor[ConnectionSync]):
9192
def add_vector(
9293
self, *, vector_config: Union[_VectorConfigCreate, List[_VectorConfigCreate]]
9394
) -> None: ...
94-
def delete_property_index(self, property_name: str, index_name: IndexName) -> bool: ...
95+
def delete_property_index(
96+
self, property_name: str, index_name: Union[PropertyIndexType, IndexName]
97+
) -> bool: ...
9598
@overload
9699
def update_property_index(
97100
self,
98101
property_name: str,
99-
index_name: IndexName,
102+
index_name: Union[PropertyIndexType, IndexName],
100103
*,
101104
tokenization: Optional[Tokenization] = None,
102105
algorithm: Optional[Literal["blockmax"]] = None,
@@ -107,7 +110,7 @@ class _ConfigCollection(_ConfigCollectionExecutor[ConnectionSync]):
107110
def update_property_index(
108111
self,
109112
property_name: str,
110-
index_name: IndexName,
113+
index_name: Union[PropertyIndexType, IndexName],
111114
*,
112115
tokenization: Optional[Tokenization] = None,
113116
algorithm: Optional[Literal["blockmax"]] = None,
@@ -118,7 +121,7 @@ class _ConfigCollection(_ConfigCollectionExecutor[ConnectionSync]):
118121
def rebuild_property_index(
119122
self,
120123
property_name: str,
121-
index_name: IndexName,
124+
index_name: Union[PropertyIndexType, IndexName],
122125
*,
123126
tenants: Union[List[str], str, None] = None,
124127
wait_for_completion: Literal[True],
@@ -127,12 +130,12 @@ class _ConfigCollection(_ConfigCollectionExecutor[ConnectionSync]):
127130
def rebuild_property_index(
128131
self,
129132
property_name: str,
130-
index_name: IndexName,
133+
index_name: Union[PropertyIndexType, IndexName],
131134
*,
132135
tenants: Union[List[str], str, None] = None,
133136
wait_for_completion: Literal[False] = False,
134137
) -> PropertyIndexTask: ...
135138
def cancel_property_index_task(
136-
self, property_name: str, index_name: IndexName
139+
self, property_name: str, index_name: Union[PropertyIndexType, IndexName]
137140
) -> PropertyIndexTask: ...
138141
def get_property_indexes(self) -> CollectionPropertyIndexes: ...

0 commit comments

Comments
 (0)