fix: raise on attempt to change immutable vector index type (#1277)
What & why
Fixes #1277.
collection.config.update(...) silently ignored attempts to change a collection's vector index type (e.g. flat → hnsw/dynamic). The vector index type is immutable server-side, but the client neither applied the change nor reported an error, so users believed the reconfiguration had taken effect when it had not.
Root cause
In _CollectionConfigUpdate.merge_with_existing the vector-index update branches merged the new vectorIndexConfig into the existing schema without validating the requested index type:
- Legacy single vector (
vector_index_config/vectorizer_config): the config keys were merged but the top-levelschema["vectorIndexType"]was never touched — a silent no-op (the exact reproduction in the issue). - Named vectors (
vectorizer_configlist /vector_config):vectorIndexTypewas overwritten with the requested type without the required server-side reindex, mislabeling the index.
The fix
A new helper __check_vector_index_type compares the requested vector_index_type() against the existing schema's type and raises WeaviateInvalidInputError when they differ. It is invoked in all three update paths before merging:
weaviate.exceptions.WeaviateInvalidInputError: Cannot update the vector index type of a
collection from 'flat' to 'dynamic'. The vector index type is immutable. To change it you
must recreate the collection with the desired vector index type and reindex its objects.
Same-type updates (e.g. tuning ef on an existing HNSW index) continue to work unchanged. No public API signatures change, so the generated .pyi stubs are unaffected.
Testing
Added unit tests in test/collection/test_config_update.py (operating on merge_with_existing, no live Weaviate server required):
test_changing_vector_index_type_single_vector_raises— reproduces #1277 (flat → dynamic raises)test_changing_vector_index_type_via_vector_index_config_raises— deprecatedvector_index_configarg also raisestest_changing_vector_index_type_named_vector_raises/test_changing_vector_index_type_vector_config_raises— named-vector paths raisetest_same_vector_index_type_single_vector_still_updates/test_same_vector_index_type_named_vector_still_updates— allowed same-type updates still merge correctly
Verified the new "should raise" tests fail on main without the source change (DID NOT RAISE) and pass with it.
Ran locally (Python 3.12):
pytest test/collection/→ 287 passed, 1 skipped (the unrelatedtest_validator.pycollection error is only due to optional heavy depsnumpy/pandas/polarsnot installed in my minimal venv; it does not touch this change)ruff format --check→ cleanflake8→ cleanpyright→ no errors inconfig.py(the 4 pre-existingconnect/v4.pyauthlib errors are present on unmodifiedmain)pydoclint→ no new findings for the added method
CLA
Per CONTRIBUTING.md, contributions require a Contributor License Agreement (signed via the DocuSign link that the bot posts on the PR). I will sign it once it appears.
To avoid any confusion in the future about your contribution to Weaviate, we work with a Contributor License Agreement. If you agree, you can simply add a comment to this PR that you agree with the CLA so that we can merge.
beep boop - the Weaviate bot 👋🤖
PS:
Are you already a member of the Weaviate Forum?
To avoid any confusion in the future about your contribution to Weaviate, we work with a Contributor License Agreement. If you agree, you can simply add a comment to this PR that you agree with the CLA so that we can merge.beep boop - the Weaviate bot 👋🤖PS:Are you already a member of the Weaviate Forum?
yes, I agree with the CLA
you agree with the CLA
I have read and agree to the Weaviate Contributor License Agreement.