weaviate-python-client icon indicating copy to clipboard operation
weaviate-python-client copied to clipboard

fix: raise on attempt to change immutable vector index type (#1277)

Open shaikn6 opened this issue 5 months ago • 4 comments

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-level schema["vectorIndexType"] was never touched — a silent no-op (the exact reproduction in the issue).
  • Named vectors (vectorizer_config list / vector_config): vectorIndexType was 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 — deprecated vector_index_config arg also raises
  • test_changing_vector_index_type_named_vector_raises / test_changing_vector_index_type_vector_config_raises — named-vector paths raise
  • test_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 unrelated test_validator.py collection error is only due to optional heavy deps numpy/pandas/polars not installed in my minimal venv; it does not touch this change)
  • ruff format --check → clean
  • flake8 → clean
  • pyright → no errors in config.py (the 4 pre-existing connect/v4.py authlib errors are present on unmodified main)
  • 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.

shaikn6 avatar Jun 25 '26 14:06 shaikn6

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?

weaviate-git-bot avatar Jun 25 '26 15:06 weaviate-git-bot

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

shaikn6 avatar Jun 25 '26 15:06 shaikn6

you agree with the CLA

shaikn6 avatar Jun 25 '26 15:06 shaikn6

I have read and agree to the Weaviate Contributor License Agreement.

shaikn6 avatar Jun 25 '26 16:06 shaikn6