langchain-ai / langchain

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

'from langchain.document_loaders import TextLoader' cannot find 'RecursiveCharacterTextSplitter' #1024

Closed keviddles closed 1 year ago

keviddles commented 1 year ago

Running langchain-0.0.85 (looks like just released, thanks!) in a Jupyter notebook. Following the notebook instructions:

from langchain.document_loaders import TextLoader

And I get:

ImportError                               Traceback (most recent call last)
Cell In[30], line 5
      3 from langchain.text_splitter import CharacterTextSplitter
      4 from langchain import OpenAI, VectorDBQA
----> 5 from langchain.document_loaders import TextLoader

File /usr/local/lib/python3.10/dist-packages/langchain/document_loaders/__init__.py:3
      1 """All different types of document loaders."""
----> 3 from langchain.document_loaders.airbyte_json import AirbyteJSONLoader
      4 from langchain.document_loaders.azlyrics import AZLyricsLoader
      5 from langchain.document_loaders.college_confidential import CollegeConfidentialLoader

File /usr/local/lib/python3.10/dist-packages/langchain/document_loaders/airbyte_json.py:6
      3 from typing import Any, List
      5 from langchain.docstore.document import Document
----> 6 from langchain.document_loaders.base import BaseLoader
      9 def _stringify_value(val: Any) -> str:
     10     if isinstance(val, str):

File /usr/local/lib/python3.10/dist-packages/langchain/document_loaders/base.py:7
      4 from typing import List, Optional
      6 from langchain.docstore.document import Document
----> 7 from langchain.text_splitter import RecursiveCharacterTextSplitter, TextSplitter
     10 class BaseLoader(ABC):
     11     """Base loader class."""

ImportError: cannot import name 'RecursiveCharacterTextSplitter' from 'langchain.text_splitter' (/usr/local/lib/python3.10/dist-packages/langchain/text_splitter.py)
hwchase17 commented 1 year ago

hmmm this works for me. would you be able to set up a google collab notebook with this error for maximal reproduciblity?

keviddles commented 1 year ago

Huh, not sure what I did but I just reinstalled from scratch and it works.

The import errors referenced in #1020 and #1042 also seem to be fixed (I can import Chroma).

I'll close this ticket, sorry for the false alarm!

yogeshb369 commented 1 year ago

I was missing this line:

from langchain.text_splitter import RecursiveCharacterTextSplitter