Turn Company Docs into an AI Assistant (Simple RAG in n8n)

Rory Ridgers shows how to build a RAG system in n8n that turns Google Drive PDFs into a searchable AI assistant. He walks through connecting Google Drive, embedding documents in n8n's native vector store, and creating a chat agent with GPT-4 that retrieves and answers questions about company docs. The system refreshes daily to work around the non-persistent storage.
Chapters
What's up guys? In this video, I'm gonna be showing you the most simple RAG system that will allow you to put all of your company's documents into an AI agent that you can chat with and essentially act as a business brain. By the way, before we get into it, if you dunno who I am, my name's Rory Ridgers and I run an AI agency where we find and eliminate your operational bottlenecks in 14 days to keep you focused working on the business rather than in it. So if that sounds like something that you are interested in, then I'll leave a link to my website in the description and you can book up a free discovery call. Okay, so we're in N8N now, and what I quickly want to do is I quickly want to go over the RAG system in general and also the RAG system that we're going to be using. So the RAG system in general, from the highest level possible, the simplest way to explain it, it's basically just your company's documents— well, in this case it's going to be your company's documents, it can be any documents— taken from one external storage, something like Google Drive or Dropbox, and then chunked up into small pieces by an LLM, put into something called a vector store. Then your AI agent could be connected up to that vector store and it can just query it with pieces of information that it wants find. So for example, if you've got company information in there and you want to find your opening times, let's say, the AI agent could query the vector store with just the word opening times, and then the vector store will quickly be able to go through all of that data and give you back the most relevant content— will give your AI agent back the most relevant content— and then it can summarize it for you. That, like I said, in the simplest form, that is essentially what, uh, RAG system is, and that's what a vector store is. In this video, there's kind of two different types of vector stores. In this video, we're going to be going for the option that's much quicker and much simpler to set up. So if you're a complete beginner with all of this and you just want something set up quick, then this is for you. The differences between the two is one is persistent and one is not persistent. So the method that we're going to be doing in this video is not persistent, but that just means it's quicker and easier to set up. And if you don't know what I mean when I say persistent, essentially what this means is if the storage is persistent, it kind of just means it's stored externally from, in this case, NAN, which just means if NAN was to go down, let's say I deleted my account or the server restarted something like that, it wouldn't make any difference because it's stored externally, so it's persistent. It's always going to be there unless you go in there and you change it. But then not persistent in this case just means that the data is actually stored inside of NAN. So that means if my server did restart or I deleted my NAN account, that information would be deleted with it. But I'm going to show you how to sort of work around that and still get all the benefits of it being quicker and easier to set up. So let's just jump straight into this. So to begin with, we're just going to do a trigger manually, which we are going to change later, but just to begin with, we're going to be programming it manually. And what we're going to do is we're going to be taking documents from my Google Drive and then putting it into the native NAN vector store. So I have this, uh, folder on my Google Drive with just some demo information. It's just a completely made-up company, but as you can see here, this is sort of, um, just demo information. So like, this is their tech stack, and then this is their general company overview, what they do, who they are, and then this is some information on their big clients. So what we want to do first is we want to get this information into our vector store. So if we come back over to NAN, first thing we're going to need to do is I need to get the files from that Drive folder. So if we come over and we go to Google Drive, and we're going to go search files and folders. And then I've already got my Google account, uh, connected up, my Google Drive account. Resources file/folder operation is search. Search method is going to be search file/folder name, but we're not actually going to do that. I'm going to show you what we'll do instead. We're going to come down to filter because we're not sort of searching dynamically and it might change every time. We're only looking at one folder. What we do is we come down here and we go to what to search, and we're just going to do files because we're only actually looking to look at the files inside of that folder, not any actual folders. And then we go to add filter again, and then we go to folder, and then here we can just pick the folder that we're actually looking for. So I'm going to find my folder quickly, which was called Demo Company Information. Cool. And now if I execute this, yeah, we get 3 items, which is just going to be the 3 PDFs I just showed you. So Tech Stack, Client, Company Overview. Perfect. Now what we need to do is we need to extract the data from each of these files. But because there's 3, we're just going to loop over them. So we're not going to do them all in one go, we're going to loop over them. So if we come after this and go to loop, and then the batch size is going to be 1, which just means we're going to do one at a time. So let's get rid of all of this junk that's already on there. Okay, cool, now it's good. Now we can start adding stuff. So we're going to go down this loop section here, and then we're just going to go drive again. And then this time we want to download a file. So we're just going to download each file. So there's 3 files in there, just going to download each of them. Um, if we quickly execute this node so we get some data through, and then you can see this data we get. And then we want to download these files, and the easiest way to do it is just by ID, because you can see we already have the IDs of each of the files here. So if we just drag that variable in, execute step, and then you should see we get some binary data back. And the binary data is basically just a more efficient way when it downloads, um, data, just a more efficient way to show it in binary. It's just sort of like a big jumble of ones and zeros that don't make any sense to us, but it makes sense to computers. So we get the binary of that file. Now we need to actually upload it to the vector store. So after this, we can just go to vector store and there's a lot of different vector stores as you can see, like Superbase, Pinecone, uh, Quadrant, loads of different types of vector stores, Mongo, Postgres, but we are just gonna go with the simple vector store. And if you use NAN, this is similar to the simple memory in that it's not persistent and it's just native to NAN. Um, but this time it's a vector store. So what we're going to do from these options, we're going to go to add documents to a vector store because that's what we're trying to do. And then in here you can see there's no credentials, no setup. You literally put the node down and you're good to go because it's already all inside of N8N. So for the memory key, this is basically just like the vector store. So you can have multiple and you can name them. And if you want to make a new one, all you do is you just type it in. So you go to— so I'm just going to go demo company info. And then create Demo Company Info. And you can see now it's in the list, it's created. It's literally as simple as that. And then embedding batch size, if you don't know what this means, essentially just the size of the embedding. So when it embeds it into the vector store, has to do it in certain chunk sizes. So if you've got a long PDF, kind of has to chunk that up and embed it that way. And this is just defining how big those chunks would be. So it's on 200 at the moment. You can just leave it at 200, to be honest. Okay, so then now that's set up and you can see we have two prongs down here. The first one is going to be embedding. This is just going to be the embedding model. To be honest, this one doesn't matter too much either. Um, I would just use the one that you already use. So the LLM that you use most often, for me that's just OpenAI, and then you can just use the first one that pops up. So it'll give me an option for the LLM. Okay, it's going to say loading options, but it's just going to give me an option for an LLM and you can just go with that one. It's stupidly cheap and pretty much all of them work. So I wouldn't worry too much about which LLM you use. And then we have document here, and this is basically just how we define the document that's going in. So we're going to go to default data loader, and then here the type of data, it's binary. Like I mentioned earlier, we get the binary data here, so the type of data is going to be binary. And because it's the step before, it just automatically picks up that you're trying to add binary. Um, and then Moze load all input data, data format automatically detect by MIME type. So whether you upload a PDF or a spreadsheet or Google Docs, anything like that, it's just going to automatically detect that. And then text splitting, just simple, we'll leave it like that. Perfect. And now that's all set up. That's literally all you have to do. We're just gonna drag this here back up to the loop so this way it can actually form a loop and loop all the way around. But if we hit execute workflow, we get the 3 items, downloads it, adds it to the vector store, and then it cycles through. So because it's just done 2, and then it's just done number 3. Perfect. So now all of that information is in the vector store. That's literally it. That's all you have to do. No credential setup, none of that. Um, it's all set up now. It's all in your vector store. So you can see this is all the data that went in. Uh, so we got for the first one, there was 8 items, then there was 7, then there were 6. So it's just depending on the size of the document. Obviously the first one was the biggest, the second one was the second biggest, and the third one was the third biggest by coincidence. Um, but now we have the issue, like I said, where this isn't persistent, which means if I was to delete my NAN account on for us to update it, or the server was to restart or crash, this data would be deleted from my vector store. So how do we combat this? There's also the issue where when you add new, uh, documents or change a document inside of that Google Drive folder, it's not going to be automatically updated and put in your vector store, which you probably would want it to be. So we're going to kill two birds with one stone on this one, and we're going to build a system that negates both of these issues. So what we're going to do So we're going to get rid of this first, uh, trigger here, and we're going to change this for a schedule trigger. So if we go to Add Node and then Trigger, it's going to be Scheduled. And here you can kind of set this to whatever you want, but I would say doing it just once a day works. You could have it like 5 times a day, you could do it once an hour, you could do it once a week, but I'd say once a day is pretty good. And if we connect this up now, then all that's going to happen just by changing that trigger— now every single day this is just going to run through and it's going to update your vector store. And you can see it literally took like 10 seconds for it to run through when I just did the demo for you. But now this means that if for whatever reason server was to restart or something happened, it crashed, anything like that, or if you used to add new documents every day, it's basically just going to do a refresh and it's just going to add all of the new information into your VEXA store. And like I said, you can change this if you think you're constantly going to be adding, uh, things to that Google Drive folder, then you can change this to maybe once an hour or once half an hour. Um, you can do it however often you want, but I just think one day pretty good depending on how much you're going to be adding any new documents to that folder. So now we have this system where every single day at midnight— you can change the trigger hour if you like, but midnight works for me— every single day at midnight, it's just going to take all of that information that is in your Google Drive folder and it's going to add that to the Vector Store. Simple as that. So now you have the Vector Store completely working and it's all automated. Anytime you update a document or add new documents, you know that it's going to be added to your Vector Store. Okay, and then now how do we actually connect this up to an AI agent so we can chat of it. So we're going to add another section down here. We're going to add node in. If you're doing this, you'd probably want to do this on two separate canvases rather than one, um, but just for this demo, I'm just going to do it on the same canvas. So if we go to add another trigger, and then we're going to do on chat message. This way we can chat with our AI agent inside of an ANN. And then go to add AI, and then AI agent. And then the prompt is already set up with the connected chat trigger node, so that's already connected. You don't have to worry about that. And then we're just going to do the standard, uh, adding an LM for our AI agent. So again, I use OpenAI for pretty much all of my LLM stuff inside of NAN. So I'm going with OpenAI and this is GPT-4.1 mini. And then now all we need to do is to go to tool and then we can go to vector store. If you type up vector, simple vector store, make sure we're connecting up that same one. So demo company information, give it a little description. Let's say our company don't have to be super in depth for anything. You can do a little bit more, but I literally just said our company info. That's all it really needs to know. And then in here, the limit. So this is just going to be the amount of data that comes back. So for example, using my example from earlier, if the AI agent was to input into this, um, opening times right now, it will return back 4 results and it's just going to be ranked in order from the one that's most relevant to— well, it's not going to be the least relevant at the bottom, but it's going to grab the 4 most relevant and then rank them in order of relevancy, if that makes sense. So limit 4, you can leave it at that. You can change it if you like. It really depends how much information you have in there. For now, I'm just going to leave it before. And then include metadata, this is already on. You might as well leave this on. It just gives your agent a little bit more context. And then re-rank results, that's off at the moment. You can leave that off. And then down here you'll see we have an embedding model, and this is pretty much the exact same as this except it's doing the opposite. So this embedding model is taking documents and breaking them up, putting them into the vector store, and then this embedding model is looking at the broken up data and then getting back the most relevant information. So it's kind of doing the reverse of it. So again, we're just going to do same thing, OpenAI, and you can see now that is all connected. And we don't even need to give our AI agent a prompt here because it already knows it's got this tool. So we can just test this out. Let's just say something really simple like, what does my company do? What does my company do? Just to make sure it's all working and knows how to use the vector store. So it's used the vector store and then it says your company, Lumina Analytics, is a data intelligence and automation company. Based in Austin, Texas, founded in 2017. Cool. And it's given us a little summary there. And if we have a look into this tool, it inputted, what does our company do? What does my company do? And you can see this is what was returned. So there was 4 responses, like I said, um, and then it basically just does them in order of relevancy. So it inputted, what does my company do? And it gave us back company overview, Lumina Analytics introduction. This is obviously from our company overview. And it also gave some information on the clients and partnerships. The, um, case for— I guess that's from clients and partnerships as well, I'm not too sure. And then I think this one is as well. So you can see this one was probably the most relevant, but this was also nice information for it to have. Cool. Now we can ask it some slightly more complex questions. Let's just say something like, I want to use Dropbox as my storage system, will this fit with the Tech stack. So I want to use Dropbox as my storage system. Will this fit with the tech stack? Okay, then it said to provide you with a more accurate answer, could you please specify the technologies or platforms included in your current tech stack? Okay, so there is information on the tech stack in the vector store, but it doesn't know that. So what we're going to do is we're just going to add a simple prompt into our AI agent. If we go to system message, and then we're just going to say, okay, so I just said you're a helpful assistant that can retrieve company information. You have access to a vector store that includes information on company overview, tech stack, client, and partnerships. Cool. So now it's got that prompt. We'll rerun this same prompt that I just gave it. Should now use the vector store because it knows that it has information on tech stack. Um, so we'll give it a sec. The current tech stack includes various data infrastructure components such as Snowflake for data warehousing, Databricks for data engineering, blah, blah, blah. Cool. While documents do not explicitly mention Dropbox as part of the storage system, the stack already includes cloud infrastructure providers like AWS, Microsoft Azure. Cool. Your requirements to use Dropbox as a storage system can likely fit into the tech stack by leveraging integration capabilities, especially through APIs or automation tools like Zapier and Make. In summary, yes, using Dropbox as your storage system can fit with the existing tech stack with appropriate integration efforts. Cool. So we'll ask it one more. It's clear that it's working and knows what it's doing. Just to show it off, I'll, um, just ask one more question. I'll say something like, okay, so I said, give me a quick overview of all of my clients and output a summary of trends and potential opportunities. So use a vector store straight away. And then we'll give this a second because it's got to go through quite a lot of information to summarize. Okay, cool. So it said overview of clients. Luminar Analytics serves over 120 enterprise clients, including many Fortune 500 companies. Um, cool. It's given us some of our clients here, an industry breakdown. This is really cool. Um, logistics and supply chain, 25%. Healthcare and life science, 20%. Financial services, 18%. Manufacturing, industrial, 17%. Retail, e-commerce, 15%. Other sectors 5%. So it's given us a breakdown of all of the different sectors with percentages. Client success metrics, uh, average operational efficiency improvement 35%. I'm not gonna make you listen to me read all of these out, but as you can see, it's given us this summary of all of the metrics, which is really, really cool. It's a nice way for us to just sort of quickly digest a lot of data that will probably take a data analyst a little bit of time to go through. Trends, uh, strong emphasis on AI-driven analytics for operational efficiency and cost reduction. Them. And there's some other trends down here, potential opportunities. Um, yeah, like I said, I'm not going to make you watch me read them all out, but yeah, as you can see, you can pause the video and have a look at them. But very, very cool. And that did that in a few seconds. I mean, that really didn't take long at all. And if we have a look in here, it literally just inputted the word client and then got quite a lot of data back. So it used all of that information to give us the output that it just gave us. And if you want this to do better queries into here to get better data back, or like more specific data, or know the context of what you're saying a little bit more, All you have to do is literally just prompt that. You can see in the AI agent, the prompt was so simple. Um, I just literally gave it the most basic information, so there's a lot of room for it to improve there.
More from Rory

Dynamic Workflows are crazy. This is how to actually use them (beginner's guide)










