Beginner’s Guide to Metadata: Make Your RAG Agents Smarter

Dr. Violet Howard shows how to build a RAG agent that returns answers with source videos, timestamps, and links. She walks through an n8n workflow that scrapes YouTube transcripts, chunks them while preserving timestamps, embeds them in Supabase with metadata fields, and lets you filter searches by specific video or delete vectors by URL.
Chapters
Today I'm going to be talking about the different ways you can use metadata to make your RAG agents much more intelligent. Not only does metadata let us organize and filter through our data, but it also lets us enrich it so that we can get way more context as to what chunks we're looking at. If it doesn't make too much sense to you yet, don't worry, we're going to break it all down. I'm going to run through some live examples, and by the end, there'll definitely be a thinking about how you can apply metadata to your own use case. All right, so I don't want to waste any time. We're going to start off with a quick demo so I can show you guys what this metadata stuff looks like. By talking to our YouTube transcript RAG agent. So I'm gonna send off this message that says, what's the difference between a relational database and a vector database? Our agent is gonna search through Supabase. It's gonna use a re-ranker to sort those results. And now we're gonna get our answer based on a YouTube transcript. And you can see not only was our agent able to search through and answer for us, it also gave us the exact YouTube video that it pulled this data from, the exact timestamp that it pulled the data from. And then we can also go right here and click into the link. If we want to watch the full video. Imagine having a team of workers— And the only reason it was able to give us this extra context is because we enriched the chunks with this information in the metadata. So that's the use case that we're going over in this video, but metadata essentially just means data about data. So whatever you're loading in, you could enrich it with metadata like the date or the department or the author or the file name or the file size, whatever you want. Before I break down this pipeline where we're getting the transcript data, preparing it, standardizing it, and then enriching it with metadata vectorize it, let's hop into a quick ExcalDraw so I can explain real quick why metadata is important and how it works with vector search. If you've been following my channel for a while now, you've probably seen this exact ExcalDraw visualization, but either way, let's run through it real quick. And I'm also going to keep this example relevant to the one that we'll be running through in NN just to keep everything consistent. So what we start off with over here is our transcript. And then what happens is we have to chunk it up and run it through an embeddings model in order to get turned into different vectors. And each of these dots or vector points is basically associated with one chunk of the transcript. So transcript could have 20 chunks, 30 chunks, 50 chunks, just depending on how long the video is. And so the issue here is without metadata, when we're looking back at this specific chunk, we actually don't know which YouTube video it came from. So if we put 3 YouTube video transcripts in our vector database, transcript A, transcript B, and transcript C, with metadata, we can give each chunk extra information. Like the title of the full video it came from, or the URL of the full video it came from, or the timestamp of this specific chunk in the transcript. And without this type of metadata, we would have no idea the type of insights we're getting back, and we honestly wouldn't have that much trust when our agent responds to us because it can't back it up with an actual source. And then one more thing to keep in mind is the metadata is just data about data. So the metadata has no effect on the actual meaning of the chunk. It has no effect on where the chunk gets placed in the vector database. So when we're searching through our vector database, the query gets embedded, it gets put into the vector database, and then the nearest chunk or nearest couple chunks, however you set it up, get pulled back just based on the actual transcript meaning. But then once we get the transcript back and we realize that it's relevant to the query, then we'll pull in the metadata and look at it for more context. And then of course you could do things like metadata filtering where you could say, okay, you know, I have transcript A, B, and C in my vector database, but for this specific query, I only want to look at transcript C because I know that's the video that I want. Insights from. So the 3 big benefits of having metadata for your vector database RAG is that you can get more context when you're pulling stuff back. You can keep your data a little more organized and segmented. And then of course you can filter using metadata to get only what you want back. So now that that's out of the way, let's hop into NN and we'll take a look at these different pipelines and how the metadata is actually working. Okay, so we just saw the chat functionality where we're talking with Supabase. Now let's look at the actual transcript pipeline of how we're getting data into our Supabase vector store with metadata. So before we run this pipeline, let me just real quick go into Supabase to show you guys the transcript that's currently in here. This is this YouTube video that you guys saw in the demo, but as you can see, each of these different chunks, we have the content, which is just text. And then in the metadata of each one, we have the timestamp of where this chunk came from. We have the video title, and then we have the video URL. So that's exactly what happens to every single YouTube video that we process into our database. Okay, so I have this set up to basically trigger on a form submission if we want to put a video into our database. So I'm going to hit execute workflow. It's going to pull up this form that prompts us to drop in a video title and a URL. So I'm going to drop in this video from Anthropic where they're sitting on a couch and they're talking about tips for building effective AI agents. What happens first is that we're going to Apify in order to scrape the YouTube transcript. We're gonna put together the full YouTube transcript. We're gonna grab the timestamps, merge it all together, and then that's actually what gets vectorized. And then it also updates us in our Google Sheet so we can come in here real quick and see which videos currently exist in our vector database. And now let's dive into each of these nodes so you guys can see what's going on. The first one is our HTTP request to Apify to scrape the transcript. It's a really simple request. We're basically just giving it the video URL, which came right here from the actual form submission. And then what it gives us is this kind of weird item where we have like hundreds of objects in here, and each object has a start time, a duration, and then text. And so it's just really split up and not exactly the way that we wanted it. And by the way, if you guys download this template and you want to get set up, all you'll have to do is go to Appify and put in your own Appify API key right here. When you get to Appify, make sure to use code 30NATHURK for 30% off for 3 months. And then you'll come down here to your settings, you'll You'll click on API and Integrations, and then right here is where you'll copy your personal API key. And then you just have to paste it in, like I said, right here. Just make sure to keep that key private because it's kind of like your password. So from there, what I decided to do was I wanted to clean it up and get one string of the entire full context. So I decided to use a code node for this. Now what I did here in this code node, just to show you guys my thought process, I come here and I realize, okay, I have this incoming JSON and I want to use code to clean it up. What I'm going to do is I'm just going to copy a bit of this JSON right here, just so I can understand the schema. And then I go over to Claude and I say, help me write a code note in N8N that will receive this incoming JSON schema. I paste in the schema. And then I say, I need it to split out all of the text as one giant string because we're processing a transcript. So I want all of the text to flow together as one string in one item. It spits out the code. I paste it in. I try it out. And what do you know? We get one item, which is the entire transcript in one string. So that's exactly what we wanted. But that's not exactly the information that I wanted to actually vectorize and chunk up because just like we saw in that visualization, we then wouldn't know the timestamps of every area that got chunked up. So what I decided to do was another code node, and this time I wanted to actually split it up, but keep the timestamps relative to each chunk of transcript. So I did the exact same thing here. I copied the schema, I went into my Claude, and I basically said what I want to do now is lump together 20 data objects at a time, and I want the timestamps to actually stay relevant to each chunk. So that may not make a lot of sense. I'd rather just come into here and show you guys what I mean by that. So the transcript node outputs different objects called data, and each data object has a start time, a duration, and then the actual text in that little object. So what I'm basically telling Claude to do is I want to lump together 20 data objects at a time, and then when I lump together these data objects, I want you to collect and combine all of the text fields together. But in order to keep the timestamp relevant, I want to get the first start time from that first data object, and then from the last one, what I want to do is get the start time plus the duration, which would equal the end time. And then you can see on this right-hand side we get 25 different chunks of transcript, and each chunk has a formatted start time and a formatted end time. So this is why we're getting our nice chunks to vectorize that have our actual timestamps with them. So that worked beautifully. I'm now merging it all together, and then we're sending it into Supabase. And the only really thing that's special going on here is in the default data loader. This is where we're telling it what data to vectorize, and this is also where we're giving it the 3 metadata fields video title, timestamp, and video URL. So the first thing is the data to actually vectorize. I didn't want to do all input data. We wanted to load very specific data, which would just be the text that actually got split up with timestamps. We didn't want to vectorize the entire combined text. So then for each of these chunks, we wanted to give the metadata. So for video title, I just went to the form submission and I dragged in the video title. For the video URL, I did the same thing from here, dragged in the video URL. But then for timestamp, what I had to do was just go to our merge node where we pulled it all together, and then I wanted to pull in the formatted start time, and then I manually put a dash, and then I pulled in the formatted end time. So now we're getting like a range of 40 seconds for each of our chunks. And now that we have everything in our vector database and enriched, we're writing it into our Google Sheet. So we can now see once again, here are the videos that exist in our vector database. And by the way, if you guys want to get a better feel for it and download this workflow, you can do so for free. You just have to join my free school community. The link for that will be down in the description. You'll then search for the title of this video, or you can click on YouTube resources, and then the post associated with this video will have the workflow right here to download. There will also be a link right here to this Google Sheet template if you want to just import the exact same one so you don't have to set up anything else. Okay, cool. So now what we can do is chat with our agent and see if it actually can access that new video. So I'm gonna send off this query that asks, what does Anthropic's team say about building agents effectively? We'll see it look through Supabase, and hopefully it's able to pull insights from that new video that we just put into our database. So it just responded. Anthropic's team shares several insights about building agents effectively. Here's the first tip from this video, from the timestamp 12 to 42, with our YouTube video link. You can see we get some more insights down here, and this is from way later in that video. So 17:45 to 18:16. And then of course it gives us a few more points, but you can see it's pulling from the right video and it's also showing us exactly where it got that data. Alright, so now that you guys have seen how that works, before we get to the pipeline down here to actually automatically delete transcripts from our vector database, I wanted to talk about, now that we have 2 YouTube videos in our vector database, what if we wanted to make a search and say, I only want you to look through this one video? Well, this is where we would use metadata filtering because we can literally say, search through our vector database for this, but only pull back rows where the video title equals this. So in order to do that, I have a different setup over here, which is our RAG agent with a form submission in order to do the metadata filtering. So we talked to this one through a form submission. I'm gonna open up the form right here and it's gonna ask us for a YouTube video to look through, and then we can give it a query. So I'm saying that I only wanna look through that Tips for Building AI Agents video by Anthropic, and I just want 3 key takeaways. So I'll send that off. Our agent's going to take that, search through Supabase only for chunks where video title equals what we just put in there, and then it's going to give us an answer. And also, this one isn't going to answer in the chat because we talked to it through a form submission, so I just have to click into the agent to read the answer. So here we go. Here are 3 key takeaways from the video, Tips for Building AI Agents. The first one is, when building agents, it's important to design your product so that as the AI models improve, your product improves as well. The second tip is about developers, and it comes from 5:17 in that video. And then the last tip comes from that same video, of course, and from the 12-second mark. So just remember, this isn't perfect. And if you really did want like 3 key takeaways or a big summary, you probably wouldn't want to take a vector search approach because the chunks still don't have holistic context of all the chunks combined. But the point I was trying to make here is this is how you can actually control which chunks you're looking through, because in the Supabase vector store node, we have a metadata filter. And this is where we're saying only pull back chunks if video title equals this dynamic input, which in our case is whatever we entered in that form submission. All right. And then the final part is we have this little pipeline to delete things if we don't want them in our vector database anymore. So let's say we're tired of chatting with this YouTube video from Nate and we want to get it out of our vector database. All we would do is we'd come in here and we would change the status to remove. And then this workflow is going to fire off if it's an active workflow because we updated a row. It's going to make sure it's only going to process rows where the status equals remove. So let me just fire this off and show you guys. And then we set up the loop just in case you go in there and you mark off like 5 as remove, it'll go ahead and process all 5. So you can see that was really quick. It already finished up. And if I go to that Google Sheet, you can see that this now is marked as removed. And if I go to our vector database and we refresh this thing, we should see that this first chunk in here will not have the YouTube title of Everything I Learned About Building Agents, that video that we just deleted. So now our vector database is up to date. So just to show you guys how this works, the trigger goes off when a row's updated, but it's still gonna pull in everything on that sheet. So then what we do is we move into a filter and we just say if the status column equals remove, then we're gonna keep it. And that's why it kept this video, but it didn't keep the tips for building AI agents. So we're only gonna actually remove the one that we marked as removed. Then we have the loop. We only have one item in this case, so it doesn't matter. But then we're doing a set just to make sure we set the URL of the video. Because that's what we're gonna use as our metadata filter to delete vectors. So we have our URL right here of the YouTube video, and then we go into a Supabase node where we're gonna delete a row. We're deleting it from that table that we had set up, and then we're basically saying only delete rows where in the metadata, the field called video URL equals this, which is the dynamic YouTube video URL that we just set. And so it comes back to us and it says, okay, We found 32 vectors where the video URL metadata field equaled this string. And so we're just gonna delete them all. It goes ahead and it deletes them. And then we update in our Google Sheet that this URL was marked as removed. So that's the full system I wanted to share with you guys today. If you download this template for free, you'll be able to play around with all of this and just test it out and see, you know, how could you start to use metadata for your specific use case? Because it's always going to be different for different types of data. But the key really is this RAG pipeline right here, where you're going to process different types of inputs, but for each input, you should know exactly what you want. So in this case, I knew whenever I get a transcript, I want the full thing, I want the timestamps, and then I'm going to know exactly what fields are going to be metadata. And so once you get that pipeline figured out where you're taking data, you're preparing it, you're standardizing it, everything's predictable. Then you can really start to enrich all of this data in a database to pull it back. And if you're looking to deep dive into some of this stuff and you're looking for a more hands-on experience, then I definitely recommend checking out my paid community. The link for that is also down in the description. We've got a great community of members who are always sharing and building with N8N every single day. And we have two full courses. One's called Agent Zero, which is the foundations for AI automation. And then we have 10 Hours to 10 Seconds where you learn how to identify, design, and build time-saving automations. So I'd love to see you guys in this community, but that's gonna do it for this one. Hopefully you all enjoyed or learned something new. If you did, I'd really appreciate a like, helps me out a ton. And as always, I appreciate you guys making it to the end of the video. I'll see you all in the next one. Thanks guys.










