Skip to content

Commit

Permalink
[BUG] Raise exception when attempting to change DF (#1461)
Browse files Browse the repository at this point in the history
## Description of changes

*Summarize the changes made by this PR.*
 - Improvements & Bug fixes
	 - Resolves #1052 

## Test plan
*How are these changes tested?*

- [x] Tests pass locally with `pytest` for python, `yarn test` for js

## Documentation Changes
*Are all docstrings for user-facing APIs updated if required? Do we need
to make documentation changes in the [docs
repository](https://github.com/chroma-core/docs)?*
  • Loading branch information
reaganjlee authored Dec 20, 2023
1 parent 466924e commit 4202a51
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions chromadb/api/models/Collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ def modify(
"""
if metadata is not None:
validate_metadata(metadata)
if "hnsw:space" in metadata:
raise ValueError(
"Changing the distance function of a collection once it is created is not supported currently.")

self._client._modify(id=self.id, new_name=name, new_metadata=metadata)
if name:
Expand Down
7 changes: 7 additions & 0 deletions chromadb/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,13 @@ def test_modify_error_on_existing_name(api):
with pytest.raises(Exception):
c2.modify(name="testspace")

def test_modify_warn_on_DF_change(api, caplog):
api.reset()

collection = api.create_collection("testspace")

with pytest.raises(Exception, match="not supported") as e:
collection.modify(metadata={"hnsw:space": "cosine"})

def test_metadata_cru(api):
api.reset()
Expand Down

0 comments on commit 4202a51

Please sign in to comment.