In this tutorial I will show you how to create a vector store in Supabase using Postgres.
This is a powerful way to enable AI agents to remember key details from conversations, making interactions
more natural and personalized.
For example, in a WhatsApp AI agent for customer support I created for my own company which uses RAC
and is trained on my company's knowledge base, memory allows it to go beyond just answering individual
questions.
It can remember the client's name, the previous inquiries, and the context of the conversation.
This means clients can ask follow up questions without having to repeat themselves, creating a more
human like experience.
Additionally, the agent is also able to accept voice messages from clients, analyze them, and provide
accurate responses, making the interaction even more engaging.
To start, head over to spacex.com and log in.
If you don't have an account yet, just register and create one.
Once you are in, we need to create a new project.
So click Create New project.
Give it a name and set a strong password.
You will want to save this password because you will need it later.
Leave the default settings for the database region and hit Create New project.
It will take a few moments for Supabase to set everything up.
Now that our project is created, let's move on to setting up the database for our vector store.
First we need to connect to our Supabase project in naan.
So basically because we want to vectorize our data, for example knowledge base into our vector store,
you have to drag and drop the vector store.
And choose Add documents to vector store component.
So now we have to set up credentials to connect to our super fast database.
So I'm going to create new credentials from scratch.
With new credential, then you have to go to our project in our Supabase account.
Scroll down.
You will see Project settings.
Then click on API.
And you should see Service Role.
So click reveal.
Copy it.
Go back to.
Paste it here.
Then we need to provide host.
So click on URL copy.
And paste it here then save.
And now again we will test our connection.
So credential successfully created.
So the next step is to create our vector store in database to store our data.
So let's double click on this node.
Then click on docs.
It will text us to documentation.
Scroll down click on Quick Start for setting up your vector store.
Then scroll down.
You will see a SQL code.
Just copy it.
Go back to your Supabase account.
On the left hand side you should see SQL editor.
Paste SQL code here and click run.
This process will create your vector store automatically.
Now, in order to check if we successfully created our vector store, let's click on Table Editor.
And as you can see we have a table named documents.
So here we will store our vectorized knowledge base in the form of vectors.
Now in our workflow, when you click on supervised vectors or nodes.
You will see that we are able to choose our vector store from the list.
Then we have to add option and leave default option match documents as it is.
The next step is to choose embeddings model.
So let's choose OpenAI.
And this model text embedding model is is really cost effective.
So let's choose this one.
So change the type of data to binary so it will process binary data from the previous step.
Then leave mode as it is and data format automatically detect by Mime type.
The next step is to split larger text into smaller chunks.
This is important because AI models like OpenAI's embeddings perform better when processing smaller
segments of text, ensuring more accurate embeddings and efficient processing.
So in this example, uh, I'm going to select recursive character text splitter.
This option is ideal because it recursively breaks down the text into smaller chunks while maintaining
context.
And this ensures that no important details are lost, uh, during the splitting process, and the chunks
remain manageable for embedding generation.
So usually I'm using, uh, 200 character overlap because it works perfectly for shorter documents and
keep the context intact between chunks.
So let's type 200.
Start our vectorization process.
We need a trigger to initiate the workflow and provide data that can be vectorized in supabase.
So in this example, as you can see, I'm using a Google Drive trigger to download a file of my company's
data.
My company's data.
And and this file serves as the source data which is then processed and vectorized into space.
All right.
So let's move on to the second part of the workflow.
So in this section we will focus on retrieving information from our vector store and connecting it to
our AI agent to generate responses for the user.
First, add the AI agent node.
So this node acts as a trigger for this part of the workflow.
So it starts the process when a user sends a message.
Ensuring the workflow receives their query and manages the overall logic of the interaction.
So drag this node and canvas and configure it to listen for input messages and set it up.
Set it up to with dynamic expressions for processing user data and session context.
So next uh, add the Postgres chat memory node.
So this ensures that the agent can retrieve and use previous conversation history.
So this way the agent remembers the user's name, previous inquiries, or any other contextual information.
So we need to set up the database connection to your Postgres instance and map the memory fields like
username and queries.
So here we have to set up credentials to connect with Supabase.
So it can be quite tricky.
But uh, I will guide you step by step.
So let's create credentials from scratch.
So to configure the Postgres connection go to your database dashboard and locate Project Settings.
Then click on database.
And as you can see we have all the necessary details.
So we have to just copy it and paste into the fields.
So let's copy the host, go back to an workflow.
Paste it here.
Do the same with a port.
Scroll down here.
And then the user.
And and here we have to enter the password associated with our Postgres user account.
Then click save.
Once all the fields are filled, click on Test Connection to verify the setup.
and if it's successful, your node is now connected to the Postgres database.
After that, before we add the supervised vector store node, we need to set up the vector store tool
node.
So this node is responsible for interacting with your knowledge base stored in the vector store and
preparing relevant information for your AI agent.
So by clicking on this plus button let's search Vector Store tool.
And you have to provide a name then description.
So basically it's an instruction to AI agent what to do.
So in this example.
Uh, I provided a description of this tool to query the adaptive II knowledge base.
Now add the AI model.
So I'm gonna choose open AI chat model.
You have to create a credential to connect with open AI account to to use your API keys.
I really like GPT for omni model because, uh, it's really cost effective and works really well for
this purpose.
Now we have to choose our chat model.
Let's select the same model as previously.
So ChatGPT for me.
And finally we can add our supervised vector store node to retrieve embeddings from the vector database.
So.
Sir.
And now we have to choose our table to retrieve information.
So from the list.
Select documents.
And now we have to choose our embedding model.
So this is an important step because we have to select the same embedding model as in the first part
of our workflow.
So open the I text embedding three model.
So this is how to create a supervised vector store in Nan.