WEBVTT

00:00.360 --> 00:03.720
Today I'm going to show you how to connect Supabase.

00:06.080 --> 00:07.200
And PostgreSQL.

00:08.440 --> 00:09.280
2010.

00:09.760 --> 00:16.680
If you are building a agents in 2010, especially RAC agents, and want to give them a long term memory,

00:17.080 --> 00:24.000
you can't use the simple memory node because it only stores short term memory for the current session.

00:24.320 --> 00:27.840
So once the conversation ends, everything is lost.

00:28.240 --> 00:36.040
Instead, you are going to need two essential things a memory so your agent can remember conversations

00:36.600 --> 00:40.880
and a vector database for RAC functionality.

00:41.280 --> 00:46.840
So today I'm going to show you how to connect both PostgreSQL and Supabase 2010.

00:47.520 --> 00:51.600
Before we start building, let me explain what we are working with.

00:51.960 --> 01:00.320
PostgreSQL is this powerful open source database that we are going to use to store our agents conversation

01:00.320 --> 01:00.920
memory.

01:01.600 --> 01:09.600
Think of it like giving a agent a brain that actually remembers what you talk about.

01:09.600 --> 01:20.120
Yesterday by Supabase is built on top of PostgreSQL, but gives us this clean interface and vector capabilities

01:20.120 --> 01:24.440
that make it perfect for storing document embeddings.

01:24.680 --> 01:31.720
So by the end of this tutorial, you will have fully functional AI agent that can remember your conversations

01:31.960 --> 01:38.120
thanks to PostgreSQL and pull relevant information from your documents.

01:38.560 --> 01:40.360
Thanks to Supabase vector store.

01:40.760 --> 01:43.040
So here is what we are going to accomplish today.

01:43.320 --> 01:50.480
First, we sign up for Sparkbase account, which is completely free by the way, and you can also self-host

01:50.520 --> 01:50.840
it.

01:51.480 --> 01:55.600
Then we will create a new project and grab all the connection details we need.

01:56.360 --> 02:02.760
The tricky part is getting all those connection strings because there are quite a few different URLs

02:02.760 --> 02:04.080
and credentials involved.

02:04.520 --> 02:06.960
I will walk you through each one step by step.

02:08.360 --> 02:13.680
Also, we will need to add credentials for our Postgres chat memory.

02:17.120 --> 02:23.200
And this is where most people get stuck because the connection details can be confusing.

02:24.320 --> 02:30.960
So we need to connect and configure things like host, username, password, port, all that connection

02:30.960 --> 02:31.440
stuff.

02:32.840 --> 02:39.680
And the reason we need both is simple because the PostgreSQL memory node stores our conversation history.

02:39.920 --> 02:40.640
So the end.

02:40.680 --> 02:43.600
So the agent remembers what we talk about.

02:43.880 --> 02:52.000
While the vector store lets us upload documents that we have the agents search through them intelligently.

02:52.840 --> 02:53.960
Let's get started.

02:54.200 --> 02:59.040
First I'm going to add a chat message trigger node.

03:03.870 --> 03:06.350
Now let's add another agents.

03:10.150 --> 03:11.590
To search for an agent.

03:14.990 --> 03:19.190
Let's rename this guy to Rack agent.

03:25.310 --> 03:30.230
All right, now let's connect it to some large language model.

03:30.430 --> 03:36.230
I'm going to use OpenAI's GPT four mini.

03:50.470 --> 03:50.830
All right.

03:50.830 --> 03:51.270
Great.

03:53.710 --> 03:57.430
Now I'm going to create a fresh super base account so you can follow along.

03:57.470 --> 03:58.150
Exactly.

03:59.350 --> 04:02.590
So head over to Supabase Superpages.com.

04:04.950 --> 04:06.510
Click on starting project.

04:09.830 --> 04:10.990
And click sign up.

04:15.750 --> 04:17.110
Now create your account.

04:17.670 --> 04:19.230
So provide email and password.

04:20.470 --> 04:25.710
Now once you sign up you should get this email to confirm your email address.

04:26.550 --> 04:27.830
So just simply confirm.

04:28.950 --> 04:32.470
Now once you confirm your email you will need to create an organization.

04:33.310 --> 04:38.110
Just leave it as personal for now since we are using the free plan.

04:38.710 --> 04:41.230
So type personal free plan.

04:41.990 --> 04:43.470
Click on Create organization.

