Okay.
Let's talk a little bit about memory in, uh, Elm applications.
As we already know, uh, the memory of a foundation LMS is limited by their context window.
This is one of the main problems of the Foundation Elm models.
And we know that the best way to solve this problem is using what we call the RAC technique.
And long chain is good, uh, you know, providing RAC technique solutions.
But apart from that, in addition to the RAC technique, like long chain offers several features to
manage the memory of larger maps.
These are interesting, uh, features, but in practice we seldom will use it.
So it's not going to be frequent that we use these alternatives to the RAC technique.
We mostly will use the RAC technique.
And in some very specific cases we may use this buffer memories that long chain offer us.
And you will see very quickly in the code in the right side of the screen.
What are these buffer memories?
We are going to present four kinds of buffer memories provided by long chain.
The first one is the buffer memory.
So after as usual, connecting with the dot m file and getting the credentials, etc. etc. we will import
the necessary modules to uh uh to.
Design a very simple exercise to demonstrate the conversation buffer.
So what we do here is we are going to create a variable called buffer memory.
We can call it whatever we want.
And we want we we are going to apply the conversation buffer memory module we have imported.
So now we have an instance of the LM and a buffer memory.
We will create now a conversation chain using the conversation chain module from uh from Lang chain.
And in this conversation chain that we call conversation we are going to configure the LM.
We are going to say that, and then we are going to use the LM we have created and memory and in the
memory we are going to say we are going to use the buffer memory we created.
Okay.
In this case, we are also going to configure verbose as true because we want to see what is happening.
You know, in the background.
With this configure we can start talking with the LM model and we can say okay my hi my name is Julio
and I have moved 33 times.
We send this message to the LM and we see here what is the behavior of the LM.
So since we have verbose as true, we can see what is happening in the background.
So the LM is building this prompt.
And you will see that this prompt here, the role, the definition of the role of the LM is something
that the conversation chain creates by default.
Okay.
So by default this chain tells the LM model the following.
The following is a friendly conversation between a human and an AI.
The AI is talkative and provides lots of specific details from its context.
If the AI does not know the answer to a question, it truthfully says it does not know.
Okay, and this is the interesting part.
Apart from this role information, the prompt includes the current conversation that the LM is having
with me.
So as you can see here in the prompt, the LM has my first message.
Now it is going to respond.
Then I enter another message and you will see that inside the prompt it has the collection of messages.
It responds my message.
And the prompt, as you see, is storing all the messages of the conversation.
So you will immediately guess what is the problem with this?
The problem with this is the context window.
So this method is limited by the context window.
So it's not very interesting for us.
It's not solving the real problem here.
So that's why we are going to use drag instead of this a.
Temporary solutions that long chain offers us, right?
So if we dig a little bit deeper in the variable we have created in the buffer memory variable, we
can see different things like the content of this buffer memory or the variables that are included,
etc. all this functionality is provided in the documentation of launch.
Apart from this conversation buffer memory, we have another couple of very similar buffer memories.
The first one, uh, limits the number of messages that it can store, and the second one limits the
tokens, the number of tokens it can store.
So as you can see here in the second kind of buffer memory, we are saying that we only want three messages
stored in the buffer memory.
And in the third kind of memory we are telling the maximum number of tokens we want to store in the
buffer memory.
Okay.
So more than these tokens are not going to be stored.
And more than these messages here are going to be stored.
So if we ask anything about a previous message, the uh LM is not going to be able to respond.
So the last a buffer memory.
The conversation summary buffer memory is more interesting than the previous ones because instead of
storing messages, it stores a summary of the current conversation.
So this is, you know, shorter and it can be more interesting for us.
The only problem with this approach is that, okay, we have a summary of the of the conversation,
but we are going to lose the details of the conversation.
Uh, if the conversation is a long conversation.
Right.
We have a summary, but we don't know the details.
So as I was telling you, this buffer memory is that luncheon provides, uh, can be interesting, you
know, for a small exercise or for a specific, very specific case.
But in most cases, we are going to use the rack technique in order to, uh, solve this memory problem
that the foundation models have.
Okay.
So you want to know more about the buffer memory.
You can go to the long chain documentation.