Skip to content

Commit fbe4a63

Browse files
committed
refactor: require InvertedIndexType on the new reindex methods (#2098)
Tightens index_name to InvertedIndexType only on update_property_index, rebuild_property_index and cancel_property_index_task (all overloads and impls); delete_property_index keeps accepting the IndexName literals as released v1.36 API. Runtime leniency is preserved — the value is still normalized and validated as a str, so raw strings keep working and keep hitting the same routes (pinned by the literal legs of the route-equality mock tests, which sit outside the pyright scope).
1 parent d4a4ef4 commit fbe4a63

5 files changed

Lines changed: 74 additions & 53 deletions

File tree

integration/test_collection_config.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
IndexName,
4444
InvertedIndexState,
4545
InvertedIndexTaskStatus,
46+
InvertedIndexType,
4647
)
4748
from weaviate.collections.classes.tenants import Tenant
4849
from weaviate.exceptions import (
@@ -2703,15 +2704,18 @@ def test_property_reindex_searchable_lifecycle(collection_factory: CollectionFac
27032704

27042705
# create the searchable index declaratively and wait for it to become ready
27052706
status = collection.config.update_property_index(
2706-
"name", "searchable", tokenization=Tokenization.WORD, wait_for_completion=True
2707+
"name",
2708+
InvertedIndexType.SEARCHABLE,
2709+
tokenization=Tokenization.WORD,
2710+
wait_for_completion=True,
27072711
)
27082712
assert status.type == "searchable"
27092713
assert status.status == InvertedIndexState.READY
27102714
assert status.tokenization == Tokenization.WORD
27112715

27122716
# re-putting the matching configuration is a no-op
27132717
task = collection.config.update_property_index(
2714-
"name", "searchable", tokenization=Tokenization.WORD
2718+
"name", InvertedIndexType.SEARCHABLE, tokenization=Tokenization.WORD
27152719
)
27162720
assert task.status == InvertedIndexTaskStatus.NO_OP
27172721
assert task.task_id is None
@@ -2730,13 +2734,13 @@ def test_property_reindex_searchable_lifecycle(collection_factory: CollectionFac
27302734

27312735
# rebuild the index from scratch
27322736
status = collection.config.rebuild_property_index(
2733-
"name", "searchable", wait_for_completion=True
2737+
"name", InvertedIndexType.SEARCHABLE, wait_for_completion=True
27342738
)
27352739
assert status.type == "searchable"
27362740
assert status.status == InvertedIndexState.READY
27372741

27382742
# cancelling when no task is live is an idempotent no-op
2739-
task = collection.config.cancel_property_index_task("name", "searchable")
2743+
task = collection.config.cancel_property_index_task("name", InvertedIndexType.SEARCHABLE)
27402744
assert task.status == InvertedIndexTaskStatus.NO_OP
27412745

27422746
# the pre-existing delete API removes the index again
@@ -2762,7 +2766,7 @@ def test_property_reindex_range_filters(collection_factory: CollectionFactory) -
27622766
collection.data.insert_many([{"age": i} for i in range(10)])
27632767

27642768
status = collection.config.update_property_index(
2765-
"age", "rangeFilters", wait_for_completion=True
2769+
"age", InvertedIndexType.RANGE_FILTERS, wait_for_completion=True
27662770
)
27672771
assert status.type == "rangeFilters"
27682772
assert status.status == InvertedIndexState.READY
@@ -2799,7 +2803,7 @@ def test_property_reindex_coupled_tokenization_change(
27992803
collection.data.insert_many([{"name": f"object {i}"} for i in range(100)])
28002804

28012805
task = collection.config.update_property_index(
2802-
"name", "searchable", tokenization=Tokenization.FIELD
2806+
"name", InvertedIndexType.SEARCHABLE, tokenization=Tokenization.FIELD
28032807
)
28042808
assert task.status == InvertedIndexTaskStatus.STARTED
28052809
assert task.task_id is not None
@@ -2819,7 +2823,10 @@ def test_property_reindex_coupled_tokenization_change(
28192823

28202824
# poll the status endpoint (via the wait path of a NO_OP upsert) until the migration is done
28212825
status = collection.config.update_property_index(
2822-
"name", "searchable", tokenization=Tokenization.FIELD, wait_for_completion=True
2826+
"name",
2827+
InvertedIndexType.SEARCHABLE,
2828+
tokenization=Tokenization.FIELD,
2829+
wait_for_completion=True,
28232830
)
28242831
assert status.status == InvertedIndexState.READY
28252832
assert status.tokenization == Tokenization.FIELD
@@ -2851,13 +2858,16 @@ def test_property_reindex_multi_tenant(collection_factory: CollectionFactory) ->
28512858
collection.with_tenant("tenant1").data.insert_many([{"age": i} for i in range(5)])
28522859

28532860
status = collection.config.update_property_index(
2854-
"age", "rangeFilters", tenants=["tenant1", "tenant2"], wait_for_completion=True
2861+
"age",
2862+
InvertedIndexType.RANGE_FILTERS,
2863+
tenants=["tenant1", "tenant2"],
2864+
wait_for_completion=True,
28552865
)
28562866
assert status.type == "rangeFilters"
28572867
assert status.status == InvertedIndexState.READY
28582868

28592869
status = collection.config.rebuild_property_index(
2860-
"age", "rangeFilters", tenants=["tenant1"], wait_for_completion=True
2870+
"age", InvertedIndexType.RANGE_FILTERS, tenants=["tenant1"], wait_for_completion=True
28612871
)
28622872
assert status.type == "rangeFilters"
28632873
assert status.status == InvertedIndexState.READY
@@ -2882,23 +2892,26 @@ async def test_property_reindex_async(async_collection_factory: AsyncCollectionF
28822892
await collection.data.insert_many([{"name": f"object {i}"} for i in range(10)])
28832893

28842894
status = await collection.config.update_property_index(
2885-
"name", "searchable", tokenization=Tokenization.WORD, wait_for_completion=True
2895+
"name",
2896+
InvertedIndexType.SEARCHABLE,
2897+
tokenization=Tokenization.WORD,
2898+
wait_for_completion=True,
28862899
)
28872900
assert status.type == "searchable"
28882901
assert status.status == InvertedIndexState.READY
28892902

28902903
task = await collection.config.update_property_index(
2891-
"name", "searchable", tokenization=Tokenization.WORD
2904+
"name", InvertedIndexType.SEARCHABLE, tokenization=Tokenization.WORD
28922905
)
28932906
assert task.status == InvertedIndexTaskStatus.NO_OP
28942907

28952908
indexes = await collection.config.get_property_indexes()
28962909
assert indexes.collection == collection.name
28972910

28982911
status = await collection.config.rebuild_property_index(
2899-
"name", "searchable", wait_for_completion=True
2912+
"name", InvertedIndexType.SEARCHABLE, wait_for_completion=True
29002913
)
29012914
assert status.status == InvertedIndexState.READY
29022915

2903-
task = await collection.config.cancel_property_index_task("name", "searchable")
2916+
task = await collection.config.cancel_property_index_task("name", InvertedIndexType.SEARCHABLE)
29042917
assert task.status == InvertedIndexTaskStatus.NO_OP

mock_tests/test_property_reindex.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ def test_update_property_index_enum_and_literal_hit_same_route(
421421

422422
task = client_139.collections.use(COLLECTION).config.update_property_index(
423423
"name",
424+
# runtime leniency pin: raw strings must keep hitting the same route
424425
index_name, # type: ignore
425426
)
426427
assert task.status == InvertedIndexTaskStatus.STARTED
@@ -453,6 +454,7 @@ def test_delete_property_index_enum_and_literal_hit_same_route(
453454
assert (
454455
client_139.collections.use(COLLECTION).config.delete_property_index(
455456
"name",
457+
# runtime leniency pin: raw strings must keep hitting the same route
456458
index_name, # type: ignore
457459
)
458460
is True
@@ -478,6 +480,7 @@ def test_rebuild_property_index_enum_and_literal_hit_same_route(
478480

479481
task = client_139.collections.use(COLLECTION).config.rebuild_property_index(
480482
"age",
483+
# runtime leniency pin: raw strings must keep hitting the same route
481484
index_name, # type: ignore
482485
)
483486
assert task.status == InvertedIndexTaskStatus.STARTED
@@ -502,6 +505,7 @@ def test_cancel_property_index_task_enum_and_literal_hit_same_route(
502505

503506
task = client_139.collections.use(COLLECTION).config.cancel_property_index_task(
504507
"age",
508+
# runtime leniency pin: raw strings must keep hitting the same route
505509
index_name, # type: ignore
506510
)
507511
assert task.status == InvertedIndexTaskStatus.CANCELLED

weaviate/collections/config/async_.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class _ConfigCollectionAsync(_ConfigCollectionExecutor[ConnectionAsync]):
101101
async def update_property_index(
102102
self,
103103
property_name: str,
104-
index_name: Union[InvertedIndexType, IndexName],
104+
index_name: InvertedIndexType,
105105
*,
106106
tokenization: Optional[Tokenization] = None,
107107
algorithm: Optional[Literal["blockmax"]] = None,
@@ -112,7 +112,7 @@ class _ConfigCollectionAsync(_ConfigCollectionExecutor[ConnectionAsync]):
112112
async def update_property_index(
113113
self,
114114
property_name: str,
115-
index_name: Union[InvertedIndexType, IndexName],
115+
index_name: InvertedIndexType,
116116
*,
117117
tokenization: Optional[Tokenization] = None,
118118
algorithm: Optional[Literal["blockmax"]] = None,
@@ -123,7 +123,7 @@ class _ConfigCollectionAsync(_ConfigCollectionExecutor[ConnectionAsync]):
123123
async def rebuild_property_index(
124124
self,
125125
property_name: str,
126-
index_name: Union[InvertedIndexType, IndexName],
126+
index_name: InvertedIndexType,
127127
*,
128128
tenants: Union[List[str], str, None] = None,
129129
wait_for_completion: Literal[True],
@@ -132,12 +132,12 @@ class _ConfigCollectionAsync(_ConfigCollectionExecutor[ConnectionAsync]):
132132
async def rebuild_property_index(
133133
self,
134134
property_name: str,
135-
index_name: Union[InvertedIndexType, IndexName],
135+
index_name: InvertedIndexType,
136136
*,
137137
tenants: Union[List[str], str, None] = None,
138138
wait_for_completion: Literal[False] = False,
139139
) -> InvertedIndexTask: ...
140140
async def cancel_property_index_task(
141-
self, property_name: str, index_name: Union[InvertedIndexType, IndexName]
141+
self, property_name: str, index_name: InvertedIndexType
142142
) -> InvertedIndexTask: ...
143143
async def get_property_indexes(self) -> CollectionInvertedIndexes: ...

0 commit comments

Comments
 (0)