AI Chatbots with Long Term Memory

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.

Example of a RAG AI chatbot

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.

Creating RAG data during conversations

To understand what's happening above, let's break it down into a sequence of events.

  1. My prompt is sent to OpenAI.
  2. OpenAI returns a function invocation to the cloudlet.
  3. The cloudlet executes the function, which will use DuckDuckGo to search for "Thomas Hansen Hyperlambda."
  4. 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.
  5. 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.
  6. 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.

Cloudlet having long-term memory now in its RAG database

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.

Thomas Hansen

Thomas Hansen I am the CEO and Founder of AINIRO.IO, Ltd. I am a software developer with more than 25 years of experience. I write about Machine Learning, AI, and how to help organizations adopt said technologies. You can follow me on LinkedIn if you want to read more of what I write.

Published 29. Nov 2024

Protecting your AI Chatbot against Abuse

A ChatGPT-based AI chatbot needs to be protected against abuse to make sure malicious actors don't waste your OpenAI API tokens on spam.

Read More

Delivering AI SaaS Companies for the Price of a Website

We're now able to deliver an AI SaaS company out of the box, for the price you'd typically pay for a custom website.

Read More

Not Invented Here Syndrome

We've just released a new plugin for Magic Cloud allowing you to use generative AI and ChatGPT to search for and analyse 280 million patents.

Read More