In this tutorial we are going to build our first rack agent.
So rack stands for Retrieval Augmented generation, which basically means we give the large language
model access to the external knowledge.
So any kind of data you want usually that will be your own internal data or documents.
So rack applications are kind of like custom gpts where you train ChatGPT to respond based on your on
your own content or files instead of just its pretrained knowledge.
And that's what's awesome about this setup, is that you can upload documents straight into Google Drive,
and the chatbot will automatically learn from them.
So every time you add something new, it will be vectorized to our vector database Is using this part
of the workflow and instantly updates its knowledge base.
This is incredibly useful for keeping your agent up to date without any manual work.
So it will be done all automatically.
We will use a practical example today.
So let's say you are interested in the latest features introduced with iOS 18 from Apple, and you simply
upload the official PDF document into your Google Drive, and the chatbot can immediately answer questions
based on that content.
So Apple could use this agent and embed it into their website.
And any time a potential customer has questions about the new iOS 18 features, it could instantly access
the vector database and provide an accurate answer.
So that's why ROC agents are especially powerful for customer support as they give users real time answers
based on the latest internal docs or updates.
All right, so first open your workspace and create a brand new workflow.
So create workflow.
And let's start by adding our Google Drive to the node.
So search for Google Drive.
And we want to select the option that says on changes involving a specific folder because we want to
automate the process.
So when we add a new document into this folder this workflow will be triggered.
So this node will watch drive folder and triggers whenever new files appear.
Here of course we need to connect our Google Drive account.
So if your Google Drive is not connected yet I click on this drop down create new credential And here
you have to provide our client ID and client secret.
If you don't know how to find those, go to the How to set up credentials section and you will find
a separate tutorial on how to connect Google Apps into your account.
If you if you have connected to your Google apps before, you can just simply sign in with Google to
refresh the connection just in case.
Now we can close it.
Now we want this trigger to watch for our Google Drive folder every minute.
But you can change it to every hour, every day.
It's completely up to you.
But in that case, I want this trigger to check my Google Drive folder every minute so it will be easier
to test our automation and agent in the future steps.
Now we want this automation to be triggered based on the changes involving a specific folder, so you
can leave it as it is, but you can also change it to.
Activate the workflow when it will notice changes to a specific file.
Within your Google Drive.
Now we want to create a dedicated folder in Google Drive to store this document.
So I'm going to attach the iOS 18 new features document as a resource.
So go to your Google Drive.
Create a folder.
I call mine First Rack Agent and then go to the new.
Click this plus button and click on File Upload.
And you can upload the same document or whatever document you want.
Now when I click on this from list folder so we can select the folder and it should pop up.
I can just search for it.
As you can see, it appears here.
So first rock agent.
And we can watch for.
And here we want to watch for file created.
So when a file is created in the watch folder select that.
And now we want to fetch the the test event.
Because basically what we want to do we want to fetch the document we just uploaded.
And we can see if the data come through.
Yeah as you can see.
As the output you have our data.
We have our document right here.
You can switch to the JSON format or to the schema.
And everything should work perfectly.
So yeah, it's a good practice to ensure that N810 pulls data about your your PDF file.
So you should see the file name file file ID.
So let's look for the file name.
That is here.
And also the filed is right here.
And fetch a lot of more data.
But we are interested just in a few fields.
So we know that the document was fetched successfully so we can move on.
So let's close it.
Let's add another node.
Now every time we add a new document into our Google Drive folder, it will be fetched by this trigger
node.
Now what we need to do we need to download this file.
So we need to add another Google Drive node.
So search for Google Drive.
And this time we want as an action we want to download the file right.
So click on that.
So we want to download a specific file and the operation.
We want to leave it as it is.
So download.
You can also copy a file, create from text, delete, etc..
As you can see, after connecting this Google Drive node into our trigger node, the fetch data comes
through.
So we have it as an input now.
Now this is very important because we don't want to select a specific file from from a list.
So from our Google Drive we want to do it dynamically.
So every time when we add a new file into our Google Drive folder it will be a different file.
Right.
So we need to add the file ID.
So let's search for filed and we should find it.
Add the spices.
So let's search for this spices object.
And as you can see here under spaces, we have our field.
And the name of this file is exactly what we are looking for.
So our iOS 18 all new features September 2024.
So let's simply drag this ID and drop it right here.
So now as you can see we successfully mapped the file into this field.
So that's it for this note.
Now let's move on.
Yes.
So we simply used the dynamic ID coming from uh this note node output to the ID field to download the
correct file using this node.
So now let's uh just rename this node to.
Root file.
And also let's rename this workflow to to vectorize data.
From Google or from Drive the Pinecone, because we are going to use pinecone as our vector database.
And we are going to vectorize files we store in our Google Drive folder to the Python vector store.
Now the next step is to load this file into our vector database.
So I really like pinecone vector database for rack agents.
So before we add a new node go to Google and search for Python.
Login or sign up if you don't have an account yet I'm going to log in.
And as you can see, pinecone is a long term memory for AI.
You can start building for free.
So basically you can build at least a few rack agents for for free without paying the monthly subscription,
which is really great for testing purposes.
Now, once you log in, what you need to do, we need to create a new index.
As you can see, I already have a couple of indexes, but for you it will be it will be completely empty.
So I'm going to create new index, give it a name and a ten like agent.
And the next thing is to configure our index.
So what we need to do we need to choose text embedding.
Very small model.
This is most cost effective OpenAI embedding model.
This is really important because we are going to use the same embedding the same embedding model in
our Na ten application.
So click on that and create index.
Now the index has been successfully created and you don't need to worry about those details, but it's
useful to know that the dimensions means that each text is stored as a list of 1535 numbers that capture
its meaningful for smart searching for our agent.
Now, the next thing we need to do, we need to create our API keys.
So click on this API key section.
Create new API key.
Give it a name.
My case is an agent create key.
Simply copy it and let's go back to N810.
Now what we are going to do we are going to search for pinecone.
So we want to add a pinecone vector store.
It.
Of course, as the action, we want to add a document to a vector store.
So click on that.
Now we need to connect to our pinecone account.
So let's create a new credential.
Create new credential.
And let's face the API key we just created and hit save.
As you can see credential successfully created.
So let's close it for now.
Now feel free to use other vector databases so you can use different vector stores for example Supabase.
So let's just quickly connect these nodes.
And if you want to use other providers you can search for vector.
And here we have simple vector store.
We have a quadrant we have supabase.
But for RAC agents I really like to use pinecone.
So I'm going to stick with that.
Now of course we need to configure this node.
So let's open it.
And the operation mode is of course insert documents.
So we are going to leave it as it is.
And now you have to.
And now we have to select the pinecone index we have just created.
So from the list I have created an agent.
So I'm going to choose this one.
You can leave embedding batch size as it is.
And now we have to add the namespace.
You can add the namespace directly in your Python account under databases right here.
But I'm going to add the namespace in N810.
So in this node I'm going to add option and Python namespace.
And I'm going to call it rack agent.
Right.
That's great.
Now let's close it safe.
Now let's test our workflow.
As you can see, we got an error because we have to add Embeddingmodel and we have to add document loader.
So let's open it.
But we successfully downloaded the file.
We add it to our Google Drive folder.
So now let's close it down and let's add the Embeddingmodel.
I really like OpenAI's embeddings models.
So I'm going to choose this one.
And here you have to ensure that the model you are selecting is the same model we use in the Python.
So it was text embedding free small model.
You have also access to the large model and Ada 002.
Also make sure that your OpenAI account is connected.
And that's it for this node.
So let's close it down and move on.
Now we have to add document.
As you can see, we are going to use the default data loader.
So we want to load data from previous step in the workflow.
So in that case from the download file.
So let's choose this one.
And as you can see as the input we fetch the iOS 18 file.
And this is in the PDF format.
So you can view it just by clicking on this button.
This in JSON format the table schema.
So we downloaded the file in a PDF format.
So this is not the JSON format.
So we need to change the type of data.
It's going to be binary.
So we want to process the binary data from the previous node.
So let's click on that.
Yes.
So we are using the PDF, uh, document in this example.
We can leave mode as load or input data.
You can also switch over to load specific data if you want to.
So this is this will be load data from a specific field in the parrot agent or chain which is a little
bit more complicated.
So let's stick with that.
And as a data format you can leave it as it is.
So automatically detect by Mime type.
But you can also switch to the PDF because we are using the PDF document.
So load PDF document.
Yes.
So if you want to sometimes upload different type of documents such as docs or uh, CSV files into your
Google Drive folder, you can use this option.
But in that case we are going to use PDF.
Now let's close it down.
Now next we need to add the text splitter.
So we are going to use the accuracy for character text beta which means that it will split text into
chunks by characters recursively.
And it's recommended for most use cases.
I recommend using it for RAC agents for better accuracy.
So we are going to use this one.
Now what this recursive character text splitter does is it breaks long text into smaller chunks so they
can be processed or embedded properly by LMS.
So no overlap means each chunk is separate and does not share text with the next one.
So for this size of document, around 900 characters um with an overlap of 50 works really well.
So it keeps each chunk short enough for processing, while the overlap helps preserve context between
chunks, which is great for better search and retrieval accuracy.
So here we are going to enter 100 and check overlap 50.
Now let's test it and see if we are able to upload this file into our vector store.
So let's close it.
Let's hit save.
And let's go quickly back to our icon.
When you click on this index, as you can see there is no records yet.
And the record is an object to add to an index which contains vector and some metadata.
So now when we go to our workflow and click on Test Workflow, it should populate our namespace with
the vectors.
So it should split the document we uploaded into our Google Drive folder.
As you can see, it keeps executing because it's waiting for us to create an event in Google Drive.
So to upload the new file into our Google Drive folder.
So what I'm going to do I'm going to pin the data.
So let's stop it.
I don't need to upload a new file into our Google Drive.
So I'm going to pin it.
Oh, it actually successfully vectorize our file and added it to our Python vector store.
As you can see we have a ten hits now.
So as you can see our document has been splitted and embedded into our vector store.
We have 80 documents.
And just to confirm as you can see we have 80 items as an output from our Python vectors to node.
So we successfully downloaded the file from our Google Drive folder.
So what we have done here is the automation was triggered when a new file was added to our Google Drive.
It downloaded the file, then passed it to the default data loader to extract the content.
That content was split into smaller chunks using recursive character text beta.
Those chunks were then sent to OpenAI to generate embeddings.
And finally, all the embeddings were stored into in our Python vector store for semantic search.
So our agent will be able to go through those embeddings and do semantic search technique to retrieve
the most relevant information based on the questions from the user.
Naturally, you will want to upload more than one file into your Google Drive to improve the knowledge
base for your RAC agents.
So if you are planning to add more data inside your Python vector store.
So Python vector database for example.
So let's say Apple just released a new version of this document.
And he would and he would probably want to drop that into your uh drive folder.
So there is a way to keep everything more organized and easy to track.
So you can attach metadata in any workflow.
So that way, once the document is stored in your vector database, you will see the actual file name
right here.
So this is super useful for staying organized.
So I will show you how to set that up in a second.
But also quick tip if you are using your RAC agent to handle completely different topics and unrelated
documents.
It's a really good idea to create separate namespaces for each category.
So for each, for each project.
So now if you want to add um metadata go to default data loader node.
Under options.
Add option.
Add metadata.
Add property.
Give it a name.
So I'm going to call it Apple.
And you have to drop here the name of the file to fill out this dynamically.
So switch to switch over to mapping.
Then go to schema.
Look for spaces.
And right here we have a name.
Let's let's drag it and drop it right here.
So as you can see it's all green and results.
We have a name.
Let's close it.
Just unpin this data.
Let's save it.
Now go to pinecone.
I'm going to delete this, uh, namespace.
So delete that agent.
And delete namespace.
And I'm going to run this workflow once again.
So now I'm going to upload the same file to.
My Google drive.
So new.
Upload.
Now let's go back to our workflow.
So you need to make sure that your workflow is active.
So that way our that way our trigger will watch our folder.
So let's make this workflow active.
Confirm I uploaded the file twice.
As you can see two uploads complete.
Now we will go to executions.
You can see that it successfully uploaded the file.
It's all green so there is no any errors.
Now let's go to our pinecone vector store.
As you can see, we have a record of 160.
So let's open it.
Go to the browser, refresh it.
And now you can see that the metadata has been added.
So I can see the exact name of the file I just vectorize to my vector store in Python.
All right.
Great.
So yes, if you want this automation to run every time you drop a new file into your Google Drive folder,
make sure to activate your workflow.
And once it's active, it will automatically pick up new files, process them, and store them in your
icon vector database.
We built our RAC agents knowledge base using pinecone.
Now every time we add a new PDF file like the latest iOS 18 features to our Google Drive, the knowledge
base updates automatically.
So now we are going to build an actual chatbot that uses this knowledge to answer questions.
So by the end, you will be able to ask your chatbot anything from your uploaded document and get clear,
accurate answers.
Now, before we dive into building the chatbot, there is something very important to keep in mind about
how vector databases like pinecone work.
So even though they are super powerful for storing and searching through document data.
They are not unlimited.
So over time, as you keep uploading new documents, your database can start to get cluttered or even
hit storage limits depending on your plan.
So it's a good idea to keep things clean and well organized.
So don't just dump in every single file you ever created, especially if they are huge PDFs with images
or unstructured content, because that kind of data is not ideal for llms to to work with anyway, and
it can make responses less accurate.
So instead, try to keep your documents, uh, relevant, uh, concise and well formatted.
So if you are no longer using certain data, it's totally fine and recommended to remove it from the
vector store to make room for new updates.
So.
So now let's move on and start building the actual agent.
So creating workflow.
Then we need to add our first note, let's show.
Let's add the agent to search for an agent.
Now let's close it.
Let's add our chat model.
So we're going to use OpenAI model GPT four.
I recommend to use GPT four for more accuracy.
All right.
So make sure you OpenAI account is connected.
But it should be automatically connected if you set up your credentials in the workspace and in the
project.
So let's close it for now.
Now we need to give our agent clear instructions on how to respond.
So let's configure this node.
Now let's add system message.
So here we have to add our prompt.
Let's switch over to expression mode and expand the editor.
I'm going to paste the prompt I have prepared earlier.
You can simply create the prompt with the help of ChatGPT or cloud, or you can modify this one.
This is just a template for you.
So let's say we can improve it.
So you can say this is the role.
So you are an assistant trained to answer questions specifically based on the iOS 18 feature documents
stored in the Connected Vector database.
And as the objective.
Your job is to help users clearly understand the new features, settings, and changes introduced in
iOS 18 by retrieving and referencing only the information available in the documents stored in the vector
store.
The user asks something that is not included in the uploaded content, or if the answer is not clear
from the available data, let them know that the information is not currently available and also we
can call it rules.
So be clear and direct.
Avoid Overexplaining I would say also use 3 to 5 sentences.
Now with bullet points or short paragraphs when listing multiple features.
If a feature only applies to certain devices or release phases like beta stable, make them clear.
When mentioned in the comments, you can just remove it.
Never guess or assume.
Stick strictly to what's inside the vector database content.
This is really important and my objective If is deliver helpful, accurate and easy to understand answers
about the iOS 18 using only the documents, let's say answers using only the documents available in
the vector store.
So no speculation, no extra assumptions, and no external sources.
All right.
Brilliant.
This prompt should work perfectly fine.
Now let's close it.
Now, to make our agent interactions feel natural, let's add a memory.
So let's add simple memory.
And let's set it to the last ten messages.
So now your agent will really remember context.
All right.
Great.
So for example, without memory, the agent will forget details immediately.
So When I say hi, my name is Damien and then ask, what's my name?
The chatbot will not be able to answer this question, but once he added the simple memory, it will
be able to remember my name.
So now when I test it and I open the chat.
Hi, my name is Damien, I like dogs.
Hi, Damien, it's nice to meet you.
If you have any questions about the new features or changes in iOS 18, feel free to ask what's.
My name?
What animals I like.
You mentioned that your name is Damien and that you like dogs.
All right.
So great.
This is how the memory works.
So this is great.
And and because of the memory, you can sometimes feel that you chat with the real human.
Okay.
So let's close it for now.
Next thing we need to connect the vector database.
So our agent can pull information directly from our documents.
We just vectorized and load it from our Google Drive folder into our pinecone vector store.
Actually, let's check if I ask our agent to about anything included in the iOS 18.
Features document.
It will be hallucinate or just state that is not able to answer these questions because it doesn't have
this information, access to this information as we want because we just added it to our prompt.
Right here.
So if a user asks something that is not included in the uploaded content, etc..
So now let's test our agent again.
Let's ask it about.
What's in the playground.
Let's copy it.
As you can see, the information about the playground is in iOS 18 is not available in the documents
I have.
And this is what we expect because we have not connected our pinecone vector database to our agent.
So now we are going to now we are going to add a tool.
We're going to add the search for vector.
And this is the tool we are going to use.
So vector store question answer tool.
So it answers questions with a vector store.
So simply add it and let's configure it later.
Now what we need to do we need to add the vector store.
We just we have created in the previous steps.
So we are going to add our vector store.
If you have created your own vector store earlier it will be connected automatically as operation mode.
We want to retrieve documents as a vector store for training tool.
So we are going to leave it as it is.
And here we are going to select our Python index.
So it was an RAC agent in my case.
Okay great.
So now as you can see you also need to add embedding model.
So we are going to use OpenAI embedding model.
The same you used for our Python vector store which is text embedding free small model.
Close it.
Now you have to add our model.
So I'm going to use GPT for all.
I'm going to switch to GPT for all.
Okay great.
And now we can configure this node.
So now we have to give it a name.
So let's call it iOS.
18.
And also the name of this node will be the same to name it.
And here we have to specify when we want to call this tool by our agent.
Now we have to add the description of the data.
So when you hover over for this question mark you can see that we need to describe the data in the vector
store.
So this will be used to fill this tool description.
So we can say something like I'm going to enter into the expression and useful for when you need to
answer questions about iOS 18 finds and returns the most relevant information from the documents in
the vector database like features, update settings or changes in the new iOS version.
Whenever you need information about iOS 18, you should always use this tool.
All right.
Great.
So now let's close it.
Let's save it.
Now the best format for Llms, especially when they are doing semantic search through a vector databases,
is actually marked down.
So that's the most LM friendly Structure.
As you probably remember, we're currently using a PDF.
And while PDF is not the perfect format for our agent, it will still work completely fine in this setup.
That said, we can improve the accuracy and relevance of the responses by taking one extra step.
And that's, uh, specifying the pinecone namespace we created earlier in our vector store.
So setting the namespace will help the agent stay focused on just the right chunk of data, and avoid
mixing it with unrelated information if you are using multiple sources.
So if you don't remember the name of the namespace you created, just go to your pinecone vector store
and the namespace.
And under namespaces you will see the name of the namespaces you created.
So mine is rug agent.
So now what we need to do we are we need to go to the pinecone vector node at option and add pinecone
namespace and type the name of the namespace you created.
As you can see, the partition the records in an index into namespaces.
So mine is RAC agent.
All right.
Awesome.
Now let's test our agent.
For that let's click save.
Let's open the chart.
And now let's ask the same question.
As you can see uh, now it is able to answer our question.
So Image Playground in iOS 18 allows users to create and manipulate images through various tools and
options, including creating images, generating images, saving sinking creations and so on.
Now you can go to our document and check if it's true or not.
Yes, you can see it's correct.
All right.
Awesome.
So let's close it.
All right.
So now I'm going to show you how to share your agent with other people so they can start using it too.
So first make sure your agent is set to active.
Otherwise it would work for anyone outside your account.
So just toggle it from inactive to active and you are good to go.
And confirm it.
Next click on your one chat message received trigger note and and then you have to make the chat publicly
available.
And here is the link you can share.
So now you can copy this link and share it with clients team Members or embed in, uh, or embed it
on a website so they will be able to open it in their browser.
Ask questions and interact with your agent just like you do.
So let's copy this link and see how it looks like.
I'm going to paste it to my browser.
And voila!
As you can see, you can interact with your agent right here.
You can of course change the initial message.
So when you go to N810, you can modify the initial message right here.
And you can make it look nicer.
And I'm going to show you exactly how to do that in one of the upcoming lessons.
So stay tuned for that.
You have successfully built your first rack agent.
You now have a fully working AI chatbot that can search your documents and answer questions using real
data.
So this is a huge milestone.
So congrats again and see you in the next episode.