📱

Get Our Mobile App

Take your business learning on the go!

Download on the App StoreGet it on Google Play

How to Build Your First RAG Agent with Agent Development Kit (ADK + Vertex AI RAG Service)

aiwithbrandon51:45

Transcription

Hey guys, in today's video you're going to be learning how to build your first rag agent using Google's new agent development kit. And this rag agent is amazing because it can answer any question about your documents inside of Google Drive. And it lets you add more documents to your agent to make it even smarter. And we're also going to be using Google's knowledge based service to make the entire process so much easier for you guys. And if you're serious about becoming an AI developer, you want to pay super close attention to everything we're talking about in today's video because understanding Rag is crucial for building your real world AI applications. And don't worry if you're new to Agent Development Kit or to Google Cloud. I'm going to be walking you through everything step by step in today's video all the way from setting up your projects inside of Google Cloud all the way to connecting your agents to your knowledge base. And because you guys are awesome, I'm going to be giving away all the source code in today's video completely for free. Just click that first link in the description below to download everything. But without the way, let's go ahead and get started so you can see your new rag agent in action. Then we'll hop over to setting everything up so you can do it yourself. Oh, and real quick, if you're looking for help on your AI projects or if you would like to meet other like-minded AI developers, definitely recommend checking out the free school community I've created for you guys. We have over 7,000 members. We have free weekly coaching calls and a bunch of extra resources. definitely recommend checking out and joining down in the link in the description below.

So, here's a quick overview of the rag agent that you guys are going to be building today with agent development kit. So, let's see what this bad boy can do. So, first things first, we can ask our agent to say, "Hey, what data sources are you connected to?" When we send off this request, our agent is going to start making tool requests to vertex AI rag service because that's what's responsible for hosting and storing all of the data and handling these rag requests. So you can see that our data source, we only have one right now called test corpus. They use the word corpus everywhere inside of Google cloud, but hey, that's what we just got to do. So now we can say what data sources do I have in that corpus? From there, the agent will now make a request using a different tool call to see, okay, well inside of this corpus, what information do I have? So, as you can see, I have uploaded four different documents inside of there to where these are all different PDFs and slideshows that I have created for the current accelerator that I'm running to help people run and build YouTube channels. So, you can now see I can ask questions about it. So, you can say, "What is a lead magnet and why do we need one for our channel?" So, you can see whenever we ask this question, we're now doing a actual rag query. So a rag query is where we make a request to the vector store. This request what happens is it finds all the relevant different pieces of information inside of our database and it grabs and you'll see later on the three closest pieces of information from the slides and then it goes, "Oh, okay. I understand why we want lead magnets for YouTube channels." It basically helps start a conversation, builds trust and uh from there it just helps you build out an email list. So it literally just walks you through everything that was a part of the slideshow.

Now, what's also really cool about this agent that we're building together today is you can continually add new pieces of information to make the agent smarter and smarter each time. So, if I hop over to, in my case, over to a new Google Drive and I can see right here I have some slides. So, I can easily add this Google slide to my agent. So, you can see I copied a link and now I can say please add this doc as well. Now I can just paste in my document and from there the agent is now going to call a new tool which is going to be add data. And this would take the longest. But what's happening behind the scene is it's chunking all the individual pieces of data. It's embedding them and then storing it into our vector store. And now you can see great I have stored this new document. So we can ask one more time what documents do you have? And now it's going to make another tool request and it should show our new document this time that includes week five. So you can see at the bottom, yep, we week five. So you can now see what do we talk about in week five. So now it's going to make one more request with our new document to showcase that yes, I understand what's in this PDF cuz I've done all the chunking, embedding, and saving it. And now I can answer everything about this PowerPoint. So you can understand why building a YouTube channel, why newsjacking is so important, and some tools. And all this was covered in the PowerPoint that I uploaded.

So yeah, this is the agent in a nutshell and you're going to understand in the rest of this video how to set up your environment, create everything in the cloud, how to build out the agent, and add in all these tools that you got to see today. So let's go ahead and dive in.

Okay, so here's a three-step overview of everything we're going to be doing in the rest of the tutorial now that you know how awesome this rag agent is. So, first things first, we're going to hop over to Google Cloud where we're going to create a new project for you guys, and we're also going to enable all the necessary AI services inside of Vertex AI to make everything else work successfully. From there, I'm going to show you how you can set up the Google Cloud CLI on your local computer. And this is what's going to allow you to log in and start to use everything that was set up in Vertex AI. Once we have setup complete, it's then for the time for the fun stuff where we're going to overview and review all the code for agent development kit. And in this overview section, I'm going to walk you through how you can start to use ADK and set it up to use all these different tools in order to properly use the Rag service inside of Vert.Ex AI. And this is the best way for you to learn about all the different commands and functionality that are open to you guys in order to set up your Rag agents. So, let's dive in over to Google Cloud to kick things off.

