Python in Plain English

New Python content every day. Follow to join our 3.5M+ monthly readers.

Follow publication

MemGPT: Assimilating information from multiple PDFs

Using MemGPT for RAG-based activities — Part II.

Infinite memory for infinite wisdom

Part I was a long time back when MemGPT did not support PDF files. Now, however, they do.

So this is how we are going to test it.

Two PDFs with related information. One question that forces us to look at both files

Let us see how GPT4 performs when we upload the two files and ask the same question:

ChatGPT still fails at identifying all the members who are working on the project

Now let us see how MemGPT fares:

Identifies the two members working on the project

MemGPT continues to shine in this regard, and while the example provided may seem trivial at first glance, it hints at the broader implications of its capabilities. Imagine a scenario where you possess an organizational chart spread across multiple PDF files, and your goal is to identify members of a particular department. Can GPT-4 effectively consolidate this disparate information from various files and provide an accurate report? Maybe. Maybe not.

With this enthusiasm to leverage MemGPT for RAG-based tasks, let’s delve into the setup. It’s worth mentioning that, for the sake of a fair comparison, I’ve opted for GPT-4 and OpenAI libraries as the backend for this experiment. However, it’s important to note that MemGPT also offers support for local models and open-source embeddings, a topic we’ll explore in a future article.

System: Macbook Pro 16 GB RAM

MemGPT Setup:

The updated steps to install MemGPT can be found here. However, they are mentioned below:

git clone git@github.com:cpacker/MemGPT.git
pip install -e .

This allows us to run MemGPT from the command line.

MemGPT configure:

Keep your openAI API key handy for this step. I was using an old API key and it was failing. So better generate a fresh one for this experiment. Also, in case you have used MemGPT before, you can clean it by removing the .memgpt folder in the home directory.

rm -rf ~/.memgpt

This will get rid of all previous agents and data sources. So delete with caution.

Make sure you add the openAI API key to the environment variables as done below.

export OPENAI_API_KEY=<your-openai-api-key>

Next, we are going to set up the parameters of the chatbot.

memgpt configure

Running the above command allows you to select the options about the chatbot. You can select the default ones. However, please make sure you choose memgpt_docs for default_preset.

The options to be chosen. You may also have to give your openAI API key.

Load Data

Now we need to load the data files. If you want to experiment with the same pdf files as mine, you can use this and this. Or you can use any pdf files lying around (that have some form of overlapping/disjoint information between them)

For me the data files were located related to the project folder (what you downloaded from github) as follows.

We can give relative addresses while adding files

Below command to add the files.

memgpt load directory --name memgpt_data_store --input-files=data/pdf_files/exp2/Annex.pdf
memgpt load directory --name memgpt_data_store --input-files=data/pdf_files/exp2/ProjectDetails.pdf

Note that all the files are being added under the alias of memgpt_data_store. This is important as we will be using the same alias to load the embeddings of the data while chatting with the bot.

Test Chatbot

Now we are ready to test the bot.

memgpt run

Above command creates a new agent and runs the interactive interface of chat.

Ready to chat

We now ask the bot to access the file embeddings with the “attach“ command. In the terminal where you are supposed to write your chat message, you need to write /attach

/attach
Choose data source — for you it will be memgpt_data_store

Once you select the data store and press enter, it will load the embeddings and give you the prompt again to ask questions. Now you can put the bot to test with the same question that we had asked GPT4 in ChatGPT:

How many people are working on the Machine Learning: Scamming Websites Detection project, who are they?

The answer comes up as follows:

The ‘Machine Learning: Scamming Websites Detection’ project includes the following individuals: Ismail Khuda Bukhsh and Ashhad.

Here is what is looks like in the terminal.

So there you go, pretty useful I believe. Two things are remaining:

  1. Increase the scale of the experiment and see how well it can retain information.
  2. Try on local/open-source LLMs and embeddings.

I hope the article is going to be useful to you. I am thinking of doing multiple tutorials and case studies on LLMs with more regular content in newsletter form. Let me know if you would be interested in something like that.

That’s it for now. RAG but don’t BRAG.

Below are links to my other llm-based articles:

Open Source LLM:

**Textfiles on MemGPT** (Keep your eyes on this)

Paradigm Shift in Retrieval Augmented Generation: MemGPT [Not really open source as the article mentions use of OpenAI] — This is the old MemGPT, restricted to text only

Multimodal Image Chat

Super Quick Visual Conversations: Unleashing LLaVA 1.5

PDF Related

Advanced Retrieval with LlamaPacks: Elevating RAG in Fewer Lines of Code!

Super Quick: Retrieval Augmented Generation Using Ollama

Super Quick: Retrieval Augmented Generation (RAG) with Llama 2.0 on Company Information using CPU

Evaluating the Suitability of CPU-based LLMs for Online Usage [Compare the time to response of three different LLMs for RAG activities]

Database Related

Super Quick: LLAMA2 on CPU Machine to Generate SQL Queries from Schema

Close Source LLM (OpenAI):

PDF Related

Chatbot Document Retrieval: Asking Non-Trivial Questions

Database Related

Super Quick: Connecting ChatGPT to a PostgreSQL database

General Info:

OpenAI Dev Day: 6 Announcements and why us RAGgers need to be worried

Super Quick: RAG Comparison between GPT4 and Open-Source

Peace and Resistance: For Palestine

PlainEnglish.io 🚀

Thank you for being a part of the In Plain English community! Before you go:

Responses (2)

Write a response

Interresting, thank you!
Are there any frontends or APIs towards memgpt other than theterminal based chat interface? Even though I love to follow the "thoughts" of the engine, that is far from consumer friendly

--

Any idea io the cost of using MemGPT? I mean tokens per interaction.

--