yoshidashingo / langchain-book

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

P104 Vector stores

nekonisi opened this issue · comments

エラーの説明

発生したエラーについて説明してください。
エラーメッセージは省略せず、全文を掲載してください。

下記コードでImportErrorが発生します。

from langchain.vectorstores import Chroma

db = Chroma.from_documents(docs, embeddings)
---------------------------------------------------------------------------
PydanticImportError                       Traceback (most recent call last)
[/usr/local/lib/python3.10/dist-packages/langchain/vectorstores/chroma.py](https://localhost:8080/#) in __init__(self, collection_name, embedding_function, persist_directory, client_settings, collection_metadata, client, relevance_score_fn)
     79         try:
---> 80             import chromadb
     81             import chromadb.config

7 frames
PydanticImportError: `BaseSettings` has been moved to the `pydantic-settings` package. See https://docs.pydantic.dev/2.6/migration/#basesettings-has-moved-to-pydantic-settings for more details.

For further information visit https://errors.pydantic.dev/2.6/u/import-error

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
[/usr/local/lib/python3.10/dist-packages/langchain/vectorstores/chroma.py](https://localhost:8080/#) in __init__(self, collection_name, embedding_function, persist_directory, client_settings, collection_metadata, client, relevance_score_fn)
     81             import chromadb.config
     82         except ImportError:
---> 83             raise ImportError(
     84                 "Could not import chromadb python package. "
     85                 "Please install it with `pip install chromadb`."

ImportError: Could not import chromadb python package. Please install it with `pip install chromadb`.

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

スクリーンショット

できるだけ、エラーのスクリーンショットを共有してください。

省略します

書籍の該当箇所

書籍のどの章のどの箇所でエラーが発生したのか記載してください。
例えば書籍のどのページかを記載いただくと、対応がスムーズになります。

p104 Vectore stores

書籍の内容以外で実施したこと

書籍の内容以外で何か実施した場合、その内容も記載してください。
たとえば書籍と違う手順でコマンドを実行した場合は、分かる範囲で実行したコマンド・手順を記載してください。

  • エラーメッセージの内容から推測して、pydanticをインストールし、実行しましたが解決しませんでした。
!pip install pydantic==1.9.1

環境

Google Colab

その他

エラーの解決のため、その他ご自身で試したことや、確認したログなどがあれば記載してください。

エラーのご報告ありがとうございます。

確認したところ、pydanticのアップデートに起因して、chromadb v0.4.10と不整合が起こり、このエラーが発生するようになっていたようです。

以下のようにpydanticを動作確認済みのバージョンに変更することで、このエラーは発生しなくなります。

!pip install pydantic==1.10.13

※ 本書では各パッケージの動作確認済みバージョンを こちらのファイル などで公開しています。

上記のpydanticのインストールコマンドは、pydanticが最初に使われる前に実行する必要があります。
Google Colabのランタイムを再起動または削除したうえで、ノートブックの先頭のあたりで実行してください。

こちらのエラーには他の方も遭遇する可能性が高そうなので、このGitHubリポジトリのTOPや第5章のノートブックに記載を追加させていただきました。

https://github.com/yoshidashingo/langchain-book
https://github.com/yoshidashingo/langchain-book/blob/main/chapter5/notebook.ipynb

よろしくお願いします。

ご対応ありがとうございます。
動作確認後、クローズするようにいたします。

It works!😍