So, welcome to step number one where we're going to set up a Google Cloud project so that we can enable all of the AI services we need inside of Vertex AI to run our Rag agent. So, first thing you need to do, just go and search for Google Cloud and you'll want to click the first link that pops up. This will take you over to Google Cloud and you will need to sign up for an account if you've never done it before. Should be completely free to do. And once you sign up for an account, we then want to go to our console. Our console is basically our dashboard where we can manage all of our projects inside of Google Cloud. So, what you'll notice if this is your first time coming in here, you should have a workspace created which will house all of your different projects. So, you can see we're looking at one of my older projects right now from a previous video. But in our case, we want to create a new project for our rag agent. So, what we'll want to do is in the top lefthand corner is we want to click here and we will want to create a new project. So once you click new project, it's going to ask you what do you want to call it. So in my case, I want to call it ADK rag and then I'm going to call it YouTube because this is for YouTube. You can call it whatever you'd like though. From there, you'll be asked to connect billing account. The only billing that we're really going to get charged for are two different items. One, we're going to get charged for tokens. So as we chat, you know, we're going to get charged for using the Gemini Flash 2.5 model, which is basically like a penny. Like it's wild how cheap it is. And then inside of Google Cloud, every time you upload documents, you're going to also get charged for storage. I believe it's 20 cent per gigabyte per month or 2 cent. Either way, it's really affordable and we're just going to be uploading a few megabytes. So, once again, it'll probably cost you another penny all in all to run this whole demo. So, two pennies and you are good to run this project. So, you want to connect your billing account. So, mine's my billing account and we are good to go. From there, it will create a new project for you guys. So you can see it has our name and it's going to take just a few seconds to create this whole project. Once it's done, you'll be able to select this project and it will change your current working project to the new one. So I'm going to click it and you can see it changes the project we're working with, which is awesome. Great. So what we can do now is we want to enable all of our AI services. So you want to click on Vertex AI. Vertex AI is basically the AI suite for Google Cloud. And we want to click enable all recommended APIs. So you're going to click this and this is what's going to set everything up for you guys to enable you to easily start to work with, you know, all of their models so you can easily chat with them more on that in the next lesson next step. And this is what's going to allow you to start working with their Vertex AI rag service. So you're going to give this just a little bit as it sets everything up, but we don't have to watch it go all the way through. we can actually head over to step number two, which is where we're going to start to set up Google Cloud, their CLI tool, which is basically their command line interface tool, which is how you can actually on your local computer connect to the cloud. So, let's go ahead and head over to step number two so you can get this all set up.

So, welcome to step number two, where we're going to start setting up Google Cloud CLI and install it on our local computer, which is going to allow our local computer to talk to Vertex AI in the cloud. So, what do we need to do? Well, we are just following the installation instructions provided by Google. And the first thing we need to do is follow the instructions depending on which operating system we're using. So, I'm on a Mac, so these are the instructions I'm going to follow. Definitely recommend picking the one for your operating system. Now, there's a link in the readme that you can use to follow and find this link. So, if you just want to download the source code completely for free and follow these instructions along, link down the description below. All right, so let's keep on cruising. So, first things first, we need to download the appropriate package. So, in my case, I'm using Apple Silicon. So, I'm going to download this one. So, I'm going to click the link. And this should take just a second to install. Sometimes it's a little weird. I'm going to refresh and download it again. And there we go. So, now it is downloading. So, we're good. So, what I could do is I can hop over to my Finder. I'm going to doubleclick the package to basically unzip everything. And once it's done, we'll end up with a file just like this that says Google Cloud SDK. Inside of it, you can see there's a ton of different things, but most importantly, there is an installation.sh file. So, how do we use this? Well, we're going to hop over to a terminal and we're going to follow the rest of the instructions set up by Google. So, the next one it wants us to do is run the installation script. So, we're going to copy this command and we're going to paste it. You need to make sure you're in your downloads folder for this to work. So, we're going to paste it and run it. Now, this should take just a second and it's going to start walking us through a few questions. No, I don't want to send everything. So, wait, sorry. Then it's going to ask, do you want to update your path? And we're going to say yes. I do want you to set everything up for this. We're just going to hit enter. And this is going to update our path. And it's going to save everything to this. So, we're going to say yes. It's going to install the recommended modules. Yes. And then from there, we should be good to go. And now you should be able to run going back to their instructions, you should be able to check which version of Google Cloud you are using. So in my case I'm just going to check it by running Google Cloud version and I should now see that this is you know it is working. Google Cloud is good. So we can move on to the next step which is going to be initializing Google Cloud so that we can connect our project. Now, in our case, we're just going to run this command, Google Cloud innit, without all the extra fluff cuz we've already updated our path. So, I'm going to type in Google Cloud innit. And now, what this is going to do is take you through the process of picking your project. I've done this in the past, so I'm going to go through it new. So, I'm going to say one cuz I want to reinitialize this configuration. And then it's going to go through the whole process of setting everything up. So, first things first is it's going to ask you to say, "Hey, you must sign in. Do you want to?" I'm going to say yes, I would like to sign in. This will open up basically your local browser to let you log in. So, I was signed in on this email. And then you're going to say yes, I'd like to allow Google Cloud SDK to do everything. So, I'm going to say okay. Now, this should take just a second. You're authenticated. Life is good. You can start using Google Cloud CLI. Fantastic. Now it's going to say, "All right, you have a ton of projects. Which one do you want to use?" So the one I just created was ADK Rag YouTube. So I'm going to say two. Then it's going to say great, you're using this project. And in our case, do you want to configure a default compute region and zone? And we are going to say yes because the rag services only work in two locations. So in our case, the best one to pick is US Central 1. And it looks like there's multiple ones. Yeah. So we can pick any of these. So I'm going to say I'm going to say nine, which is going to be US Central 1A. So we're going to say nine. Fantastic. Then we should be good to go. So if you follow along with the rest of our instructions, in our case, we've already set up the credentials, but we can run it once again just to make sure everything is good. And yeah, so we're already good. We don't need to do this. Life is good. So, so now what we can do is move on to the next step now that we have set up Google Cloud on our computer, which is now actually hopping over to our Rag agent that we're going to be showing you guys for the rest of the tutorial where you're going to learn how you can have your agent start to work with the Rag service in Vertex AI. So, let's hop over to part number three.

