chroma-core / chroma-core/chroma

[Bug]: validation context fails when underlying exception has keyword-only args

Open
#3,233 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
29.3k
Forks
2.5k
Avg merge
1d 4h
Merged PRs (30d)
38

Description

### What happened?

The following code throws a `TypeError` when `validation_context` tries to add context to the exception:
```python
import chromadb
from chromadb.utils import embedding_functions

client = chromadb.HttpClient()
embedding_function = embedding_functions.OpenAIEmbeddingFunction(
api_key="This is a bad key!",
model_name="text-embedding-3-small",
)

client.delete_collection("test")
collection = client.create_collection("test", embedding_function=embedding_function)
collection.add(
documents=["Hello, world!"],
ids=["id1"],
)
```

Instead, it should throw an `APIStatusError`

### Versions

Chroma version: 0.5.21
OpenAI version: 1.56.1
Python version: 3.12.7 (main, Oct 19 2024, 03:00:35) [GCC 12.2.0]
Operating System: linux
OS Version: #1 SMP Thu Oct 3 10:17:28 UTC 2024
OS Release: 6.10.11-linuxkit
Machine Architecture: aarch64

### Relevant log output

```shell
Traceback (most recent call last):
File "/app/.venv/lib/python3.12/site-packages/chromadb/api/models/CollectionCommon.py", line 90, in wrapper
return func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/chromadb/api/models/CollectionCommon.py", line 213, in _validate_and_prepare_add_request
add_embeddings = self._embed_record_set(record_set=add_records)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/chromadb/api/models/CollectionCommon.py", line 526, in _embed_record_set
return self._embed(input=record_set[field]) # type: ignore[literal-required]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/chromadb/api/models/CollectionCommon.py", line 539, in _embed
return self._embedding_function(input=input)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/chromadb/api/types.py", line 466, in __call__
result = call(self, input)
^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/chromadb/utils/embedding_functions/openai_embedding_function.py", line 113, in __call__
embeddings = self._client.create(
^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/openai/resources/embeddings.py", line 124, in create
return self._post(
^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 1280, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 957, in request
return self._request(
^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/openai/_base_client.py", line 1061, in _request
raise self._make_status_error_from_response(err.response) from None
openai.AuthenticationError: Error code: 401 - {'error': {'message': 'Incorrect API key provided: This is ******key!. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/app/debug.py", line 11, in
collection.add(
File "/app/.venv/lib/python3.12/site-packages/chromadb/api/models/Collection.py", line 81, in add
add_request = self._validate_and_prepare_add_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/chromadb/api/models/CollectionCommon.py", line 93, in wrapper
raise type(e)(msg).with_traceback(e.__traceback__)
^^^^^^^^^^^^
TypeError: APIStatusError.__init__() missing 2 required keyword-only arguments: 'response' and 'body'
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in chromadb/api/models/CollectionCommon.py at the wrapper around line 93, then reproduce the reported collection.add call with the invalid OpenAI key. Trace how validation_context rebuilds the exception and verify that the failure remains an APIStatusError rather than becoming a TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.