AI Chatbots with Long Term Memory
To create an AI chatbot with long term memory can be done entirely without coding using Magic. The process combines RAG with AI functions, allowing us to dynamically populate the RAG database as we're prompting the AI chatbot.
The Basics of RAG
RAG or Retrieval Augmented Generation implies to retrieve context data, associate the context with a question, for then to supply both the context data and the question to OpenAI or some other LLM. This is the core foundation for how an AI chatbot such as ours is created. When the user is asking a question, our platform will retrieve matching context data from our RAG database and push this to OpenAI, having OpenAI using this context to answer the user's original question. You can see an example of it below.
Basics of AI Agents
An AI Agent again can execute functions and actually do something. This "something" can be for instance to save items into a database. By exposing a function to the AI agent that allows it to update its RAG data, we can now dynamically add to our RAG data during conversations with our AI chatbot.
To understand what's happening above, let's break it down into a sequence of events.
- My prompt is sent to OpenAI.
- OpenAI returns a function invocation to the cloudlet.
- The cloudlet executes the function, which will use DuckDuckGo to search for "Thomas Hansen Hyperlambda."
- The search result is then sent to OpenAI, which again finds the 3 results most likely to answer the original question, and returns another function invocation to the cloudlet.
- The cloudlet executes this function too, which again results in that it scrapes the 3 most relevant search results from DuckDuckGo and creates a "context" it sends to OpenAI again based upon the content it found at these 3 URLs.
- OpenAI uses this context to create a summary, and finishes with returning another function invocation that dynamically inserts a new RAG data item into the cloudlet's RAG database.
Afterwards the AI chatbot will "remember" what it just stored in its long term memory if asked about Hyperlambda. Below you can see how it's able to answer questions about Hyperlambda correctly in a new session.
Without us having performed the first step asking it to create a new training snippet, the AI chatbot would probably have hallucinated and just made up some random stuff about Hyperlambda and its inventor. For the record, both of the last two screenshots are taken from our AI Expert System.
Advantages
This allows you to use an AI chatbot user interface to search, scrape, and explore concepts - For then to persist facts and search results into its RAG data. This allows you to dynamically create your AI chatbot using natural language and perform web searches and scrape URLs. Some example use cases might be.
- Research
- OSINT
- Knowledge Expert Systems
- Etc ...
How it's done
The first thing you'll need is a Magic Cloud cloudlet. Once you've got a cloudlet, you'll need to install the following plugins.
- AI Expert System plugin
- OpenAI plugin
Then you'll need to create a machine learning type, and choose "AI Agent" as its flavour. When you're done with this, you'll need to add the "create-snippet" AI function to it, for then to vectorize your type. Anything you now say to the AI chatbot that's some sort of permutation of "Create a new training snippet" will ensure the cloudlet persists a new training snippet into your RAG database.
You can watch the following video where I walk you through the whole process.
Have a Custom AI Solution
At AINIRO we specialise in delivering custom AI solutions and AI chatbots with AI agent features. If you want to talk to us about how we can help you implement your next custom AI solution, you can reach out to us below.