So, welcome to part number three where we're going to get our hands dirty and start working with the code. And in this part three, we're going to break it up into first, I'm going to show you how you can set up your local environment so you can install all the necessary packages to run everything. Second, I'm going to quickly show you how you can set up your file. This one's super simple. Then finally, we're going to dive into the agent and its tools. So, let's dive into getting our environment set up so we can run this and start doing our rag request. So, the first thing we're going to do is create a virtual environment for you guys so that we can install all the necessary dependencies inside of this project. And you can see all the dependencies for this project and our requirements.txt file where we're going to install Google agent development kit as well as all the Google Cloud libraries needed in order to run everything. So first thing we're going to do is run this command right here which is going to create our virtual environment. So I'm going to paste this in and this will create a virtual environment folder for us in the top left. Once we have this set up, what we can do is run this command if you're on a Mac, which is going to activate the virtual environment. And if you're on a Windows, you're going to want to run this. All right, so let's open everything back up in our terminal. Paste it in. Now, you can see it looks like, yep, we are inside of our virtual environment. Now, once we have that set up, we can move on to the next command, which is going to actually install all of those dependencies you saw inside the requirements.txt file. So paste this in and this is going to go through and just install everything needed to get everything running. So now while that's running because it's going to take a few seconds, we need to start working on setting up ourv file. And this is where we're storing all of our environment variables. The good news is we're actually not saving any API keys or credentials or anything like that. The reason why is cuz you set up Google Cloud CLI and you've already logged in. So your local computer automatically has the ability to work with Vertex AI. So no API key is needed. You already did all that hard work. So the only thing we have to do is just say hey which project are we working with whenever we're making requests to Vertex AI. So in our case yes we're using Vertex AI. When it comes to the cloud location just go ahead and put central 1. That's just the easiest way. And then finally we have to say what is our project ID. So you can find your project ID if you head back over to Google Cloud Console and you can find it right here. The main thing is you need to make sure you have the right project selected because you don't want to, you know, work with the wrong project. Okay. So, you're going to copy that ID and then come back and paste it right in here. And then you're set up and you're good to go. And at this point, you can run everything to make sure it's working. So, you need to make sure you're in the right folder. So, we're just in the root folder of the project you cloned. And you can now run ADK web. And this will spin up the server and the website. So, now you can come in here and start to chat with it. So, you can say, "Who are you?" And at this point it will should answer like I am Gemini a model by Google. Yeah. So exactly perfect. So you are now cooking. If anything went wrong at to this point feel free drop a comment down below or hop over to my school. Happy to help you out on either place.

All right great. So now we can move over to the next part where I'm going to walk you through the agent. Then we're going to move on to tools. So now it's time to look at our rag agent which is going to handle all of our requests, connect all of our tools, send them off to our knowledge base, do everything for us. Now one of the things I do want to mention before we dive in. First off, if any of this looks foreign, always hop over to my ADK crash course where you can learn more about setting up agents and all the course structures. For example, when we're creating a rag agent, we need to set up a folder or really just an agent in general. Sorry. Whenever we're creating a new agent, you need to have it in a folder. You then need to have an agent.py and you need to have a root agent. All this covered inside the crash course. Definitely recommend checking it out. So, let's dive into the core parts of this agent. So, the first things first, we have to pick a model from Google to make this work. You could use a different model. You could bring in OpenAI claw. You can bring in any model, but we're going to be using this Gemini 2.5 flash model. Reason why it's super smart and it's super fast. You can go over to Google's AI developer docs to see all the models they have, see what they're good for, and you can also see how much they cost. This one cost pennies to run, so that's why we're using this one as well. Fantastic. From this point, we now get to pass in all of the different tools we want to add to our rag model. In this case, we're showing all the different tools that you saw earlier. Everything from creating, adding, deleting, listing. We have everything mentioned right here. Now, I do want to start walking you through all of the descriptions first because in the next section, we're going to go through each tool one by one, but I do want you to see some of the core instructions for this agent. So, when you're off on your own working on making your own rag agents, you'll know what to do. So, what we're doing inside the instruction section is just telling the agent it exactly what it needs to do. At the end of the day, we're working with agents. Agents need context about what's going on and they also need to understand what actions they can take to better support users. So, we give it some context to basically say, "Hey, you are a rag agent. You're going to be working with a document store. Inside this document store, you have access to a ton of different commands that you can run to help answer specific questions. So, we're just giving it a high level overview. From there, we dive deeper into its core capabilities. So when it comes to quering documents, you can answer questions by retrieving the relevant information. You can list them out, create new corpus, you can delete them, whatever you want to do, it's pretty much called out right here. Then we start to give it instructions on how to, you know, interact with the user. So you can ask them what they want to do and then we give it basic classification instructions. So if they're asking questions about a knowledge base, we pretty much want to do a rag query. If they're asking what corpuses are available, list them and so forth and so forth. So basically, this is just classify the request, call a tool. Classify the request, call a tool. That's what all we're doing here. Then for each tool to have the best results, what I recommend and what is in the Google docs is basically to for each tool, you can kind of list out the different parameters and provide even additional information around what information needs to get passed into them. So if you have any special instructions too for these, you can feel free to add it here for your tool calls. So yeah, we just have parameters and tool calls left and right. Then finally, I've just added some additional information so that it provides for a better experience. So hey, these are all internal technical implementation details. Do not show any of this information to the user when answering questions. For example, you'll see later on we're going to track which current corpus we're working with inside of state to say like, oh, we were asking questions about this knowledge base. Now we're asking questions about this knowledge base. So, we're going to keep track of that. And basically, you know, we're just giving it some additional instructions on how to use the tool calls. Cuz if you don't have this right here specifically to say this is not userfacing information, it will repeat to the user a lot of the underlying things like, okay, cool. Now, I'm going to call this tool command and do this for you. And like, no, I don't they don't need to know that. they just need to get their questions answered. Finally, we're just giving it some additional communication guidelines. So, just be clear, you know, explain what actions you've taked and so forth and so forth. So, definitely if you have any questions, dig deeper into the instructions because this is in my opinion the best way to make robust agents.

