How to Set up Supabase and Postgres for RAG Agent with Memory in n8n (2025)

Dr. Violet Howard shows how to set up Supabase and Postgres in n8n to build a RAG agent with persistent chat memory and vector storage. The tutorial covers creating a Supabase project, configuring the Postgres chat-memory node, creating a documents table for embeddings, and ingesting a Google Doc to answer queries like "what brake services are offered at the body shop?"
Chapters
So today I'm going to be showing you guys how to connect PostgreSQL and Supabase to N8n. So what I'm going to be doing today is walking through signing up for an account, creating a project, and then connecting them both to N8n so you guys can follow every step of the way. But real quick, Postgres is an open-source relational database management system that you're able to use plugins like pgvector if you want vector similarity search. In this case, we're just going to be using Postgres as the memory for our agent, and then Supabase is a backend as a service that's kind of built on top of Postgres. And in today's example, we're going to be using that as the vector database. but don't wanna waste any time. Here we are in n8n, and what we know we're gonna do here for our agent is give it memory with Postgres and access to a vector database in Supabase. So for memory, I'm gonna click on this plus and click on Postgres chat memory, and then we'll set up this credential. And then over here, we wanna click on the plus for tool. We'll grab a Supabase vector store node, and then this is where we'll hook up our Supabase credential. So whenever we need to connect to these third-party services, what we have to do is come into the node, go to our credential, and then we want to create a new one. And then we have all this stuff to configure, like our host, our username, our password, our port, all this kind of stuff. So we have to hop into Supabase first, create an account, create a new project, and then we'll be able to access all this information to plug in. So here we are in Supabase. I'm gonna be creating a new account like I said, just so we can walk through all of this step by step for you guys. So first thing you wanna do is sign up for a new account. So I just got my confirmation email, so I'm gonna go ahead and confirm. Once you do that, it's gonna have you create a new organization, and then within that, we create a new project. So I'm just gonna leave everything as is for now. It's gonna be personal, it's gonna be free, and I'll hit create organization. And then from here, we are creating a new project. So I'm gonna leave everything once again as is. This is the organization we're creating the project in. Here's the project name, and then you need to create a password, and you're gonna have to remember this password to hook up to our Supabase node later. So I've entered my password. I'm gonna copy this because like I said, you wanna save this so you can enter it later, and then we'll click Create New Project. This is going to be launching up our project, and this may take a few minutes, so just have to be patient here. As you can see, we're in the screen. It's gonna say Setting Up Project. So we pretty much are just gonna wait until our project's been set up. So while this is happening, we can see that there's already some stuff that may look a little confusing. We've got project API keys with a service role secret. We have configuration with a different URL and some sort of JWT secret. So I'm gonna show you guys how you need to access what it is and plug it into the right places in N8N. But as you can see, we got launched to a different screen. The project status is still being launched, so just gonna wait for it to be complete. So everything just got set up. We're now good to connect to N8N. And what you wanna do is typically you'd come down to product settings and you click on database, and this is where everything would be to connect. But it says connection string has moved. So as you can see, there's a little button up here called connect. So we're gonna click on this, and now this is where we're grabbing the information that we need for Postgres. So this is where it gets a little confusing because there's a lot of stuff that we need for Postgres. We need to get a host, username, our password from earlier when we set up the project, and then a port. So all we're looking for are those 4 things, but we need to find them in here. So what I'm gonna do is change the type to PostgreSQL, and then I'm gonna go down to the transaction pooler, and this is where we're gonna find the things that we need. The first thing that we're looking for is the host, which if you set it up just like me, it's gonna be after the -h. So it's gonna be aws, and then we have our region.pooler.supabase.com. .com. So we're gonna grab that, copy it, and then we're gonna paste that into the host section right there. So that's what it should look like for host. Now we have a database and a username to set up. So if we go back into that Supabase page, we can see we have a D and a U. So the D is gonna stay as Postgres, but for user, we're going to grab everything after the U, which is gonna be postgres.com, and then these different characters. So I'm gonna paste that in here under the user. And for the password, this is where you're gonna paste in the password that you use to set up your Supabase project. And then finally at the bottom, we're looking for a port, which is by default 5342. But in this case, we're going to grab the port from the transaction pooler right here, which is following the lowercase p. So we have 6543. I'm going to copy that, paste that into here as the port, and then we'll hit save. And we'll see if we got connection tested successfully. There we go, we got green. And then I'm just going to rename this so I can keep it organized. So there we go, we've connected to Postgres as our chat memory. We can see that it is going to be using the connected chat trigger node. That's how it's going to be using the key to store this information. And it's going to be storing it in a table in Supabase called n8n chat histories. So real quick, I'm going to talk to the agent. I'm just going to disconnect the Supabase so we don't get any errors. So now when I send off, hello AI agent, it's going to respond to us with something like, hey, how can I help you today? Hello, how can I assist you? And now you can see that there were two things stored in our Postgres chat memory. So we'll switch over to Supabase. And now we're going to come up here in the left and go to table editor. We can see we have a new table that we just created called n8n chat histories. And then we have two messages in here. So the first one, as you can see, was a human type and the content was, hello AI agent, which is what we said to the AI agent. And then the second one was a type AI, and this is the AI's response to us. So it said, hello, how can I assist you today? So this is where all of your chats are going to be stored based on the session ID. And just once again, this session ID is coming from the connected chat trigger node. So it's just coming from this node right here. As you can see, there's the session ID that matches the one in our chat memory table. and that is how it's using it to store sort of like the unique chat conversations. Cool. Now that we have Postgres chat memory set up, let's hook up our Supabase vector store. So we're gonna drag it in and then now we need to go up here and connect our credentials. So I'm gonna create new credential and we can see that we need two things, a host and a service role secret. And the host is not gonna be the same one as the host that we use to set up our Postgres. So let's hop into Supabase and grab this information. So back in Supabase, we're going to go down to the settings. We're going to click on Data API, and then we have our project URL, and then we have our service role secret. So this is all we're using. For URL, we're going to copy this, go back to Supabase, and then we'll paste this in as our host. As you can see, it's supposed to be HTTPS, um, and then your Supabase account. So we'll paste that in, and you can see that's what we have,.co. Also keep in mind, this is because I launched up an organization and a project in Supabase's cloud. If you were to self-host this, it would be a little different because you'd have to access your localhost. And then of course we need our service role secret. So back in Supabase, I'm gonna reveal, copy, and then paste it into n8n. So let me do that real quick. And as you can see, I got that huge token, just paste it in. So what I'm gonna do now is save it. Hopefully it goes green. There we go. We have connection tested successfully. And then once again, just gonna rename this. The next step from here would be to create our Supabase vector store within the platform that we can actually push documents into. So you're gonna click on docs right here. You are going to go to the quick start for setting up your vector store. And then all you have to do right here is copy this command. So in the top right, copy this script, come back into Supabase. You'll come on the left-hand side to SQL editor. You'll paste that command in here. You don't change anything at all. You'll just hit run. And then you could, should see down here, success, no rows returned. And then in the table editor, we'll have a new table over here called documents. So this is where, when we're actually vectorizing our data, it's gonna go into this table. Okay, so I'm just gonna do a real quick example of putting a Google Doc into our Supabase vector database. Just to show you guys that everything's connected the way it should be and working as it should. So I'm gonna grab a Google Drive node right here. I'm gonna click download file. I'm going to select a file to download, which in this case I'm just gonna grab Body Shop Services Terms and Conditions, and then hit test step. And we'll see the binary data, which is a doc file over here. And now we have that information. And what we wanna do with it is add it to Supabase Vector Store. So I'm gonna type in Supabase. We'll see Vector Store. The operation is going to be add documents to Vector Store. and then we have to choose the right credential because we have to choose the table to put it in. So this is, in this case, we already made a table. As you can see in our Supabase, it's called documents. So back in here, I'm going to choose the credential I just made. I'm going to choose insert documents, and I'm going to choose the table to insert it to, not the n8n chat histories. We want to insert this to documents because this one is set up for vectorization. From there, I have to choose our document loader as well as our embeddings. So I'm not really going to dive into exactly what this all means right now. If you are kind of confused and you're wanting a deeper dive on RAG and building agents, definitely check out my paid community. We've got different deep dive topics about all this kind of stuff, but I'm just going to set this up real quick so we can see the actual example. I'm just choosing the binary data to load in here. I'm choosing the embedding and I'm choosing our text splitter, which is going to be recursive. And so now all I have to do here is hit run. It's going to be taking that binary data of that body shop file. It split it up. And as you can see, there's 3 items. So if we go back into our Supabase vector store, and we hit refresh, we now see 3 items in our vector database and we have the different content. And all this information here, like the standard oil change, the synthetic oil change, is coming from our body shop document that I have right here that we put in there just to validate the RAG. And we know that this is a vector database store rather than a relational one because we can see we have our vector embedding over here, which is all the dimensions, and then we have our metadata. So we have stuff like the source and, um, the blob type, all this kind of stuff. and this is where we could also go ahead and add more metadata if we wanted to. Anyways, now that we have vectors in our documents table, we can hook up the actual agent to the, the correct table. So in here, what I'm gonna call this is, body shop. For the description, I'm gonna say use this to get information about the body shop. And then from the table name, we have to choose the correct table, of course. So we know that we just put all this into something called documents. So I'm gonna choose documents. And finally, we just have to choose our embeddings, of course, so that it can embed the query and pull stuff back accurately. And that's pretty much it. We have our AI agent set up. So let's go ahead and do a test and see what we get back. So I'm going to go ahead and say, what brake services are offered at the body shop? It's going to update the Postgres memory. So now we'll be able to see that query. It hit the Supabase vector store in order to retrieve that information and then create an augmented generated answer for us. And now we have the body shop offers the following brake services. $120 per axle for replacement, $150 per axle for rotor replacement, and then full brake inspection is $30. So if we click back into our document, we can see that that's exactly what it just pulled. And then if we go into our vector database within Supabase, we can find that information in here. But then we can also click on N8N chat history, and we can see we have two more chats. So the first one was a human, which is what we said, what brake services are offered at the body shop. And then the second one was AI content, which is the body shop offers the following brake services, blah, blah, blah. and this is exactly what it just responded to us with within N8N down here, as you can see. And so keep in mind, this AI agent has zero prompting. We didn't even open up the system message. All that's in here is, you are a helpful assistant. But if you are setting this up, what you want to do is, you know, explain its role and you want to tell it, you know, you have access to a vector database. It is called X. It has information about X, Y, and Z, and you should use it when a client asks about X, Y, and Z. Anyways, that's going to be it for this one. Supabase and Postgres are super, super powerful tools to use to connect up as a database for your agents, whether it's gonna be relational or vector databases. And you've got lots of options with, you know, self-hosting and some good options for security and scalability there. So anyways, hope this one was helpful. If you learned something new, please give it a like. It definitely helps me out a lot and appreciate you guys as always. So thanks, see you in the next one.