04:46.150 --> 04:51.150
Now when you create your project you will need to set a database password.

04:51.510 --> 04:52.710
So this is super important.

04:52.710 --> 04:59.030
Make sure you save this password somewhere safe because we are going to need it later when we connect

04:59.030 --> 05:00.150
to PostgreSQL.

05:03.910 --> 05:05.150
So type your password.

05:10.150 --> 05:13.870
I'm going to copy mine and paste it into my notes.

05:14.590 --> 05:21.230
So this password is specifically for accessing the PostgreSQL database that Supabase creates for you.

05:22.230 --> 05:23.590
Now let's create the project.

05:23.590 --> 05:24.870
So creating project.

05:25.710 --> 05:28.230
So this is going to take a few minutes to set up.

05:28.430 --> 05:29.950
So we just need to wait.

05:32.150 --> 05:33.950
Here you can see the project status.

05:36.150 --> 05:37.790
So it is doing behind the scenes.

05:37.790 --> 05:41.470
It's setting up the PostgreSQL instance.

05:42.150 --> 05:49.470
Now once your project is set up you need to go to Project Settings and click on it from the left sidebar.

05:52.190 --> 05:55.230
Then under configuration click on database.

05:58.870 --> 06:01.190
And now you can see connection string has moved.

06:01.350 --> 06:04.830
And you can find Project Connect details by clicking connect in the top bar.

06:05.190 --> 06:08.630
So you need to click on that connect button in that in the top.

06:13.710 --> 06:17.830
And you will see this dashboard with a bunch of different API keys and URLs.

06:17.990 --> 06:22.550
And this is where people usually get confused because there is so much information here.

06:23.070 --> 06:26.910
But we only need specific pieces for our PostgreSQL connection.

06:27.550 --> 06:29.910
So now let's go back to our workflow.

06:30.470 --> 06:36.030
Now as memory for our rack agent let's add Postgres memory.

06:39.190 --> 06:40.670
Let's create new credential.

06:43.550 --> 06:48.230
And as you can see we need to provide host database user and password.

06:49.070 --> 06:52.030
So now I'm going to show you where you can find these credentials.

06:52.550 --> 06:57.470
Now we need to change the connection type to PostgreSQL.

07:00.670 --> 07:04.500
And then scroll down To the transaction puller.

07:05.140 --> 07:09.900
So this is where we'll find our host username password and port.

07:10.180 --> 07:13.340
So the host tells N810 where to find your database.

07:13.540 --> 07:16.900
The username and password authenticate us.

07:16.940 --> 07:21.500
And the port specifies which connection method to use for the host.

07:21.500 --> 07:25.260
We are looking for everything after dash h.

07:27.300 --> 07:33.060
Which obviously stands for host up to dash P.

07:33.940 --> 07:35.060
So let's copy it.

07:37.620 --> 07:43.260
Let's go back to our editing workflow and paste it into host field.

07:44.100 --> 07:47.300
Next we need the database and username.

07:47.540 --> 07:49.580
So let's go to our connection string.

07:51.700 --> 08:00.220
Here you can see that we have a dash for D which is our database Postgres.

08:00.220 --> 08:01.140
So let's copy it.

08:05.620 --> 08:08.380
Is the same as default and for username.

08:14.740 --> 08:16.980
We have everything after you.

08:17.020 --> 08:20.620
So Postgres dot and some random characters.

08:21.620 --> 08:22.700
So let's copy it.

08:25.100 --> 08:27.620
And paste it into the user field.

08:27.900 --> 08:30.100
So the database stays Postgres.

08:30.500 --> 08:32.820
That's just the default database name.

08:33.500 --> 08:34.660
Now for the password.

08:35.140 --> 08:39.580
This is where you use that password you created when setting up the project.

08:39.740 --> 08:42.580
So this authenticates you as the database owner.

08:43.340 --> 08:44.420
Now let's scroll down.

08:49.140 --> 08:50.660
And let's find the port number.

08:52.460 --> 08:54.460
So go back to our connection string.

08:58.220 --> 09:01.500
And here after dash P you can see the port number.

09:01.820 --> 09:02.700
Let's copy it.

09:06.420 --> 09:07.900
And paste into this field.

09:11.020 --> 09:15.060
And you should see that green check mark is telling us everything is working.

09:15.420 --> 09:20.620
So now I'm going to rename this credentials Something tutorial.

