chroma-core / chroma

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

[Bug]: KeyError 'dimension' after upgrading from 0.4.24 to 0.5.3 #2440

Closed vishalnagda1 closed 3 months ago

vishalnagda1 commented 3 months ago

What happened?

After updating chromadb from version 0.4.24 to 0.5.3, our Flask application throws a KeyError: 'dimension' when attempting to create a collection. This error does not occur in version 0.4.24. It seems that the newer version may have changed how dimensions are handled, but there was no clear documentation on how to adapt to these changes.

Environment:

Steps to Reproduce:

Expected Result: The application should successfully interact with the chromadb client to get or create a collection without errors, as it did in version 0.4.24.

Actual Result: The application fails and throws the following error: KeyError: 'dimension' The traceback points to the line where create_collection attempts to access dimension from a JSON response, which apparently does not exist in the new version.

Code Snippet: Here is the relevant part of the code that leads to the exception:

# Assuming resp_json is the response from some API call
dimension = resp_json["dimension"]  # This line throws KeyError in version 0.5.3

Additional Context: It's possible that the newer version of chromadb handles dimensions differently or the key has been renamed or removed. Any guidance on handling this change or a fix would be greatly appreciated.

Versions

Relevant log output

pipenv run flask shell
Loading .env environment variables...
[2024-07-02 12:59:58,964] INFO in mongoClient: Database connected successfully TNGPT-db
/home/vishal/.local/share/virtualenvs/backend-8pWthUxh/lib/python3.10/site-packages/transformers/utils/generic.py:441: UserWarning: torch.utils._pytree._register_pytree_node is deprecated. Please use torch.utils._pytree.register_pytree_node instead.
  _torch_pytree._register_pytree_node(
/home/vishal/.local/share/virtualenvs/backend-8pWthUxh/lib/python3.10/site-packages/transformers/utils/generic.py:309: UserWarning: torch.utils._pytree._register_pytree_node is deprecated. Please use torch.utils._pytree.register_pytree_node instead.
  _torch_pytree._register_pytree_node(
Traceback (most recent call last):
  File "/home/vishal/.local/share/virtualenvs/backend-8pWthUxh/bin/flask", line 8, in <module>
    sys.exit(main())
  File "/home/vishal/.local/share/virtualenvs/backend-8pWthUxh/lib/python3.10/site-packages/flask/cli.py", line 1105, in main
    cli.main()
  File "/home/vishal/.local/share/virtualenvs/backend-8pWthUxh/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/home/vishal/.local/share/virtualenvs/backend-8pWthUxh/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/vishal/.local/share/virtualenvs/backend-8pWthUxh/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/vishal/.local/share/virtualenvs/backend-8pWthUxh/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/home/vishal/.local/share/virtualenvs/backend-8pWthUxh/lib/python3.10/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/vishal/.local/share/virtualenvs/backend-8pWthUxh/lib/python3.10/site-packages/flask/cli.py", line 383, in decorator
    app = ctx.ensure_object(ScriptInfo).load_app()
  File "/home/vishal/.local/share/virtualenvs/backend-8pWthUxh/lib/python3.10/site-packages/flask/cli.py", line 335, in load_app
    app = locate_app(import_name, name)
  File "/home/vishal/.local/share/virtualenvs/backend-8pWthUxh/lib/python3.10/site-packages/flask/cli.py", line 245, in locate_app
    __import__(module_name)
  File "/home/vishal/dev/tngpt/backend/src/app.py", line 29, in <module>
    from src.modules.index import *
  File "/home/vishal/dev/tngpt/backend/src/modules/index.py", line 2, in <module>
    from src.modules.file_upload.index import *
  File "/home/vishal/dev/tngpt/backend/src/modules/file_upload/index.py", line 4, in <module>
    from src.modules.file_upload.handler import list_uploads, bulk_delete, get_upload_detail, archive_upload, upload_single_file
  File "/home/vishal/dev/tngpt/backend/src/modules/file_upload/handler.py", line 15, in <module>
    from src.modules.file_data.handler import extract_file_data
  File "/home/vishal/dev/tngpt/backend/src/modules/file_data/handler.py", line 8, in <module>
    from src.modules.file_data.helper import (
  File "/home/vishal/dev/tngpt/backend/src/modules/file_data/helper.py", line 15, in <module>
    from src.database.chroma import store_text_in_vector
  File "/home/vishal/dev/tngpt/backend/src/database/chroma.py", line 58, in <module>
    def get_chroma_collection(instance=get_chroma_instance()):
  File "/home/vishal/dev/tngpt/backend/src/database/chroma.py", line 55, in get_chroma_instance
    return Chroma(embedding_function=_OEMBED, client=connect_chroma())
  File "/home/vishal/.local/share/virtualenvs/backend-8pWthUxh/lib/python3.10/site-packages/langchain_chroma/vectorstores.py", line 204, in __init__
    self.__ensure_collection()
  File "/home/vishal/.local/share/virtualenvs/backend-8pWthUxh/lib/python3.10/site-packages/langchain_chroma/vectorstores.py", line 211, in __ensure_collection
    self._chroma_collection = self._client.get_or_create_collection(
  File "/home/vishal/.local/share/virtualenvs/backend-8pWthUxh/lib/python3.10/site-packages/chromadb/api/client.py", line 151, in get_or_create_collection
    return self._server.get_or_create_collection(
  File "/home/vishal/.local/share/virtualenvs/backend-8pWthUxh/lib/python3.10/site-packages/chromadb/telemetry/opentelemetry/__init__.py", line 146, in wrapper
    return f(*args, **kwargs)
  File "/home/vishal/.local/share/virtualenvs/backend-8pWthUxh/lib/python3.10/site-packages/chromadb/api/fastapi.py", line 290, in get_or_create_collection
    self.create_collection(
  File "/home/vishal/.local/share/virtualenvs/backend-8pWthUxh/lib/python3.10/site-packages/chromadb/telemetry/opentelemetry/__init__.py", line 146, in wrapper
    return f(*args, **kwargs)
  File "/home/vishal/.local/share/virtualenvs/backend-8pWthUxh/lib/python3.10/site-packages/chromadb/api/fastapi.py", line 220, in create_collection
    dimension=resp_json["dimension"],
KeyError: 'dimension'
tazarov commented 3 months ago

@vishalnagda1, we've fixed this problem in latest main with #2378. Can you pull from main instead of latest (0.5.3) pypi version.

The issue is that newer clients add additional attributes that older servers will not return, thus throwing the KeyError you see above.

You can also upgrade your server to version 0.5.3. Our general recommendation to avoid similar errors in the future is to upgrade servers and clients in lockstep.

vishalnagda1 commented 3 months ago

Thank you for your help! Pulling the latest changes from the main branch as you suggested resolved the issue. I've updated my project, and everything is working smoothly now. I appreciate your guidance and quick response. I'll close this issue now.