1

I am trying to do a text chunking by LangChain's RecursiveCharacterTextSplitter model. I have install langchain(pip install langchain[all]), but the program still report there is no RecursiveCharacterTextSplitter package. I use from langchain.text_splitter import RecursiveCharacterTextSplitter I tried to find something on the python file of langchain and get nothing helpful. Anyone meet the same problem? Thank you for your time!

If anyone knows how to solve it, that will be great.

  • langchain is not good: https://youtu.be/ygehmBjwtiw – D.L Aug 19 '23 at 06:31
  • There have been a lot of questions recently around langchain (just search stackoverflow). It may not be as robust as it could be – DarkKnight Aug 19 '23 at 06:45
  • Here's something that might assist you: consider exploring this implementation using LangChain - you can find it at [PrivateDocBot](https://github.com/Abhi5h3k/PrivateDocBot) – Abhi Aug 27 '23 at 15:27

2 Answers2

0

Could you try below steps.

Create a virtual environment using the command

    python -m venv my_venv_name

Activate the virtual environment by executing source

    my_venv_name/bin/activate

PIP install libraries

   pip install langchain==0.0.208 
   pip install """Other required libraries like OpenAI etc..

You should now successfully able to import

    from langchain.text_splitter import RecursiveCharacterTextSplitter

Also, you can check

your langchain environment path, something as /langchain_env/lib/python3.9/site-packages/langchain/text_splitter.py, here you you should see the definition of RecursiveCharacterTextSplitter

ZKS
  • 817
  • 3
  • 16
  • 31
  • I installed langchain 0.0.39 and it doesnt work. Then I followed your directions to install 0.0.208 and it work. Do you know the reason why 0.0.39 doesnt work? – Zhenyu Wang Aug 20 '23 at 00:45
  • 0.0.39 seems to be very old version, not able to find on github as well. I see oldest version 0.0.64 https://github.com/langchain-ai/langchain/releases?page=22 , which is also having RecursiveCharacterTextSplitter. So you can use any version based on your requirement between 0.0.64 to current latest version 0.0.268. Latest stable version is always recommended. – ZKS Aug 20 '23 at 06:08
  • Got it. I thought 0.0.39 is newer than 0.0.208 cause it starts from '3' newer than '2' lol. Ok I got it. Thanks a lot! – Zhenyu Wang Aug 20 '23 at 23:14
0

In my env, I have

pip list | grep langchain
langchain                    0.0.262

then the following should work

from langchain.text_splitter import RecursiveCharacterTextSplitter
j3ffyang
  • 1,049
  • 12
  • 12
  • That should work too. It is just the version reason. I used a too old version to import RecursiveCharacterTextSplitter – Zhenyu Wang Aug 20 '23 at 23:16