09:24.500 --> 09:24.900
All right.

09:24.900 --> 09:25.380
Great.

09:26.820 --> 09:27.580
Perfect.

09:27.820 --> 09:29.700
Now our chat memory is connected.

09:30.500 --> 09:31.380
You can see.

09:33.820 --> 09:39.500
That is going to use our connected chat trigger node as the session key.

09:39.980 --> 09:43.460
And it will store everything in a table in Supabase.

09:43.860 --> 09:49.420
So the session key is important because it keeps different conversations separate.

09:49.940 --> 09:52.980
Now let me quickly show you by testing this connection.

09:53.540 --> 09:54.780
So let's open the chat.

10:00.140 --> 10:03.740
And first actually let's go to our database.

10:03.740 --> 10:03.820
base.

10:04.420 --> 10:08.340
And when you go to table editor.

10:11.140 --> 10:13.300
You can see that we don't have any tables yet.

10:14.300 --> 10:16.940
But when I start the conversation with our agent.

10:22.820 --> 10:24.380
I want to send a simple message.

10:24.380 --> 10:24.860
Hello.

10:26.260 --> 10:32.900
And now let me check the table editor and refresh it.

10:37.740 --> 10:39.900
We should see this conversation start.

10:40.420 --> 10:40.700
Yes.

10:40.700 --> 10:41.220
Here we go.

10:41.220 --> 10:47.100
So we have a new table called N810 Chat Histories with two messages.

10:47.100 --> 10:50.180
When I click on it we have my message.

10:50.380 --> 10:51.100
So hello.

10:52.900 --> 10:54.340
And the agent's reply.

10:56.900 --> 10:58.620
So hello how can I assist you today?

10:59.060 --> 10:59.700
Perfect.

10:59.940 --> 11:05.340
Yes, this is how all your conversations get stored based on session Session ID?

11:06.300 --> 11:09.180
So the session ID comes from our chat trigger node.

11:10.260 --> 11:13.780
So each conversation gets its own unique ID.

11:13.820 --> 11:18.540
This means if you have multiple users the conversations stay separate.

11:18.820 --> 11:20.660
Now lets add vector style.

11:20.980 --> 11:23.700
So for this part we need to create another credential.

11:23.900 --> 11:26.860
But this time it's for Spa based API.

11:27.540 --> 11:28.660
So lets add tool.

11:31.100 --> 11:34.780
For Supabase select Supabase vector store.

11:37.540 --> 11:38.740
Create credential.

11:40.420 --> 11:44.980
And this is where people get confused because we need two different sets of credentials.

11:44.980 --> 11:47.580
Because we are accessing Supabase in two different ways.

11:47.980 --> 11:50.020
So go back to your Supabase dashboard.

11:53.900 --> 11:55.780
Go to Project settings.

12:00.420 --> 12:01.340
Data API.

12:04.850 --> 12:06.970
And from here you can grab your URL.

12:07.450 --> 12:08.330
So copy it.

12:11.930 --> 12:13.930
And paste it into the host field.

12:17.970 --> 12:20.010
Now you need to provide service raw secret.

12:25.050 --> 12:26.370
Go to API keys.

12:30.970 --> 12:32.570
And reveal its service role.

12:34.250 --> 12:35.050
Copy it.

12:37.290 --> 12:38.770
And paste it into this field.

12:39.490 --> 12:42.730
So the project goes into the host field.

12:43.210 --> 12:45.450
And the service roll secret is that long token.

12:45.930 --> 12:52.050
And the reason we need different credentials is because the vector store communicates through Supabase

12:52.090 --> 12:59.210
rest API, while the PostgreSQL memory connects directly to the database.

12:59.330 --> 13:01.010
So there are two different protocols.

13:01.570 --> 13:02.530
Now let's save it.

13:04.330 --> 13:05.130
Excellent.

13:06.090 --> 13:08.250
Now I'll rename this credential as well.

13:18.450 --> 13:18.810
All right.

13:18.810 --> 13:19.170
Cool.

13:19.970 --> 13:25.610
Now before we can actually use the vector store we need to set up the documents table in Supabase.

13:25.930 --> 13:31.210
So this is a crucial step that allows for vector similarity search.

13:31.770 --> 13:32.810
So in Supabase.

13:38.610 --> 13:39.610
Go to docs.

13:40.330 --> 13:47.090
Here in the documentation you can find the exact command we need to copy and paste to the SQL editor

