Today I'm going to show you how to connect Supabase.
And PostgreSQL.
2010.
If you are building a agents in 2010, especially RAC agents, and want to give them a long term memory,
you can't use the simple memory node because it only stores short term memory for the current session.
So once the conversation ends, everything is lost.
Instead, you are going to need two essential things a memory so your agent can remember conversations
and a vector database for RAC functionality.
So today I'm going to show you how to connect both PostgreSQL and Supabase 2010.
Before we start building, let me explain what we are working with.
PostgreSQL is this powerful open source database that we are going to use to store our agents conversation
memory.
Think of it like giving a agent a brain that actually remembers what you talk about.
Yesterday by Supabase is built on top of PostgreSQL, but gives us this clean interface and vector capabilities
that make it perfect for storing document embeddings.
So by the end of this tutorial, you will have fully functional AI agent that can remember your conversations
thanks to PostgreSQL and pull relevant information from your documents.
Thanks to Supabase vector store.
So here is what we are going to accomplish today.
First, we sign up for Sparkbase account, which is completely free by the way, and you can also self-host
it.
Then we will create a new project and grab all the connection details we need.
The tricky part is getting all those connection strings because there are quite a few different URLs
and credentials involved.
I will walk you through each one step by step.
Also, we will need to add credentials for our Postgres chat memory.
And this is where most people get stuck because the connection details can be confusing.
So we need to connect and configure things like host, username, password, port, all that connection
stuff.
And the reason we need both is simple because the PostgreSQL memory node stores our conversation history.
So the end.
So the agent remembers what we talk about.
While the vector store lets us upload documents that we have the agents search through them intelligently.
Let's get started.
First I'm going to add a chat message trigger node.
Now let's add another agents.
To search for an agent.
Let's rename this guy to Rack agent.
All right, now let's connect it to some large language model.
I'm going to use OpenAI's GPT four mini.
All right.
Great.
Now I'm going to create a fresh super base account so you can follow along.
Exactly.
So head over to Supabase Superpages.com.
Click on starting project.
And click sign up.
Now create your account.
So provide email and password.
Now once you sign up you should get this email to confirm your email address.
So just simply confirm.
Now once you confirm your email you will need to create an organization.
Just leave it as personal for now since we are using the free plan.
So type personal free plan.
Click on Create organization.
Now when you create your project you will need to set a database password.
So this is super important.
Make sure you save this password somewhere safe because we are going to need it later when we connect
to PostgreSQL.
So type your password.
I'm going to copy mine and paste it into my notes.
So this password is specifically for accessing the PostgreSQL database that Supabase creates for you.
Now let's create the project.
So creating project.
So this is going to take a few minutes to set up.
So we just need to wait.
Here you can see the project status.
So it is doing behind the scenes.
It's setting up the PostgreSQL instance.
Now once your project is set up you need to go to Project Settings and click on it from the left sidebar.
Then under configuration click on database.
And now you can see connection string has moved.
And you can find Project Connect details by clicking connect in the top bar.
So you need to click on that connect button in that in the top.
And you will see this dashboard with a bunch of different API keys and URLs.
And this is where people usually get confused because there is so much information here.
But we only need specific pieces for our PostgreSQL connection.
So now let's go back to our workflow.
Now as memory for our rack agent let's add Postgres memory.
Let's create new credential.
And as you can see we need to provide host database user and password.
So now I'm going to show you where you can find these credentials.
Now we need to change the connection type to PostgreSQL.
And then scroll down To the transaction puller.
So this is where we'll find our host username password and port.
So the host tells N810 where to find your database.
The username and password authenticate us.
And the port specifies which connection method to use for the host.
We are looking for everything after dash h.
Which obviously stands for host up to dash P.
So let's copy it.
Let's go back to our editing workflow and paste it into host field.
Next we need the database and username.
So let's go to our connection string.
Here you can see that we have a dash for D which is our database Postgres.
So let's copy it.
Is the same as default and for username.
We have everything after you.
So Postgres dot and some random characters.
So let's copy it.
And paste it into the user field.
So the database stays Postgres.
That's just the default database name.
Now for the password.
This is where you use that password you created when setting up the project.
So this authenticates you as the database owner.
Now let's scroll down.
And let's find the port number.
So go back to our connection string.
And here after dash P you can see the port number.
Let's copy it.
And paste into this field.
And you should see that green check mark is telling us everything is working.
So now I'm going to rename this credentials Something tutorial.
All right.
Great.
Perfect.
Now our chat memory is connected.
You can see.
That is going to use our connected chat trigger node as the session key.
And it will store everything in a table in Supabase.
So the session key is important because it keeps different conversations separate.
Now let me quickly show you by testing this connection.
So let's open the chat.
And first actually let's go to our database.
base.
And when you go to table editor.
You can see that we don't have any tables yet.
But when I start the conversation with our agent.
I want to send a simple message.
Hello.
And now let me check the table editor and refresh it.
We should see this conversation start.
Yes.
Here we go.
So we have a new table called N810 Chat Histories with two messages.
When I click on it we have my message.
So hello.
And the agent's reply.
So hello how can I assist you today?
Perfect.
Yes, this is how all your conversations get stored based on session Session ID?
So the session ID comes from our chat trigger node.
So each conversation gets its own unique ID.
This means if you have multiple users the conversations stay separate.
Now lets add vector style.
So for this part we need to create another credential.
But this time it's for Spa based API.
So lets add tool.
For Supabase select Supabase vector store.
Create credential.
And this is where people get confused because we need two different sets of credentials.
Because we are accessing Supabase in two different ways.
So go back to your Supabase dashboard.
Go to Project settings.
Data API.
And from here you can grab your URL.
So copy it.
And paste it into the host field.
Now you need to provide service raw secret.
Go to API keys.
And reveal its service role.
Copy it.
And paste it into this field.
So the project goes into the host field.
And the service roll secret is that long token.
And the reason we need different credentials is because the vector store communicates through Supabase
rest API, while the PostgreSQL memory connects directly to the database.
So there are two different protocols.
Now let's save it.
Excellent.
Now I'll rename this credential as well.
All right.
Cool.
Now before we can actually use the vector store we need to set up the documents table in Supabase.
So this is a crucial step that allows for vector similarity search.
So in Supabase.
Go to docs.
Here in the documentation you can find the exact command we need to copy and paste to the SQL editor
in Starbase.
So scroll down, click on Quickstart for setting up your vector store.
Copy this SQL code.
Don't change anything here.
Simply copy it.
Go to the dashboard.
In the left sidebar, find SQL editor.
Click on new SQL snippet.
And here you are going to run this command to set up our documents table with Vector Store.
So paste the command here.
Click on run.
And you should see success.
No rows returned.
And then when I go to table editor we have a new table called documents.
So now let me show you how this works by adding a document to our vector store.
I'm going to use a Google Drive node to grab the documents.
So let's add Google Drive node.
Let's do not file.
And from list I'm going to choose.
A voice agent prompt framework migrate.
Now when I test this node.
To get the binary data.
So this document will become our knowledge base.
So now I will connect this to our supervised vector node.
So let's search for vector store.
Vector store.
We are going to add documents to vector store.
For the credentials.
I'm going to choose the credential I've just made the operation mode.
We have insert documents and you have to choose the table we want to push the data to.
So the table you just created in our super base vector store called documents.
So let's select documents.
Right.
Perfect.
Now let's add the document loader.
Now I need to configure the document loader and embeddings to.
So the document loader.
Will be default data loader to load data from previous step in the workflow.
So basically the document loader breaks the file into chunks.
Let's change the type of data to binary.
All right great.
And embeddings model.
We're going to use OpenAI models.
Text embedding XML.
So default model.
And basically this model converts each chunk into vectors that the large language model can search through.
All right.
Cool.
And now, when I test this step, it processes the document and splits it into chunks.
Now, as you can see, it created 13 chunks from our document.
Now back in Supabase.
We now have 13 vectorized chunks of our document with embeddings and metadata.
So the vectors are those long arrays of numbers.
That's how the AI so large language models understands and searches the content.
We also have metadata.
And here we've got access to all the content splitted into chunks.
So as you can see I can read through each of them.
Perfect.
Now, regarding metadata, we've got stuff like source and blob type, all this kind of information.
So this is where we could also add more metadata if we wanted to.
Things like document categories, dates or any other information that might help with searching.
So the metadata is really useful because it helps the AI understand context about each document chunk.
So when someone asks a question, the AI doesn't just look at the content.
It can also consider whether that content came from and what type of document it is.
So all this content comes from this file I store in my Google Drive and it has been vectorized.
Split it into chunks and added to the documents table in Supabase.
All right.
Now that we successfully vectorized the file and store the data in our super base table.
It's time to connect our agent to this vector database.
So in Superbase vector store.
Make sure you are connected to the same super base account for the operation mode.
We've got retrieve documents as tool for agent.
So basically you want to retrieve documents from vector store to be used as tool with eye nodes.
Then for the description you can say something like.
Use this to get.
Information.
About.
The AI voice agent prompt engineering framework.
All right.
So this description helps the I know when to use this tool.
And make sure you select the correct table.
So from list select documents not editing chart histories because we want to because we want to retrieve
information based on the files we vectorized.
All right.
Great.
And now let's add our embedding model.
We are going to use OpenAI's embedding model the default one.
So text embedding XML perfect.
And now let's test it first let's hit save.
Let's open chat.
And let's ask it for example.
What is the part two of the framework about?
And hit send.
As you can see.
It retrieves the relevant information from our vector database.
And is preparing the response.
So part two of the Prompt Engineering Framework focuses on defining the personality of the agent.
Here are the key components.
And in our document we have personality emotional and conversational style of the agent.
Okay great.
So the AI searches through our document chunks, finds the most relevant ones, and uses that information
to answer the question.
So if we check our chat histories table, we will see both the question.
And the IRS response.
Start here.
So our agent maintenance memory while also accessing the vector database.
So our documents table.
And this is awesome because by combining both systems we have persistent memory and intelligent document
search using similarity search.
So that's it.
The beauty of this setup is that you can add more documents, um, handle multiple conversations.
And it's all stored securely in your smart base project.
Now we know how to connect Supabase and PostgreSQL to your agents in N810.
Thanks to that, your agents can remember conversations through PostgreSQL.
And intelligently search through documents using Supabase vector database.
So we've got everything you need to build powerful agents that actually remember everything.
I hope this was helpful.
Thanks for watching and see you in the next one.