So, now that we got that out of the way, we're going to start going through each one of the tools one by one for multiple reasons. a so you can understand what they do and I think analyzing these tools is the best way for you to understand how to start interfacing with Vertex AI's rag service. So you're going to start to see from creating new ones to how we can add information check what corpuses we have make queries to them. You're going to understand all of it by looking at these tools. So let's start on the first one which is where we're going to create our first knowledge store and then we're going to keep going from there. So let's hop over to our first tool.

So, welcome to the first tool inside of our rag agent, which is going to allow us to create new knowledge stores inside of Vert.Ex AI. So, this is specifically the create corpus tool call. And I want to walk you through the core components of this tool call so you can understand exactly what's going on. So, I'm going to scroll down because all the code's not necessary, just a few certain parts. So the main things that you need to add when creating a new knowledge store inside of Vertex AI is first you need a name for the data store. So if you want to have multiple knowledge stores, one for answering personal questions, work questions, other questions, you would want to create a corpus for each one and you can give them a name. We just want to make sure that this name follows their naming schema. So we just don't want to put like spaces. We're going to use underscores and so forth. Great. So once we have a nice clean name that we can use to showcase, what we want to do next is start to create some of the model configurations we need in order to create our corpus. Cuz if you look, this is the most important command right here to where you can see in order to create a new corpus, we need to give a display name. And then for the vector database we're creating, we need to say, hey, which embedding model configuration do you want to use? Now, if you've never seen embedding configurations before, here's just like a 10-second crash course of everything related to doing basically rag. And the long story short is when doing rag request, there's it's got kind of a two-sided problem. Over here on the left hand side is adding data to your vector store and then the right hand side is asking questions about it. So, here's your crash course. When you're adding information to your vector store, what you can do is say, "Hey, I want to add this document." This document gets chunked up into a bunch of small little pieces to where it's easier to digest. From there, we eventually get to the rag corpus, which is what we're creating right now. And we have to pick which embedding model do we want to use for everything. The embedding model is what takes human language and then converts it to a bunch of ones and zeros. So the computer can fully understand exactly like, oh, when you talking about this question, it's also super similar to this phrase. So it can just basically compare numbers to numbers cuz that's what computers are good at. Computers are not good at comparing words to words. All right, so we're picking a embedding model. Now, you can kind of see it right here. There's some that come from Google. So we're just going to be using Google's models for this. So their Google model, it's their text embedding model version five. And just in case you have questions about pricing, this model for a 100page book, if you were to embed all of it, it would cost you 40% of a penny. Meaning like it's not even one penny, it's like 40% of a penny. So a 100page book less than a penny, which is wild. So this model is insanely cost effective to use. So definitely recommend using this one. And that is what we're going to be using today. And then finally, whenever we eventually ask questions later, so you'll learn more about this later. Whenever we ask questions, our questions are going to become embedded as well. And then once they're embedded, we can compare what embeddings we have in the vector store compared to the query that's being passed in. So long story short, we need to have one consistent embedding used for in loading data into the knowledge store. And then when we're asking questions to the knowledge store, we need one shared embedding to make everything, you know, standard. So what do we need to do now? So in our case, we're saying, okay, I understand that I need to provide a embedding model. So what we're doing is we have a configuration file and in that configuration file we're just saying hey I want to use that embedding model that I just showed you on the whiteboard and I want to use that one. Fantastic. From there all we're doing after we make the request and this one will take roughly about 1 to 2 minutes creating it just takes a while. What'll happen is it will then we're going to start to update our state inside of our agent development kit. And our state is just basically a way we can keep up with information across multiple calls. So, we're going to say, hey, I made a new corpus. This exists. Here's the name of it. Also, this is the current corpus I'm working with. Cuz obviously, if you just created one, you probably want to work with it. Finally, we're just going to return if everything works well. Hey, this was created properly. Here's the name of it. Here's the and there's two different names. There's a display name, which you're going to add, which is like just like the human readable one of like personal knowledge base. But then under the hood, there's a more official name which is going to be like, you'll see this later on, but it has a bunch of forward slashes and it's it's more of like the unique identifier of the knowledge store. So, we're just returning both so that our agent knows exactly what information was created. And if anything goes wrong, we're just going to return an error so that the agent can understand what went wrong.