13:47.090 --> 13:47.890
in Starbase.

13:48.410 --> 13:53.410
So scroll down, click on Quickstart for setting up your vector store.

13:59.570 --> 14:01.330
Copy this SQL code.

14:01.330 --> 14:02.650
Don't change anything here.

14:05.410 --> 14:06.490
Simply copy it.

14:08.250 --> 14:10.050
Go to the dashboard.

14:13.970 --> 14:17.530
In the left sidebar, find SQL editor.

14:18.450 --> 14:20.330
Click on new SQL snippet.

14:24.010 --> 14:29.650
And here you are going to run this command to set up our documents table with Vector Store.

14:30.410 --> 14:31.650
So paste the command here.

14:34.410 --> 14:35.250
Click on run.

14:38.850 --> 14:40.410
And you should see success.

14:40.610 --> 14:41.690
No rows returned.

14:42.490 --> 14:49.850
And then when I go to table editor we have a new table called documents.

14:50.330 --> 14:54.410
So now let me show you how this works by adding a document to our vector store.

14:55.210 --> 14:58.450
I'm going to use a Google Drive node to grab the documents.

14:59.050 --> 15:02.370
So let's add Google Drive node.

15:09.770 --> 15:10.850
Let's do not file.

15:12.250 --> 15:14.010
And from list I'm going to choose.

15:17.490 --> 15:21.730
A voice agent prompt framework migrate.

15:22.770 --> 15:24.170
Now when I test this node.

15:29.130 --> 15:30.330
To get the binary data.

15:30.330 --> 15:32.610
So this document will become our knowledge base.

15:33.530 --> 15:36.890
So now I will connect this to our supervised vector node.

15:37.730 --> 15:39.290
So let's search for vector store.

15:44.370 --> 15:45.010
Vector store.

15:45.970 --> 15:47.930
We are going to add documents to vector store.

15:51.090 --> 15:52.250
For the credentials.

15:52.610 --> 15:56.850
I'm going to choose the credential I've just made the operation mode.

15:56.850 --> 16:03.570
We have insert documents and you have to choose the table we want to push the data to.

16:04.610 --> 16:09.250
So the table you just created in our super base vector store called documents.

16:09.890 --> 16:11.170
So let's select documents.

16:12.810 --> 16:13.050
Right.

16:13.050 --> 16:13.610
Perfect.

16:14.290 --> 16:16.730
Now let's add the document loader.

16:17.850 --> 16:22.250
Now I need to configure the document loader and embeddings to.

16:22.930 --> 16:24.250
So the document loader.

16:26.290 --> 16:30.170
Will be default data loader to load data from previous step in the workflow.

16:32.490 --> 16:35.970
So basically the document loader breaks the file into chunks.

16:38.570 --> 16:41.530
Let's change the type of data to binary.

16:43.250 --> 16:44.050
All right great.

16:44.930 --> 16:46.050
And embeddings model.

16:49.730 --> 16:51.890
We're going to use OpenAI models.

16:54.730 --> 16:56.130
Text embedding XML.

16:56.130 --> 16:57.050
So default model.

16:59.250 --> 17:06.090
And basically this model converts each chunk into vectors that the large language model can search through.

17:07.880 --> 17:08.280
All right.

17:08.280 --> 17:08.680
Cool.

17:11.600 --> 17:18.840
And now, when I test this step, it processes the document and splits it into chunks.

17:20.840 --> 17:26.000
Now, as you can see, it created 13 chunks from our document.

17:27.000 --> 17:28.720
Now back in Supabase.

17:31.640 --> 17:37.760
We now have 13 vectorized chunks of our document with embeddings and metadata.

17:38.200 --> 17:42.680
So the vectors are those long arrays of numbers.

17:43.000 --> 17:48.800
That's how the AI so large language models understands and searches the content.

17:50.400 --> 17:51.680
We also have metadata.

17:53.600 --> 17:57.760
And here we've got access to all the content splitted into chunks.

18:00.600 --> 18:03.320
So as you can see I can read through each of them.

18:06.840 --> 18:07.440
Perfect.

18:08.080 --> 18:17.320
Now, regarding metadata, we've got stuff like source and blob type, all this kind of information.

18:17.320 --> 18:22.280
So this is where we could also add more metadata if we wanted to.

18:22.520 --> 18:27.880
Things like document categories, dates or any other information that might help with searching.

18:28.560 --> 18:34.680
So the metadata is really useful because it helps the AI understand context about each document chunk.

18:35.280 --> 18:41.000
So when someone asks a question, the AI doesn't just look at the content.

18:41.720 --> 18:46.840
It can also consider whether that content came from and what type of document it is.

18:48.280 --> 18:56.920
So all this content comes from this file I store in my Google Drive and it has been vectorized.

18:57.360 --> 19:01.440
Split it into chunks and added to the documents table in Supabase.

19:03.040 --> 19:03.760
All right.

19:04.080 --> 19:10.960
Now that we successfully vectorized the file and store the data in our super base table.

19:11.280 --> 19:14.160
It's time to connect our agent to this vector database.

19:14.640 --> 19:16.200
So in Superbase vector store.

19:19.440 --> 19:24.280
Make sure you are connected to the same super base account for the operation mode.

19:24.600 --> 19:28.000
We've got retrieve documents as tool for agent.

19:28.800 --> 19:34.080
So basically you want to retrieve documents from vector store to be used as tool with eye nodes.

19:35.600 --> 19:38.920
Then for the description you can say something like.

19:41.280 --> 19:43.280
Use this to get.

19:45.560 --> 19:46.440
Information.

19:49.080 --> 19:49.920
About.

19:53.600 --> 19:56.800
The AI voice agent prompt engineering framework.

20:16.080 --> 20:16.720
All right.

20:17.840 --> 20:21.600
So this description helps the I know when to use this tool.

20:22.360 --> 20:24.760
And make sure you select the correct table.

20:25.200 --> 20:33.320
So from list select documents not editing chart histories because we want to because we want to retrieve

20:33.320 --> 20:37.760
information based on the files we vectorized.

20:39.480 --> 20:39.840
All right.

20:39.840 --> 20:40.280
Great.

20:40.800 --> 20:43.680
And now let's add our embedding model.

20:45.480 --> 20:49.800
We are going to use OpenAI's embedding model the default one.

20:50.160 --> 20:53.040
So text embedding XML perfect.

20:54.280 --> 20:57.720
And now let's test it first let's hit save.

20:59.040 --> 21:00.040
Let's open chat.

21:02.560 --> 21:05.320
And let's ask it for example.

21:11.270 --> 21:18.470
What is the part two of the framework about?

21:20.670 --> 21:21.550
And hit send.

21:26.150 --> 21:27.030
As you can see.

21:29.390 --> 21:32.430
It retrieves the relevant information from our vector database.

21:35.670 --> 21:37.030
And is preparing the response.

21:37.630 --> 21:42.550
So part two of the Prompt Engineering Framework focuses on defining the personality of the agent.

21:42.830 --> 21:44.110
Here are the key components.

21:44.870 --> 21:51.430
And in our document we have personality emotional and conversational style of the agent.

21:51.750 --> 21:52.510
Okay great.

21:52.910 --> 21:59.430
So the AI searches through our document chunks, finds the most relevant ones, and uses that information

21:59.430 --> 22:00.630
to answer the question.

22:01.470 --> 22:06.710
So if we check our chat histories table, we will see both the question.

22:08.830 --> 22:10.150
And the IRS response.

22:10.390 --> 22:11.110
Start here.

22:12.390 --> 22:17.110
So our agent maintenance memory while also accessing the vector database.

22:17.630 --> 22:19.110
So our documents table.

22:19.710 --> 22:26.670
And this is awesome because by combining both systems we have persistent memory and intelligent document

22:26.670 --> 22:29.230
search using similarity search.

22:29.870 --> 22:30.790
So that's it.

22:30.910 --> 22:36.590
The beauty of this setup is that you can add more documents, um, handle multiple conversations.

22:36.990 --> 22:40.070
And it's all stored securely in your smart base project.

22:40.870 --> 22:46.070
Now we know how to connect Supabase and PostgreSQL to your agents in N810.

22:46.750 --> 22:51.750
Thanks to that, your agents can remember conversations through PostgreSQL.

22:54.190 --> 22:59.230
And intelligently search through documents using Supabase vector database.

23:00.390 --> 23:05.310
So we've got everything you need to build powerful agents that actually remember everything.

23:05.750 --> 23:07.270
I hope this was helpful.

23:07.470 --> 23:09.230
Thanks for watching and see you in the next one.
