chroma-core / chroma

the AI-native open-source embedding database
https://www.trychroma.com/
Apache License 2.0
14.95k stars 1.26k forks source link

[Bug]: Collection.delete raises Exception instead of ValueError #2569

Open curious-broccoli opened 2 months ago

curious-broccoli commented 2 months ago

What happened?

Maybe this is intended, but the docs for Collection.delete say that it should raise ValueError if e.g. no ids are passed. But it raises an Exception.

import chromadb

client = chromadb.HttpClient(host="localhost", port="8100")
collection = client.get_collection("hpc-expert")
try:
    collection.delete(ids=[])
except ValueError:
    print("ValueError")
except Exception:
    print("Exception")
    raise

Versions

Client: chromadb 0.5.0 or chromadb-client 0.5.5.dev0, Python 3.12.4 Server: docker image chromadb/chroma:0.5.4

Relevant log output

Exception
Traceback (most recent call last):
  File "/home/moritz/programming/python/venv/chromaJustClient/lib/python3.12/site-packages/chromadb/api/base_http_client.py", line 95, in _raise_chroma_error
    resp.raise_for_status()
  File "/home/moritz/programming/python/venv/chromaJustClient/lib/python3.12/site-packages/httpx/_models.py", line 761, in raise_for_status
    raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Server error '500 Internal Server Error' for url 'http://localhost:8100/api/v1/collections/1e2073a0-4dcf-4f38-9a09-7d40b783d5cd/delete'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/moritz/programming/python/llm-server-wrappers/hpc-expert/hpc-expert/testdb.py", line 6, in <module>
    collection.delete(ids=[])
  File "/home/moritz/programming/python/venv/chromaJustClient/lib/python3.12/site-packages/chromadb/api/models/Collection.py", line 332, in delete
    self._client._delete(self.id, ids, where, where_document)
  File "/home/moritz/programming/python/venv/chromaJustClient/lib/python3.12/site-packages/chromadb/telemetry/opentelemetry/__init__.py", line 146, in wrapper
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/home/moritz/programming/python/venv/chromaJustClient/lib/python3.12/site-packages/chromadb/api/fastapi.py", line 368, in _delete
    resp_json = self._make_request(
                ^^^^^^^^^^^^^^^^^^^
  File "/home/moritz/programming/python/venv/chromaJustClient/lib/python3.12/site-packages/chromadb/api/fastapi.py", line 87, in _make_request
    BaseHTTPClient._raise_chroma_error(response)
  File "/home/moritz/programming/python/venv/chromaJustClient/lib/python3.12/site-packages/chromadb/api/base_http_client.py", line 97, in _raise_chroma_error
    raise (Exception(resp.text))
Exception: {"error":"ValueError('\\n                You must provide either ids, where, or where_document to delete. If\\n                you want to delete all data in a collection you can delete the\\n                collection itself using the delete_collection method. Or alternatively,\\n                you can get() all the relevant ids and then delete them.\\n                ')"}
tazarov commented 2 months ago

Hey @curious-broccoli, thanks for bringing this to our attention. Indeed, generic value errors like this one cause the server to return a pretty generic exception, str(e), and then the client handles it as a generic Exception with raise_for_status().

We have a PR that addresses this to a certain degree, in addition to other issues - #1494.