So, let's see this in action. Over here, I've already have agent development kit running. If this is your first time running agent development kit, what you can do just type in adk web and this will spin up a web server to where you can start chatting with your agents. So let me refresh this. Great. So I would say I would like to create a new knowledge store called personal. Actually I wanted to call this one business. Then what it's going to do is say great I'm going to make the corpus and we can analyze. If you click on the tool call, you can see exactly what information was passed to our function call. So in our case, you can see our rag agent made a call to create corpus. And in this request, what it did, let's scroll down. Some of these are tricky. It kind of jumps around for you. So I think this is request two. Some of the times, yeah, so we're going to click here. Ah, sorry. It just didn't load the picture. It moved out of the way. So you can see we called the create corpus function. And you can see this is the response. Sorry, there's so much happening in here which is good. Oh yeah, so you can see we made a call to create corpus when it came to passing in parameters. You can see we wanted the name of it to be business and then you can see it took a second and then finally returned. So you can see let's just look at the response in the next tab right here. Let's see create corpus. Great. So you can see it returned all of that information that we showed at the end of our code. All this right here. Sorry, too many windows guys. There we go. So you can see right down here we said return this if it works properly. And you can see that's exactly what returned. Success. Successfully created the corpus called business. Here's the project name that I was talking about earlier where it has all the unique identifiers, the location and the actual ID of that rag corpus and it has the display name. So it created it. It created it perfectly. So now what I want to do just to show you guys that this does exist. We're going to move over to the list corpus example where we can see all the different corpuses we've created so far. and so we can see which ones exist and we should hope to see our new business one. So, let's hop over to tool number two.

So, welcome to tool number two where I'm going to show you guys how you can start to list all the corpora that you guys have created so far. I know I'm butchering the plurality of this word, so I apologize, but the main thing we're going to do is just list all the different rag stoages that we've created so far. You can notice we're not passing in any parameters into this one because there's no need to. We just want to see everything we've ever created. And let me show you how we can do it. And in this case, there's really only one core command we need to run. Got to love Google for making this so straightforward. But basically on the rag import from vertex AI, what we're going to do is call the list grappora. What this is going to do is then just return all of the different instances that we've created so far. So we're going to get back a list in here which is going to be of type. You can see it right here. Let's see right here. Yeah, the return type is going to be I keep jumping away. But it is a list. Yeah. So it's a list of rag corporate pagers and what this means is we can now iterate through each one we get back and we can pull out the specific information we want. So in our case we're going to pull out the resource name which was like the really complex one with page project number you know the location all the extra information. We just want the display name which was the human readable one and some additional information about when we create it. Once we have all of that ready we're just going to return it to our front-end users so that they can see exactly what they have available. So to show you that this is working is I'm going to rerun this. So you can now see I'm back in our agent. I'm in a new session and I can say what corpora do I have? Let's see. And from there this agent is going to make a tool call to list corpora. And what this will do same thing as earlier is it's going to make a tool call. And now you can see that we have one created which is called business which is exactly what we did in the previous step. So now that you have seen that all of this is working, we're now going to start moving to the next step where we're going to add information to our vector store so that we can later start to ask questions about it. So let's hop over to tool number three which is going to be add data.

