langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
88.74k stars 13.94k forks source link

"No module named 'chromadb'" — add chromadb as dependency? #1387

Open slhck opened 1 year ago

slhck commented 1 year ago

Trying to follow the guides:

But when I run:

db = Chroma.from_documents(texts, embeddings)

I get:

ModuleNotFoundError                       Traceback (most recent call last)
File ~/Library/Caches/pypoetry/virtualenvs/docs-bot-z8dlOdVH-py3.10/lib/python3.10/site-packages/langchain/vectorstores/chroma.py:40, in Chroma.__init__(self, collection_name, embedding_function, persist_directory)
     39 try:
---> 40     import chromadb
     41     import chromadb.config

ModuleNotFoundError: No module named 'chromadb'

In my Poetry dependencies, I only had langchain and openai.

I'd suggest adding a line somewhere in the docs that this is an optional dependency and should be installed?

Once I do:

poetry add chromadb

It works.

slhck commented 1 year ago

Interestingly I did not hit this exception path:

https://github.com/hwchase17/langchain/blob/4b5e850361bd4b47ac739748232d696deac79eaf/langchain/vectorstores/chroma.py#L32-L46

Using v0.0.98 within a Jupyter notebook.

IqraShahid-dev commented 1 year ago

Even though I have installed chromadb using pip install chromadb but error still persists Is their any underlying issue ,version issue or any other ? Can't make it work

from langchain.embeddings.openai import OpenAIEmbeddings from langchain.vectorstores import Chroma embeddings= OpenAIEmbeddings(openai_api_key=os.environ['OPENAI_API_KEY']) docsearch= Chroma.from_documents(texts, embeddings)

error

Traceback (most recent call last): File "/home/ubuntu/.local/lib/python3.10/site-packages/langchain/vectorstores/chroma.py", line 62, in init import chromadb ModuleNotFoundError: No module named 'chromadb'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/ubuntu/textToQuery.py", line 22, in docsearch = Chroma.from_documents(texts, embeddings) File "/home/ubuntu/.local/lib/python3.10/site-packages/langchain/vectorstores/chroma.py", line 265, in from_documents return cls.from_texts( File "/home/ubuntu/.local/lib/python3.10/site-packages/langchain/vectorstores/chroma.py", line 228, in from_texts chroma_collection = cls( File "/home/ubuntu/.local/lib/python3.10/site-packages/langchain/vectorstores/chroma.py", line 65, in init raise ValueError( ValueError: Could not import chromadb python package. Please install it with pip install chromadb

slhck commented 1 year ago

Make sure that it's installed in the same site packages directory. You may have used a different version of pip from a different python environment.

IqraShahid-dev commented 1 year ago

pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)

I don't think so it's a pip problem. I have noticed that during pip install chromadb , torch process gets killed maybe memory issue.

Capture (2)

with this pip install torch --no-cache-dir

Capture (3)

What's the chromadb package size?

slhck commented 1 year ago

This is the size:

~/Library/Caches/pypoetry/virtualenvs/docs-bot-z8dlOdVH-py3.10
➜ du -hs lib/python3.10/site-packages/chromadb/
376K    lib/python3.10/site-packages/chromadb/

~/Library/Caches/pypoetry/virtualenvs/docs-bot-z8dlOdVH-py3.10
➜ du -hs lib/python3.10/site-packages/chromadb-0.3.10.dist-info
 32K    lib/python3.10/site-packages/chromadb-0.3.10.dist-info

For me using the following pyproject.toml was enough, using Poetry:

[tool.poetry]
name = "test"
version = "0.1.0"
description = ""
authors = [""]
readme = "README.md"
packages = [{include = "test"}]

[tool.poetry.dependencies]
python = "^3.10,<3.11"
langchain = "^0.0.98"
openai = "^0.27.0"
chromadb = "^0.3.10"

[tool.poetry.group.dev.dependencies]
flake8 = "^6.0.0"
mypy = "^1.0.1"
isort = "^5.12.0"
jupyter = "^1.0.0"
notebook = "^6.5.2"
black = "^23.1.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

Then run poetry install. I generally prefer to use Poetry over user or system library installations.

(Make sure to update to the most recent version of the packages; the above are a bit outdated.)

IqraShahid-dev commented 1 year ago

Thanks, Well my main issue was memory. With combination of larger instance and poetry ,I am able to resolve my problem.

UdayanSL commented 1 year ago

Thanks, Well my main issue was memory. With combination of larger instance and poetry ,I am able to resolve my problem.

Can you please help me out with how you took care of the situation. I am also facing the same issue...will be really helpful if you could elaborate the steps

RatanPrakash commented 1 year ago

Did you restart the terminal after the installation. try that it worked for me.

berkayaltug commented 12 months ago

Hi everyone, this is how you can fix this error.

khurramwbox commented 10 months ago

Did you restart the terminal after the installation? I have tried lot of different combination like install with pip, conda etc but it solved with just restarting kernel

vijay-pushparaj commented 10 months ago

After restart it worked for me

RatanPrakash commented 10 months ago

Close this issue for now.

slhck commented 10 months ago

I will close this issue once the chromadb dependency is properly documented. I'm not sure if this has been done in the meantime.

akashAD98 commented 10 months ago

im getting below error for chroma db

pip install chromadb
Using cached exceptiongroup-1.1.3-py3-none-any.whl (14 kB)
Building wheels for collected packages: chroma-hnswlib
  Building wheel for chroma-hnswlib (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for chroma-hnswlib (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [5 lines of output]
      running bdist_wheel
      running build
      running build_ext
      building 'hnswlib' extension
      error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for chroma-hnswlib
Failed to build chroma-hnswlib
ERROR: Could not build wheels for chroma-hnswlib, which is required to install pyproject.toml-based projects
hilarykitz commented 9 months ago

I found this was a version mismatch - langchain expected version 1.5.6. Pinning "chromadb": "1.5.6" in my package.json sorted the issue in my node project, i assume you will need to just align the version in python as well :)

wingleungchoi commented 8 months ago

In my case, it is because I named a file with chromadb.py. Python tries to import from this file instead of installed package. I solved it after renaming the file. Hope it help people new to python.

Lykos2 commented 5 months ago

Restart the terminal.It worked for me

harshpatel0204 commented 3 months ago

chromadb

refer this link for solution: https://stackoverflow.com/questions/64261546/how-to-solve-error-microsoft-visual-c-14-0-or-greater-is-required-when-inst

ashishnex007 commented 2 months ago

image

Tho I installed chromadb, still have this issue pls help anyone