What's up everybody?
It's Legion man here.
And in this lecture I am going to show you really, really quickly how you can create RAC agents by
using Postgres or PostgreSQL and Supabase vector store, so that you have your agent with memory up
and running instantly.
First of all, let's add our agent and now let us select any chat model that you like.
In this example I'm using OpenAI chat model.
And here comes the main part which is memory.
In memory we have simple memory option, but it will store in n810 only.
But we need to store our data or our chat history into our external database.
That's why we are going to use Postgres shared memory.
If you don't know what is Postgres?
Postgres is basically open source database integration that will allow you to connect your workflows
to Postgres SQL databases like Supabase Vector store.
And yes, it is obviously free since it is open source.
That's why we are going to use Postgres now in order to connect our Postgres with our super base, we
will use external tool search for super base vector store this one.
Now I know like you guys might not know what is the main difference between Postgres and super base
and why we are using both of these.
So let us go back to our blackboard to understand this concept and we will come back building this memory
or rack agent inside our n810.
Welcome back everyone.
This is my fancy drawing of agent.
Don't laugh.
Yeah.
So coming back to the point of memory, we are using Postgres now in order to store our chat histories
as well as to feedback this chat history to our agent, we need to connect this PostgreSQL node to any
external data point or data server.
In this example we are using Supabase.
Supabase is really good.
It allows you to customize your data storage as per your need.
That's why I'm using Supabase.
So to answer the question, why we are using both of them is first of all, let's say we are storing
our chat history.
For example, if I say hi, user will say hi, the I will say hello, how can I help you?
So both of these chat history will be stored to our Supabase table.
So this is one example of chat history.
Now if we want to feed this chat history back to our AI agent, we are going to connect both of them
with each other so that Postgres chat memory can send this information from our supabase table back
to our AI agent.
So this is just one use case of using Supabase and Postgres.
Second use case could be for example, you have your internal team SOP and you want to store that information
and make your AI agent as agent.
You can use that as well so you can upload your external files, PDFs, whatever you like to supabase
directly.
So in this example, our AI agent can get all of this information from our Supabase table directly.
Supabase is an external data source, and by using Postgres, we can fill in all of this information
from Supabase to our AI engine.
That's all from my side.
And let's go back to our interface.
Awesome.
We are back!
Now first of all, we need to create an account in Supabase, then feed in all of this information for
both Postgres and Supabase vector store.
So let's go to supabase.
I'm showing you everything from scratch so that you are not hanging out in any place.
Sign in or login with your Supabase account.
I'm using my GitHub.
Awesome!
So create your organization and I'm using the free plan.
Now one thing you need to remember is this password is really important.
Apart from that you can left everything as it is.
Region does not matter.
You don't need to change any advanced configuration or security option.
And let's create our project.
Note that creating a project might take some around like 2 to 3 minutes, but then you are good to go.
Yeah, so my project status is live right now and there are no security issues.
Now we need to connect our Postgres chat memory with our Supabase account.
So go to supabase and use this connect button.
If you are not able to find it, it will be somewhere here.
Click on connect.
So Postgres is an open source Postgres SQL or SQL.
So we are going to use this type of pgsql.
So scroll down and we are going to use this transaction puller.
All right.
So we need to fill in all of this information one by one.
So I will copy my host URL then my database for user I will simply copy this and paste it here.
Now remember that password.
Fill in that here.
Scroll down.
And for port it is 5432.
But here it is 6543.
After you have done that click on save.
You don't have to worry about maximum number of connection and SSL issues.
You will get this screen response if everything is okay.
Now let us name this as anytime Chat history and the context window length is fine.
So now if we test our AI agent let us disconnect this.
Let us chat with our AI agent.
We will say hi.
So it will run this two times by two times.
I will explain first time for our user message and second time for the AI message.
So if you open our Superbase now and we will have a new table of anytime chat history.
And these are the two rows that it has added.
Human.
Human said hi and AI, I said hello, how are you or how can I assist you today?
I hope this makes sense.
It is as easy as I can explain.
Cool.
So if everything is green, we will be able to store every chat session with our AI agent inside our
database, which in our example Supabase.
Now let's say if you want to convert your AI agent into a rag agent rec basically means retrieval,
augmented generation.
So you have feed in your external data, for example your PDF file, doc file or CSV file.
And you want to allow your agent to access those information.
It is known as Rec agent.
So we will connect this Supabase vector store where we will store our external database or our external
PDF files to give access to our AI agent.
So first of all, we need to create or connect our credentials.
Click on new credentials.
Yeah.
So we will need our host and our service role secret key.
So go to supabase.
Click on settings and let's go to data API.
This will be the URL and this will be your Secret service key sorry secret key.
So let's copy this paste it here.
Same goes for this one.
So I'm going to reveal this.
And I'm not going to show my secret key.
Copy this and paste it here.
Click on save.
Awesome connection.
successful for operation mode, we want to use it as rack to retrieve external documentation and use
tool for AI agent.
Since our AI agent is tool agent, we are going to use as tool for AI agent.
Now for name, let's say we want to create Legion Man, which is my company name and documents for description.
We can say it is a valuable information or valuable data storage of Legion Company.
And for tables we haven't actually created any tables.
So I'm going to show you how you can do that.
As you can see we don't have any tables.
So we are going to use sorry.
We are going to go to documentations.
And if we scroll down we have this link Supabase.
Provide a quick startup to set up our vector store.
So scroll down and we want to use this SQL.
So copy this SQL.
Go back to your Supabase instead of using text editor.
Sorry table editor we are going to use SQL editor, please set and click on run.
Yeah, it is a success but no rules written.
And this is what actually we want.
So it means that we have created the table which means success.
But the table is empty.
So if we go back to our table editor awesome.
We have a new table named documents from the dashboard.
You can upload your files, but I'm going to show you a super cool trick how you can use any ten to
upload your files to your table.
So if we pop up this yeah, click on refresh.
We should be able to see our documents.
Awesome.
And lastly we need to add our embeddings.
So if you don't know what is embedding uh it's alright.
Like if you don't know what is embedding.
Basically embedding is numerical representation of data for example images, text code.
It will convert it into numerical data so that our LLM or our large language model can understand that
data much better way.
So we are going to use OpenAI embeddings.
Again if you don't know what is embedding it's all right.
You don't need to know it.
Just add it here.
Awesome.
We are done with our super base vector store.
But as I mentioned, you can easily import your files from anytime itself.
So I'm going to show you how you can do that.
Search for super base.
And what we want to do is we want to add documents to our vector store.
Let's select our table of document and the embedding batch size.
Now let's go back and let's connect this chat trigger or chat node to our supervised vector store.
Here we need to add embeddings.
Again I'm going to use OpenAI and text splitter as well or data loader.
So we can use this default data loader so that it will automatically pick what is the data type of that
data file.
For example, it will automatically know if it is a PDF, CSV or JSON.
Yeah, but first of all, we need to change the type of data to binary because most of the time we are
going to use binary unless you have JSON.
And for more we want to load all data.
And for data format we want to automatically detect by Mimetype as well as we also need to add text
splitter.
So I will explain you what is text splitter.
Let's say you have a PDF file and it comprises of 10,000 words right.
So if you store all of those 10,000 words in just one single chunk, our LLM will hallucinate.
That's why what we want to do is we want to separate it into different text splitter, let's say 1000,
thousand, thousand in that format.
So we can use this text filter of 1000.
Same goes for chunk over length let's say 200 whatever you want to use.
But your chunk size will always differ as per your document size.
Now in order to upload our files, allow upload files, enable this.
And now if you open sorry open chat trigger, we can upload our files from here.
Awesome.
It is running successfully.
So if we go back to our Supabase click on refresh.
We have all the data that we need.
In this example, I'm using the CSV file of famous rails by count on views, likes, comment, etc.
etc. so if we go back we have all of the storage inside our supabase document table.
That's how we can upload files from anytime itself.
So let's connect back this to our AI agent.
But now we need to tell our AI agent to use Supabase vector store if needed.
So inside prompt we can tell that use the Supabase vector store to retrieve data from Vector store.
So let's start with our AI agent.
Awesome.
As you can see, it is able to detect that it needs to call this external tool of Supabase vector store.
And yeah.
Number of likes and comments in the profile of Nick.
Is this real?
This is the URL.
This is the view.
So if we check that inside our Google sheet.
Yeah same views and comments.
Comments is 97379707970.
Yeah.
So this is how we can create ranked agents very easily without any complexity.
Now this agent just copy this and go to our any workflow that we have built previously.
So instead of this qualification where we have to add all of our prompts and everything, you can just
replace this rag here, our entire agent here, and you can add all of your internal documentation criterias,
which company that you have worked previously.
It will understand all the things automatically according to your business or your company.
Alright, that's all from my side.
If you have any questions do let me know.
I'm always happy to help.
Bye bye.
Take care and I will see you in the next one.