AI Learning Record – LangChain-ChatChat ChatGLM2 Personal Knowledge Base

In the previous article AI Learning Record – Using and Fine-tuning ChatGLM2-6B, we separately introduced the ChatGLM2 project, which is a class of chatGPT projects. And in this article, we will introduce the LangChain-ChatChat personal knowledge management library based on ChatGLM2 (or other chat systems) on GitHub.

Its characteristic is that it can

  • Switching quickly between different chat systems, such as between chatGPT and chatGLM.
  • Can upload files and build an intelligent retrieval system. Such as for law or medicine.

Being able to build one’s own knowledge base is the biggest advantage, and it does seem to have that effect, but I haven’t delved into using it yet. The search is a bit too fast, unlike typical AI training, so we’ll have to wait and see how effective it is.

Required Hardware

It is recommended to have a graphics card with at least 16GB of memory, but it seems that 6GB should also be sufficient if you lower the specifications. However, I have not tried it myself. If there is no GPU, the system requires at least 32GB of RAM, but the speed will be very slow. An i7-12700K processor can output about two characters per second.

Basic environment installation

Some basic environment settings (such as Anaconda and shared scripts) have already been written in the article on “Common Operations“. Please take a look first to ensure that all commands can run correctly.

Create a Conda environment

Due to the different dependencies of each project, an environment will be set up for each case here.

Source code download and installation environment

Install the following packages.

Download model and embedding

Due to downloading large files with Git, it is necessary to support LFS. You can successfully install it by following the steps in this article: Supporting LFS with Git.

Download the model and embeddings.

 

Edit configuration file

First, copy the example configuration file. Then modify model_config.py and server_config.py with the following difference in their diffs.

 

 

The diff file looks a bit messy. In model_config.py, only m3e-base and llm_model_dict only retain chatglm2-6b in embedding_model_dict. While in server_config.py, it allows connections from external machines.

Initialization and Startup

“Initiate knowledge base initialization.”

Press one key to start all services.

Start

Seeing the above picture means that it has been successfully started, and then use the browser to connect to the web page via http://IP:8501.

Home Page

On the left, you can choose to use a conversational mode, including LLM conversation (like chatGPT), knowledge base QA, or search engine. The number of historical dialogue rounds refers to the number of previous questions and answers that it will reference. On the right is the question and answer area.

Knowledge Base Management

Entering the knowledge base management, you can perform operations such as creating and uploading files. Let’s try downloading the Copyright Act from the Ministry of Justice link. Downloading a PDF should work.

Alright, switching back to the dialogue mode and selecting Knowledge Base Q&A.

I asked “Will I be punished for distributing pirated software?” and “What is the range of possible sentences?”, and he spoke knowledgeably about it. After carefully reading one of them, I found out that it was indeed correct!

“Violation of Article 81-1 may be punished by imprisonment for a term not exceeding one year, detention, or a fine of not less than NT$250,000 and not more than NT$2,500,000, in addition to any other punishment provided by law.”

Conclusion

These two articles really amazing, it has only been a short time since the last research and there is already a powerful retriever that can be used privately! AI’s progress is really fast~

Leave a Reply(Name請以user_開頭,否則會被判定會垃圾息)

請輸入答案 39 − 36 =