So, welcome to tool number three where you're going to learn how you can start to add data specifically files from your Google Drive such as your Google Docs, Slides, and so forth as well as items from cloud storage. Now in this tool I'm going to walk you through all the main important parts. So first things first is whenever we want to add data, we need to specify which corpus do you want to add information to. When it comes to paths, we need to say basically, hey, what are the different links to all the different resources you want me to chunk, embed, and then put into the vector store. And finally, we're going to work with tool context, which is just something unique to agent development kit to where we can update state. So let's look at what we want to do. And I do think it's important to mention that there are only a few supported formats when it comes to saving data. So if you just provided a random link, this is going to break. You specifically need to provide a link from Google Drive, Google or Google Docs or Google Cloud Storage. And you can see the supported file formats right here. Now let's go through this part by part so you can understand what we're trying to do in this tool and understand some best practices as well. So first thing, whenever we start to run this tool, we just want to confirm that hey, you asked to make a request to save data to this corpus. does it exist? So, we have a nice utility checker that will make a request over to Google to say, "Hey, does this exist? If it doesn't, you know, so it's going to get all of them. It's going to check the list and it's going to say, hey, you know, for whatever reason, this one was not in there. Therefore, you can't do this." So, we're just going to check first before just assuming everything works. So, it's good to have some validation. Then, what we're going to do next is just to make sure that all the different inputs that were passed to us are actually valid. So, we just want to make sure that everything that gets passed to us is going to be a path or a string. So, what we can do next is start to now that we've checked the different types to make sure that they're valid, what we can start to do next is to make sure that these URLs are actually in the right format. Meaning, they need to either be the Google Docs, Sheets, or Slide style, which is this style right here, where it has the unique file ID. Option two is it needs to follow the Google Drive format where it looks like a link like this. Or finally, it needs to be a Google Cloud Storage link. And that's good. We're going to continue. If anything else goes wrong, we're going to add to the fact that, hey, this link was invalid. So once again, we're just doing a little bit of extra validation so that our agent can, you know, roll with the punches and knows that it's only working with valid data if it gets to certain points. Fantastic. So now we're at the part to where we're going to say hey I have valid data that I would like to pass to my vector store. So what we're going to do is go great here's the display name which is going to be business. I want to get that full resource name. Once I get the full resource name I then want to start setting up some of my chunking configurations. And I can show you what this means real fast. So back over to our handydandy whiteboard. When we get a huge document like let's say we get a 100page document. Well, we can't just put the whole 100page document into the vector store. What we ideally want to do is chunk it up based on paragraphs or, you know, a character count. There's a bunch of different strategies, but the main two that you'll use 99% of the time are going to be chunk size and chunk overlap. So, here's what that means. Chunk size is how many tokens do you want to include in each different chunk. So, do you want to include a,000 characters, 500 characters, do you want to include 10,000? Whatever you want to do, you can set here. And then chunk overlap is the next one. So, let's just imagine just so you can kind of see this in action. Let's imagine that this was chunk one. Well, if you wanted chunk overlap to be a little bit or or zero, what would happen is after the last word, we would just make a brand new chunk. But if you did want there to be chunk overlap, which does really help when returning more contextual responses, what'll happen is there will actually be a little bit of an overlap where this area right here will include some text from the the last sentence, which is great cuz like all the time when you're breaking up and looking at chunks, there's a good chance some information was in part one, some information was part two. So adding a little bit overlap helps generate better results. It does increase the size of your vector store, but it does result in better funnel embeddings. So here's what we're going to pass in. So, we're going to say I would like a default chunk size of 512. And then when it comes to chunk overlap, I want about a 20% overlap, which is these are pretty standard numbers. Definitely recommend starting here. Fantastic. So, once we have said, okay, great. Here's what my all my chunking configurations should be. What we can do is start to run this command, which is the most important one, which is where we're going to start to import our files into our vector store. So, this is where we're going to go. Great. Here's the actual full name of our business vector store. Here are the valid paths. So, here's the Google Drive. Here's the other Google Cloud Storage links. From there, we're going to pass in our transformation. So, how do we want to chunk things? And then finally, we're going to pass in another field, which is max embeddings request per minute. And basically, we just don't want to blow things out of the water. I believe this one is Yeah, this one. You don't even have to have this one. It defaults to a,000. So you could drop this one if you want, but you can see what it does. If you dig in just a little bit more, you can see, let's see, I just want to read it to you guys so you can see exactly what it does. Yeah. So it's optional, but it's the max number of queries per minute that this job's allowed to make. This volume basically it just makes sure you stay compliant with Google's quotas. So that's all we're trying to do here is just to make sure we don't go over any quotas. Okay, great. So what we're going to do after we import all the different files into our vector store, we're golden. So, at this point, we can say, "Great. We're going to reset our current corpus just in case for whatever reason that got out of sync." And then from there, we're going to start to build up a nice message that we can send back to the user saying, "Hey, I went off and included all of these Google drives and URLs into your vector store." And what we're going to do is just showcase the number of files that were imported as well as where they went. So, that is everything that you need to do when it comes to adding data to your vector store. So, now let me show you how to do it. So, I am over now inside of Google Drive. And if you want to add a document to your vector store, you can click any of these documents right here. You're going to I need to just only click one more actions. I'm going to refresh real fast. For some reason, it tried to select two. Yeah. So, I can click the one I want. From there, I can click share. At this point, what you want to do, just to make it super easy, click share again. And at this point, you can say, "Hey, anyone with this link can access the contents in it, which is all we need for right now." Click copy link. And now what we can do is start to run this. So let's hop back over to our case a new session. Well, we'll actually stay in this one. So you can say I would like to add the following

doc to my business corpus and then we can just paste in the link. Now, what this will do is it will pass this information in. So, it's going to call the add data function that we just created. For some reason, uh, don't trust the visuals in ADK. They're working on that. But yeah, so right now you can see it's pulling the wrong one. So, it's still delayed. It won't update until after the whole tool calls run. But right now, what it's doing is it's taking in that Google slide that was like 60 slides. There was a ton of information into it. And what it's doing is it's now chunking it up into small pieces. After it chunks it up, it's then passing all the embeddings over to the vector store. So, you can see that this information has now been successfully added to your corpus. Awesome.

So, now we're going to move on to the next step to where we should be able to say, "All right, Corpus, you said that you saved this document there, but can you actually show me which document you saved, just to have proof that everything worked?" So, now we're going to hop over to the next tool. So, now it's time for us to look at our get corpus information function. And the whole point of this function is to say, "Hey, I want to know for the specific knowledge store that I'm working with, which documents are inside of it." That's all we're trying to do. So, here's how we can run this. First things, we need to pass in the corpus. So, the agent's going to do that. Then it's going to just check, "Hey, is this an actual valid corpus name?" Just as a quick test. If it's not, we're going to exit early. So, it's more good validation and agent best practices. From there, we're going to get the corpus official name. So, that's the more long one. From there, what we're going to do is say, "All right, from Vertex AI, I want to get the rag class, and I want to call list functions on this specific corpus that we're trying to work with." From there, we're going to get back a list of all the different rag files inside of that corpus. And then we can start to iterate through each one of them. And ideally, what we're trying to do is just extract all the information we want to return. So, in our case, we're going to pull out the file ID, the display name, the unique resource identifier, when it was created, and the last time it was updated. That's all the information we're going to return. And we're just going to iterate through each one, put it in one huge file detail list. And once we're done processing all of them, we are going to return them back to our agent saying, "Hey, things were a success. I can now see all the information inside of this corpus. Here's the name of it. Here's the display name. Here's how many files, and here's a list of details of all the files."

So, let's see this in action. So, I've opened up a new session because I didn't want to, you know, get things confusing. So, we can say, "What corpus do I have?" Just because we need to know what we're working with. So, you can see our old one's working. Great. So, we have that one. So, I can say, "What documents, what docs are in the business corpus?" And this should return back to us. Hey, it looks like you just called, look like you just uploaded a document called week one, cuz that's exactly what I did a second ago over here. Yeah, week one. So, you can see it was uploaded and yeah, there's only one document in there. Great.

