Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Cannot import chroma due to TypeError: Instance and class checks can only be used with @runtime_checkable protocols #2806

Open
mirekphd opened this issue Sep 16, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@mirekphd
Copy link

mirekphd commented Sep 16, 2024

What happened?

Users tried to import chromadb in our AI containers (latestml/ml-gpu-py311-cuda118-hf:TAG), but the import failed with TypeError (see below for stack trace).

Versions

Chroma 0.5.3
Python 3.11.10
Ubuntu 22.04

Note: the reason why we cannot upgrade chromadb from 0.5.3 to either 0.5.4 or 0.5.5 is that both of these newer versions are blocklisted by another package as seen by this error message displayed by pip during such attempt:

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
langchain-chroma 0.1.4 requires chromadb!=0.5.4,!=0.5.5,<0.6.0,>=0.4.0, but you have chromadb 0.5.5 which is incompatible.

Relevant log output

Reproducible example using Docker run:

$ docker run --rm -it --name test latestml/ml-gpu-py311-cuda118-hf:20240916-1725 python -c "import chromadb"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/opt/conda/lib/python3.11/site-packages/chromadb/__init__.py", line 3, in <module>
    from chromadb.api.client import Client as ClientCreator
  File "/opt/conda/lib/python3.11/site-packages/chromadb/api/__init__.py", line 7, in <module>
    from chromadb.api.models.Collection import Collection
  File "/opt/conda/lib/python3.11/site-packages/chromadb/api/models/Collection.py", line 4, in <module>
    from chromadb.api.models.CollectionCommon import CollectionCommon
  File "/opt/conda/lib/python3.11/site-packages/chromadb/api/models/CollectionCommon.py", line 14, in <module>
    import chromadb.utils.embedding_functions as ef
  File "/opt/conda/lib/python3.11/site-packages/chromadb/utils/embedding_functions/__init__.py", line 46, in <module>
    _all_classes.update(_import_all_efs())
                        ^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/chromadb/utils/embedding_functions/__init__.py", line 37, in _import_all_efs
    and isinstance(attr, EmbeddingFunction)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/typing_extensions.py", line 639, in __instancecheck__
    raise TypeError("Instance and class checks can only be used with"
TypeError: Instance and class checks can only be used with @runtime_checkable protocols

Local run (inside the above containers):

(base) jovyan@004209e9b72b:~$ python
Python 3.11.10 | packaged by conda-forge | (main, Sep 10 2024, 11:01:28) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

>>> import chromadb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/conda/lib/python3.11/site-packages/chromadb/__init__.py", line 3, in <module>
    from chromadb.api.client import Client as ClientCreator
  File "/opt/conda/lib/python3.11/site-packages/chromadb/api/__init__.py", line 7, in <module>
    from chromadb.api.models.Collection import Collection
  File "/opt/conda/lib/python3.11/site-packages/chromadb/api/models/Collection.py", line 4, in <module>
    from chromadb.api.models.CollectionCommon import CollectionCommon
  File "/opt/conda/lib/python3.11/site-packages/chromadb/api/models/CollectionCommon.py", line 14, in <module>
    import chromadb.utils.embedding_functions as ef
  File "/opt/conda/lib/python3.11/site-packages/chromadb/utils/embedding_functions/__init__.py", line 46, in <module>
    _all_classes.update(_import_all_efs())
                        ^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/chromadb/utils/embedding_functions/__init__.py", line 37, in _import_all_efs
    and isinstance(attr, EmbeddingFunction)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/typing_extensions.py", line 639, in __instancecheck__
    raise TypeError("Instance and class checks can only be used with"
TypeError: Instance and class checks can only be used with @runtime_checkable protocols
>>> 

@mirekphd mirekphd added the bug Something isn't working label Sep 16, 2024
@mirekphd
Copy link
Author

One workaround I found is uninstalling the package that pins chromadb to an older version and upgrading chromadb to latest, thus:

$ pip uninstall langchain-chroma
Found existing installation: langchain-chroma 0.1.4
Uninstalling langchain-chroma-0.1.4:
  Would remove:
    /opt/conda/lib/python3.11/site-packages/langchain_chroma-0.1.4.dist-info/*
    /opt/conda/lib/python3.11/site-packages/langchain_chroma/*
Proceed (Y/n)? y
  Successfully uninstalled langchain-chroma-0.1.4

$ pip install chromadb==0.5.5

$ pip show chromadb
Name: chromadb
Version: 0.5.5
Summary: Chroma.
Home-page: https://github.com/chroma-core/chroma
Author: 
Author-email: Jeff Huber <jeff@trychroma.com>, Anton Troynikov <anton@trychroma.com>
License: 
Location: /opt/conda/lib/python3.11/site-packages
[..]

$ python -c "import chromadb; print(chromadb.__version__)"
0.5.5

@jeffchuber
Copy link
Contributor

@mirekphd making sure i have this right - latest chroma works ok? we would consider that a "valid workaround" if so...

@mirekphd
Copy link
Author

On its own and in general: if one can upgrade chromadb to its latest version - it is not even a problem that your users would encounter, but the last 2 versions including the latest i.e. the working one are for some reason blocklisted by LangChain... so effectively you cannot upgrade it to latest (if users want to use chromadb through LangChain).

@tazarov
Copy link
Contributor

tazarov commented Sep 16, 2024

@jeffchuber, this is how LC have defined their version string in 0.1.4 of the langchain-chroma package:

https://github.com/langchain-ai/langchain/blob/a319a0ff1d17057d750f7e4a8fee98aa8f68703c/libs/partners/chroma/pyproject.toml#L50

It might be so that 0.5.4 and 0.5.5 break backward compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants