WEBVTT

00:00.040 --> 00:05.720
In this tutorial I will show you how to create a vector store in Supabase using Postgres.

00:05.920 --> 00:12.560
This is a powerful way to enable AI agents to remember key details from conversations, making interactions

00:12.560 --> 00:14.360
more natural and personalized.

00:15.160 --> 00:22.200
For example, in a WhatsApp AI agent for customer support I created for my own company which uses RAC

00:22.400 --> 00:27.720
and is trained on my company's knowledge base, memory allows it to go beyond just answering individual

00:27.720 --> 00:28.440
questions.

00:28.600 --> 00:33.640
It can remember the client's name, the previous inquiries, and the context of the conversation.

00:33.920 --> 00:39.920
This means clients can ask follow up questions without having to repeat themselves, creating a more

00:39.920 --> 00:41.320
human like experience.

00:41.840 --> 00:48.160
Additionally, the agent is also able to accept voice messages from clients, analyze them, and provide

00:48.160 --> 00:52.040
accurate responses, making the interaction even more engaging.

00:52.960 --> 00:56.840
To start, head over to spacex.com and log in.

00:56.880 --> 00:59.920
If you don't have an account yet, just register and create one.

01:01.080 --> 01:03.790
Once you are in, we need to create a new project.

01:04.350 --> 01:06.070
So click Create New project.

01:07.990 --> 01:10.470
Give it a name and set a strong password.

01:10.990 --> 01:13.830
You will want to save this password because you will need it later.

01:14.510 --> 01:18.830
Leave the default settings for the database region and hit Create New project.

01:19.190 --> 01:22.350
It will take a few moments for Supabase to set everything up.

01:23.310 --> 01:28.950
Now that our project is created, let's move on to setting up the database for our vector store.

01:29.390 --> 01:32.710
First we need to connect to our Supabase project in naan.

01:33.150 --> 01:39.630
So basically because we want to vectorize our data, for example knowledge base into our vector store,

01:39.830 --> 01:43.350
you have to drag and drop the vector store.

01:48.310 --> 01:51.750
And choose Add documents to vector store component.

01:52.630 --> 01:57.670
So now we have to set up credentials to connect to our super fast database.

01:58.270 --> 02:02.150
So I'm going to create new credentials from scratch.

02:04.830 --> 02:12.230
With new credential, then you have to go to our project in our Supabase account.

02:16.630 --> 02:17.310
Scroll down.

02:18.670 --> 02:20.310
You will see Project settings.

02:22.630 --> 02:24.510
Then click on API.

02:27.310 --> 02:30.070
And you should see Service Role.

02:30.110 --> 02:31.190
So click reveal.

02:32.870 --> 02:33.550
Copy it.

02:34.790 --> 02:35.390
Go back to.

02:37.990 --> 02:38.750
Paste it here.

02:41.110 --> 02:42.670
Then we need to provide host.

02:43.950 --> 02:48.670
So click on URL copy.

02:51.390 --> 02:54.710
And paste it here then save.

02:57.110 --> 02:59.350
And now again we will test our connection.

03:00.670 --> 03:03.190
So credential successfully created.

03:03.230 --> 03:08.900
So the next step is to create our vector store in database to store our data.

03:09.580 --> 03:11.300
So let's double click on this node.

03:13.180 --> 03:14.420
Then click on docs.

03:15.700 --> 03:18.780
It will text us to documentation.

03:19.420 --> 03:23.980
Scroll down click on Quick Start for setting up your vector store.

03:26.460 --> 03:27.500
Then scroll down.

03:28.380 --> 03:30.100
You will see a SQL code.

03:32.300 --> 03:33.140
Just copy it.

03:33.940 --> 03:35.940
Go back to your Supabase account.

03:37.660 --> 03:40.820
On the left hand side you should see SQL editor.

03:43.460 --> 03:46.780
Paste SQL code here and click run.

03:49.420 --> 03:52.420
This process will create your vector store automatically.

03:53.980 --> 04:00.220
Now, in order to check if we successfully created our vector store, let's click on Table Editor.

04:02.420 --> 04:06.020
And as you can see we have a table named documents.

04:07.740 --> 04:13.660
So here we will store our vectorized knowledge base in the form of vectors.

04:14.180 --> 04:20.140
Now in our workflow, when you click on supervised vectors or nodes.

04:22.620 --> 04:27.500
You will see that we are able to choose our vector store from the list.

04:30.900 --> 04:37.740
Then we have to add option and leave default option match documents as it is.

04:40.980 --> 04:45.260
The next step is to choose embeddings model.

04:45.620 --> 04:48.500
So let's choose OpenAI.

04:53.340 --> 04:59.100
And this model text embedding model is is really cost effective.

04:59.580 --> 05:01.500
So let's choose this one.

05:07.260 --> 05:14.490
So change the type of data to binary so it will process binary data from the previous step.

05:17.410 --> 05:23.890
Then leave mode as it is and data format automatically detect by Mime type.

05:26.770 --> 05:30.050
The next step is to split larger text into smaller chunks.

05:30.490 --> 05:36.850
This is important because AI models like OpenAI's embeddings perform better when processing smaller

05:36.850 --> 05:42.210
segments of text, ensuring more accurate embeddings and efficient processing.

05:42.970 --> 05:51.410
So in this example, uh, I'm going to select recursive character text splitter.

05:52.330 --> 05:58.730
This option is ideal because it recursively breaks down the text into smaller chunks while maintaining

05:58.730 --> 05:59.450
context.

