Long Term Memory AI Chatbot
Tags: ai, machinelearning, productivity, lowcode
Published: 2024-06-29 11:47:56

Our [AI workflow technology](https://ainiro.io/ai-workflows) allows us to deliver AI chatbots with long term memory. This allows you to _"train"_ your AI chatbot during conversations, and such modify your chatbot's future responses as a consequence of you correcting it during interactions.

This is one of the core requirements for AGI, and is actually extremely easy to build using our technology. In the following video I am showing you how to create an AI chatbot with long term memory in 3 minutes.

{% embed https://www.youtube.com/watch?v=a7O7-_JVAaY %}

## How it works

The implementation is actually ridiculously simple. It is basically just an AI function that can be triggered using natural language, that persists information into the chatbot's RAG and VSS database.

This allows the AI chatbot to use whatever information you're providing to it in the future for information related to the subject you store in its memory. Below is the entire training snippet's prompt engineering.

**Store to memory**

```text
Stores a piece of information to long term memory, which implies saving to
ml_training_snippets, and re-vectorizing the type, such that it can be
retrieved later using RAG and VSS.

The [prompt] argument and the [completion] argument are both mandatory
arguments. If the user does not provide you with an explicit prompt
argument, then create a short one line summary of the information with
keywords related to the fact that makes it easy to retrieve the information
later using RAG and VSS.

If the user asks you to perform an action associated with this function
invocation, then inform the user of what you are about to do, and do not
return follow up questions, but instead end your response with the following:

___
FUNCTION_INVOCATION[/modules/openai/workflows/workflows/store-memory.hl]:
{
  "prompt": "[VALUE]",
  "completion": "[VALUE]"
}
___
```

The entire AI workflow itself looks like the following.

```text
.arguments
   _type:string
   prompt:string
   completion:string
.description:Store something to long term memory
.type:public

// Sanity checking invocation.
validators.mandatory:x:@.arguments/*/_type
validators.mandatory:x:@.arguments/*/prompt
validators.mandatory:x:@.arguments/*/completion

// Opening up our database connection to store item to memory.
data.connect:[generic|magic]

   // Creating our ml_training_snippets item.
   data.create
      table:ml_training_snippets
      values
         type:x:@.arguments/*/_type
         prompt:x:@.arguments/*/prompt
         completion:x:@.arguments/*/completion
         meta:long-term-memory

// Re-vectorising the type.
execute:magic.ai.vectorise
   type:x:@.arguments/*/_type

// Returning success to caller.
return
   result:success
```

The above **[\_type]** argument is automatically added to the invocation by the AI function invocation implementation, and is basically just whatever machine learning type you happen to be using this within.

## Use cases

* Training the chatbot in natural language conversations
* QA testing and increasing the chatbot's quality during conversations
* Creating an AI Expert System serving as a _"memory extension"_
* Etc, etc, etc

Of the above I think possibly the training parts is my favourite, because it allows you to start out with an _"empty AI machine learning model"_, start asking it questions, and only when it fails you modify it. This allows you to use the GPT-4o model as your foundation, and only modify it where it goes wrong.

If you're interested in such an AI chatbot, and/or AI Expert System, you can contact us below.

* [Contact us](https://ainiro.io/contact-us)