So, now what we can do is move over to our rag query tool. And this is where things are going to get interesting because this is where you're going to be able to see us start to make requests about what's inside of this document. So, let's hop over to the next tool. So, you can see the rag fully in action. So, now it's time to dive into the rag query tool, which is my favorite one out of everything that we've done so far because this is where we've actually all the dots are going to connect and you're going to see our agent start to answer questions about our documents. So, what do we need to do in order to run this tool? We need to say, "Hey, which corpus are we working with, and what question or query do you have about it?" From there, more validation, make sure the corpus exists. If not, return. From there, we're going to start working on the specific retrieval parameters. Now, in the case of making requests to a vector store, the two most common types of configurations that you're pretty much always going to see in all vector stores are top K and filter. So, let me explain each one of these really quickly. Top K means, "Great, out of all of the different data that's close to this query, how many do you want to return back to?" So, if I find 10 pieces of data that are pretty similar, obviously I'm going to return the closest ones first, but how many do you want me to return back to in general? In our case, we're going to say, "Hey, I only want the top three closest to answer questions." Okay, great. Next, what I want to do is then pass in a filter, meaning, "Okay, well, we have a vector store with a ton of different information. How close does the data that you're asking a question about versus what's in the data store need to be similar to each other?" And this is where something called a distance threshold comes in. So, let me just show this one cuz this one's so much easier to understand visually. So, let's imagine all the blue dots are our different embeddings that we have saved in our vector store. And we ask the question in our case of like, we just ask a question. And it just so happens there's a few dots right next to us. There's some that are like kind of close, but then there's some that are really far away. So, here is what it would look like whenever you want to do your default vector distance threshold. So, let's just say to start off, we pick a number that is super high. So, it goes between zero. It goes really depending on the platform between negative one and one, but usually I think it's between zero and one. So, one means it's identical. Basically, 0.8 means like, "Hey, it's pretty darn close." 0.5 is like, "Eh, like they talk about the same thing." 0.1 is pretty much just like, "Hey, give me anything." So, here's what this would look like. So, if we were like, "Hey, I want to do a vector distance score of 0.9." Well, what that could mean is I want to do anything that's really close to me, which would mean, "Oh, okay. So, here's all the information that's really close to you." So, in this case, what would happen is we would just get back two pieces of information. Whatever they are, great. That's up to you to understand and deal with answering the question. But, I'm just my sole goal is to give you relevant information. Now, if we were to bump this up to say, "Okay, actually, what I wanted to do is like a 0.5." Oh, a 0.5 gives me this information. So, in this case, oh, you get more data. However, some of it is not as similar, aka, this is very similar. This is not so similar. So, at this point, we're getting more information in, but it just might not be hyper relevant. So, hopefully that little crash course on distance thresholds matter. And there's a bunch of other types, but this is the most common one that you want to use. Great.

So, at this point, we now understand, "Hey, whenever I'm making a rag retrieval request, I understand the default configurations I want to pass in. I want to get back three pieces of data, and I want to get back, eh, just close-ish data, 0.5 close-ish." So, from there, what we can do is make our rag retrieval query. So, in our query, the main pieces that you need to pass in specifically are like, "Hey, which vector stores do you want to work with?" In our case, we're just going to work with one. Later on, you can maybe update this tool to work with multiple, but for right now, we're just going to do one. And then we're going to pass in the name of it. From there, we're going to pass in the text. So, if we were to say like, "Hey, what is the topic of this document?" It would go off and answer that question. And then our configurations. Now, it is important to note this piece of information right here. The query is raw text. This piece of information will get embedded before getting passed in to the vector store. It's basically what allows the vector store to go, "Oh, here's the numeric representation of your query, and here's all the numeric pieces of information in the vector store. So, I can see, oh, these two are very similar." So, just know this query that is text will get converted over to an embedding. Fantastic. From this, we're going to get a response. This response is just going to have a ton of different context like pieces of context, which are basically just, you know, "Hey, here's what was found." And what we're going to return back to our agent is the unique resource identifier, the name of the source. We're also going to return the text. So, like the raw piece of information. So, like, "Oh, on slide five, it said, you know, this program is about helping people make YouTube," cuz that's what the slide was about. And then finally the score. So, how similar was this embedding compared to the query? Was it really close, or was it pretty far away? So, we're going to return all of those results, put them in our list, and that's what's going to get returned back to the to the viewer down here. So, yep, things went great. Here's how many, you know, we successfully queried this vector store. Here was the query. Here were the results. Here's how many results we got back.

So, let's see this one action cuz this one is my favorite part. And I think it might be helpful as well to just open up the document real fast so you can kind of see what's inside of it. So, this was for a program I was launching. So, yeah. So, let's just ask this question. "What are, what do we talk about in phase one?" So, that's what we're going to talk about and see if it gives us information back. So, let's hop back over to our agent and then we can say, "What do we talk about in phase one?" Now, what this should do is make a request to our vector store, a rag query. So, you can see it's, well, man, it's going so fast. That's the whole, the hard problem. So, you can see this is pretty cool, guys. So, you can see, "Oh, in this document, in phase one, here's what we talked about. We talked about understanding your content engine and all the core components." And if I hop back over to the slides really fast, you can see that's exactly that was what was called out in slide one. So, all around it like found everything. It found the right page. It found the right piece of information, and it helped return an answer too. So, yeah, this was, this is crazy that it was able to do that. And yeah, so that's the power of your rag agent.

So, now that we've covered pretty much connect all the dots, I want to show you a few additional tools that you have at your disposal, which are going to be everything around, you know, deleting and a few other tools. Let's go ahead and hop over to the next one.