06:00.010 --> 06:06.970
And this ensures that no important details are lost, uh, during the splitting process, and the chunks

06:06.970 --> 06:09.490
remain manageable for embedding generation.

06:12.450 --> 06:19.720
So usually I'm using, uh, 200 character overlap because it works perfectly for shorter documents and

06:20.360 --> 06:22.760
keep the context intact between chunks.

06:24.560 --> 06:26.240
So let's type 200.

06:28.280 --> 06:30.200
Start our vectorization process.

06:30.520 --> 06:37.840
We need a trigger to initiate the workflow and provide data that can be vectorized in supabase.

06:38.680 --> 06:48.440
So in this example, as you can see, I'm using a Google Drive trigger to download a file of my company's

06:48.440 --> 06:48.920
data.

06:48.960 --> 06:50.080
My company's data.

06:50.560 --> 06:57.720
And and this file serves as the source data which is then processed and vectorized into space.

07:01.240 --> 07:01.720
All right.

07:01.720 --> 07:04.360
So let's move on to the second part of the workflow.

07:08.120 --> 07:15.120
So in this section we will focus on retrieving information from our vector store and connecting it to

07:15.160 --> 07:18.440
our AI agent to generate responses for the user.

07:20.200 --> 07:23.080
First, add the AI agent node.

07:23.880 --> 07:29.920
So this node acts as a trigger for this part of the workflow.

07:30.360 --> 07:34.640
So it starts the process when a user sends a message.

07:35.320 --> 07:41.680
Ensuring the workflow receives their query and manages the overall logic of the interaction.

07:42.400 --> 07:54.880
So drag this node and canvas and configure it to listen for input messages and set it up.

07:54.920 --> 08:01.840
Set it up to with dynamic expressions for processing user data and session context.

08:04.520 --> 08:08.000
So next uh, add the Postgres chat memory node.

08:08.520 --> 08:15.160
So this ensures that the agent can retrieve and use previous conversation history.

08:15.560 --> 08:23.750
So this way the agent remembers the user's name, previous inquiries, or any other contextual information.

08:24.310 --> 08:31.790
So we need to set up the database connection to your Postgres instance and map the memory fields like

08:32.150 --> 08:33.910
username and queries.

08:40.550 --> 08:45.910
So here we have to set up credentials to connect with Supabase.

08:46.990 --> 08:48.350
So it can be quite tricky.

08:48.350 --> 08:51.590
But uh, I will guide you step by step.

08:53.910 --> 08:55.870
So let's create credentials from scratch.

08:59.230 --> 09:10.350
So to configure the Postgres connection go to your database dashboard and locate Project Settings.

09:11.830 --> 09:13.350
Then click on database.

09:14.990 --> 09:18.230
And as you can see we have all the necessary details.

09:19.100 --> 09:24.580
So we have to just copy it and paste into the fields.

09:25.180 --> 09:30.900
So let's copy the host, go back to an workflow.

09:32.100 --> 09:32.860
Paste it here.

09:35.140 --> 09:38.220
Do the same with a port.

09:42.740 --> 09:43.620
Scroll down here.

09:50.100 --> 09:51.780
And then the user.

10:01.420 --> 10:08.260
And and here we have to enter the password associated with our Postgres user account.

10:13.300 --> 10:14.180
Then click save.

10:16.220 --> 10:20.620
Once all the fields are filled, click on Test Connection to verify the setup.

10:21.140 --> 10:25.300
and if it's successful, your node is now connected to the Postgres database.

10:33.740 --> 10:41.580
After that, before we add the supervised vector store node, we need to set up the vector store tool

10:41.580 --> 10:42.020
node.

10:42.460 --> 10:49.780
So this node is responsible for interacting with your knowledge base stored in the vector store and

10:49.780 --> 10:52.460
preparing relevant information for your AI agent.

10:54.460 --> 11:00.500
So by clicking on this plus button let's search Vector Store tool.

11:06.340 --> 11:12.060
And you have to provide a name then description.

11:12.060 --> 11:18.620
So basically it's an instruction to AI agent what to do.

11:18.660 --> 11:20.620
So in this example.

11:23.170 --> 11:28.610
Uh, I provided a description of this tool to query the adaptive II knowledge base.

11:31.970 --> 11:34.210
Now add the AI model.

11:36.330 --> 11:39.050
So I'm gonna choose open AI chat model.

11:42.650 --> 11:49.730
You have to create a credential to connect with open AI account to to use your API keys.

11:51.610 --> 11:57.930
I really like GPT for omni model because, uh, it's really cost effective and works really well for

11:57.930 --> 11:59.010
this purpose.

12:00.410 --> 12:02.690
Now we have to choose our chat model.

12:04.410 --> 12:06.930
Let's select the same model as previously.

12:06.930 --> 12:09.610
So ChatGPT for me.

12:12.930 --> 12:22.010
And finally we can add our supervised vector store node to retrieve embeddings from the vector database.

12:28.130 --> 12:28.450
So.

12:30.570 --> 12:31.010
Sir.

12:32.890 --> 12:38.850
And now we have to choose our table to retrieve information.

12:38.850 --> 12:41.530
So from the list.

12:45.490 --> 12:46.690
Select documents.

12:51.290 --> 12:56.690
And now we have to choose our embedding model.

12:56.690 --> 13:04.450
So this is an important step because we have to select the same embedding model as in the first part

13:04.450 --> 13:05.530
of our workflow.

13:08.290 --> 13:12.770
So open the I text embedding three model.

13:22.970 --> 13:27.650
So this is how to create a supervised vector store in Nan.