So, now we're into the delete tools part of this, and I'm just going to show you how you can delete a document. So, if you accidentally uploaded something and you don't want it to be there anymore, or if you just have an updated version, I'm going to show you how you can delete it. And then after this, we're going to talk about how you can delete the corpus as a whole. So, let's dive into this one real fast because it's super straightforward. So, all we need to do is know the corpus name and the document ID. So, you need to know like, "Oh, I'm trying to delete the lead magnet or the, uh, not the lead magnet, but the PowerPoint that we just looked at, week one." I'm going to show you how to delete it. So, we need that document ID. So, here's how we can do it. So, first things first, we're always going to check to make sure that we're in a valid corpus. From there, what's different about this one is we need to find the document ID. Now, at this point, we would probably couldn't just run this query right out the gate. We would have to at least do some sort of list documents first, then it could run it. Or the agent's usually pretty smart to where if you ask to delete this document, it'll go, "Hey, I don't have that information. Let me call list, then I'll run it." So, the agent's actually pretty smart and can plan through steps like that. But long story short, we're just trying to get the document ID. Once we have that document ID, we can build up a full-on rag path, which has the like corpus name, files, document ID, cuz this is what we actually need to run delete. Once we call delete, what it will do is it will call delete file and it'll delete it. And it's pretty much straightforward as that. If we don't get back anything, we just know, yeah, if no errors were thrown, we know it deleted properly.

So, let me show you this one in action. So, if we hop back over here, let me show you this. So, we're going to say, "In our case, I'm going to say delete that document." And this will call the now delete document tool. And you can see it called it. It called specifically the document ID cuz it already had it, which is pretty darn cool. So, what I'm going to do just so you guys can see this tool in action. I'm going to add a new document and then we're going to go to a different page. So, let's add that one back in. We're going to do copy link. So, I'm going to start a new one. So, I'm just going to show you this. So, I'm going to say add in this document. And then what we're going to do, oh, sorry, add in this document. So, now what I'm going to do, I'm going to let it add that document. We're gonna go over to a new session where it has no idea what we're talking about. And I'm gonna say delete the week one slide and see if it can handle it because, you know, maybe it can, maybe it can't, but I just want to show you guys the power of this agent. So, adding data does take the longest. So, I'm going to give it a second to create and once it's done adding data, I'm going to go ahead and type out the message so you can see it. So, I'm going to say delete the week one presentation. So, great. I have that ready. Great. It was saved to the right corpus. So, I'm going to do a new session. So, we're going to say, "Open the week one corpus," because we have to be in the right corpus first. Sorry. "Open my bad." "Open the business corpus." My bad. From there, once that's selected, I can now say, "Great." I can now say, "Delete this information." And once we have that, I can run it. Yeah. So, it already had the ID. So, sometimes it gets a little too smart. We can try it again if you want. We'll try it again. We're hanging out together. So, I can just type in, "Delete what one presentation." This time it'll probably throw an error because it's going to go, "Hey, which corpus?" The business. Does. And now it's going to go, "Okay, well, now that I know which corpus you've told me, I'm going to then start to plan out how I can do this by calling list documents." So, yeah. So, sometimes the agents are smart, sometimes agents aren't. You know, we could add and add in way more functionality to make this agent smarter to add in additional calls, but for right now, don't want to go too deep. So, you can see now it called the list, then it called the documents, then once it gets the corpus information, it now will have the ID. Now that it has the ID, it can delete it. So, you can see like the agent's actually thinking through the problem. So, hopefully that was a pretty cool demo of seeing that tool in action.

So, now let's hop over to the final one where you're going to learn how to delete your corpus and not get charged for just existing random data staying in your vector store forever. So, here's the final tool that we're going to be showing for our rag agent today. And this one is pretty straightforward. All we're going to do is pass in the name of the corpus, a confirmation of like, "Yes, do you want to delete this document?" And this one is super straightforward because all we need to do, like we've done every time, get the corpus name. Once we have the corpus name, we just call delete on it. And if things work great, we're just going to return, "Things look great." We're also going to update our state to say, "Hey, this corpus no longer exists." So, we're just going to drop it from state and say, "Yep, that it is false," meaning it does not exist anymore. So, that is pretty much a super straightforward tool call.

Now, I'd like to show you this in action. So, we're going to say, "Delete the corpus." And at this point, what will happen is it will probably ask us for a question. Yeah. So, here's the one you want to delete. Do you want to confirm? Type in yes. So, I'm going to say, "Yes, delete the corpus business corpus." And from there, it now that it has the confirmation, it's going to go, "Okay, great. I can now delete it." It's going to call delete and it says it's done. So, if I rerun it and say, "Hey, what corpus do I have?" At this point, we should expect the answer to be none because there are no longer anything in our vector stores. So, great.

So, you guys have now mastered all the core functionalities of working with our different vector stores using Vertex AI. So, you're now a master of using their rag service. So, just as a recap, you guys are now experts at building rag agents with agent development kit. So, give yourself a pat on the back. And as a few quick reminders, you can download all the source code from today's video completely for free. Click that link down description below. And if you need help on your AI projects or just have questions in general, definitely recommend checking out that free school community I've created for you guys as well. Also, if you're looking for more AI content just like this, I have a ton of amazing resources right here on this channel. Everything from an ADK crash course, LangChain crash course, Crew AI crash course. If you need it, I pretty much have it right here on this channel and I definitely recommend checking it out. And I also recommend checking out whatever video is popping up right now from YouTube. But until the next time, can't wait to see you guys. Have a great day. See you.