1 00:00:00,06 --> 00:00:02,05 - [Instructor] In this lesson, we'll build a simple 2 00:00:02,05 --> 00:00:04,08 knowledge retrieval workflow from scratch. 3 00:00:04,08 --> 00:00:08,00 This is the first tool our agent will be able to access. 4 00:00:08,00 --> 00:00:11,05 Create a new workflow, 5 00:00:11,05 --> 00:00:17,06 and let's name this, knowledge tool. 6 00:00:17,06 --> 00:00:20,08 So quick heads up, this is a very lightweight example. 7 00:00:20,08 --> 00:00:24,01 Perfect for short documents with just a few pages 8 00:00:24,01 --> 00:00:26,03 that don't require a complex RAG, 9 00:00:26,03 --> 00:00:28,08 retrieval augmented generation setup. 10 00:00:28,08 --> 00:00:30,03 For a full retrieval setup, 11 00:00:30,03 --> 00:00:33,08 see my other course, build a custom chat bot with n8n. 12 00:00:33,08 --> 00:00:36,02 The goal of this workflow is to grab a file 13 00:00:36,02 --> 00:00:39,09 from an external source, in this case GitHub. 14 00:00:39,09 --> 00:00:41,07 Let's see our file. 15 00:00:41,07 --> 00:00:44,05 Navigate to tools, 16 00:00:44,05 --> 00:00:47,05 knowledge, docs, 17 00:00:47,05 --> 00:00:50,07 and then the conference details markdown file. 18 00:00:50,07 --> 00:00:54,04 So this is the file we want our agent to be able to query 19 00:00:54,04 --> 00:00:57,07 to get information about our conference as needed. 20 00:00:57,07 --> 00:01:00,00 So let's head back to n8n 21 00:01:00,00 --> 00:01:03,06 and start with a workflow trigger. 22 00:01:03,06 --> 00:01:10,05 We want to choose when executed by another workflow. 23 00:01:10,05 --> 00:01:12,07 For input data mode, make sure you select 24 00:01:12,07 --> 00:01:15,02 define using fields below, 25 00:01:15,02 --> 00:01:20,09 and then add one field, which you call question. 26 00:01:20,09 --> 00:01:23,04 Make sure type is set to string. 27 00:01:23,04 --> 00:01:25,03 Click execute step. 28 00:01:25,03 --> 00:01:27,03 And as you can see, this is currently empty. 29 00:01:27,03 --> 00:01:29,02 Now we want to pin a simple test question, 30 00:01:29,02 --> 00:01:32,02 so we can actually use that during development. 31 00:01:32,02 --> 00:01:35,02 Hit edit, 32 00:01:35,02 --> 00:01:41,02 and then enter a small test question like 33 00:01:41,02 --> 00:01:44,07 what halls are available. 34 00:01:44,07 --> 00:01:48,03 Hit save, and you can now see that this data 35 00:01:48,03 --> 00:01:50,06 is pinned for test executions. 36 00:01:50,06 --> 00:01:51,09 Great. 37 00:01:51,09 --> 00:01:55,05 Next, let's close this and add the next node. 38 00:01:55,05 --> 00:01:57,08 So next, let's add a node to GitHub 39 00:01:57,08 --> 00:02:00,02 so we can download our documents. 40 00:02:00,02 --> 00:02:03,02 Search for GitHub, 41 00:02:03,02 --> 00:02:05,04 and then select list files. 42 00:02:05,04 --> 00:02:08,01 Here make sure you're connected to a GitHub account. 43 00:02:08,01 --> 00:02:09,04 If that's not the case, 44 00:02:09,04 --> 00:02:10,09 just click this little dot drop menu, 45 00:02:10,09 --> 00:02:13,01 click create new credentials, 46 00:02:13,01 --> 00:02:15,01 select this one OAuth2 47 00:02:15,01 --> 00:02:17,02 and select connect my account. 48 00:02:17,02 --> 00:02:19,02 Make sure you already logged into GitHub, 49 00:02:19,02 --> 00:02:22,02 and then you should see this success message. 50 00:02:22,02 --> 00:02:24,03 Let's close this window for now 51 00:02:24,03 --> 00:02:28,08 and then put your own GitHub username in this field. 52 00:02:28,08 --> 00:02:33,09 Next, select the forked repository here from your list. 53 00:02:33,09 --> 00:02:36,07 Then we put in the path to our knowledge documents. 54 00:02:36,07 --> 00:02:38,07 In this case that's 55 00:02:38,07 --> 00:02:46,00 tools/knowledge/docs. 56 00:02:46,00 --> 00:02:51,01 Hit execute step. 57 00:02:51,01 --> 00:02:55,04 Let's fix the typo here. 58 00:02:55,04 --> 00:02:58,00 Hit execute step. 59 00:02:58,00 --> 00:02:58,09 And there we are. 60 00:02:58,09 --> 00:03:00,06 So you should now see the markdown document 61 00:03:00,06 --> 00:03:02,02 listed here on the right side. 62 00:03:02,02 --> 00:03:03,04 Let's close this window. 63 00:03:03,04 --> 00:03:07,00 And next, let's add a node to download this file actually. 64 00:03:07,00 --> 00:03:08,07 We don't have to insert everything manually, 65 00:03:08,07 --> 00:03:12,08 just duplicate this node 66 00:03:12,08 --> 00:03:14,05 and let's wire them up. 67 00:03:14,05 --> 00:03:18,06 Open this one, and instead of listing file operation, 68 00:03:18,06 --> 00:03:21,09 now select Get. 69 00:03:21,09 --> 00:03:24,08 We now have to replace the file path with the file path 70 00:03:24,08 --> 00:03:27,08 of the actual document. 71 00:03:27,08 --> 00:03:31,03 We can simply pull that over from here. 72 00:03:31,03 --> 00:03:33,02 And there we go. 73 00:03:33,02 --> 00:03:34,00 That's it. 74 00:03:34,00 --> 00:03:36,01 Just hit execute step. 75 00:03:36,01 --> 00:03:37,08 And you should see that we have now downloaded 76 00:03:37,08 --> 00:03:39,05 this markdown file. 77 00:03:39,05 --> 00:03:41,08 So let's close this. 78 00:03:41,08 --> 00:03:43,08 And since this is a binary file, 79 00:03:43,08 --> 00:03:50,00 let's now extract the text from this file. 80 00:03:50,00 --> 00:03:53,05 Search for extract from file, 81 00:03:53,05 --> 00:03:58,01 and then select extract from text file. 82 00:03:58,01 --> 00:04:02,01 We can leave the standard settings here, hit execute. 83 00:04:02,01 --> 00:04:04,02 And there you see, this is our file content 84 00:04:04,02 --> 00:04:06,05 in plain text format. 85 00:04:06,05 --> 00:04:07,09 So what do we do with this? 86 00:04:07,09 --> 00:04:10,03 We now feed in this entire text file into 87 00:04:10,03 --> 00:04:14,01 the context of an LLM, so the LLM can then answer questions 88 00:04:14,01 --> 00:04:18,02 based on that information. 89 00:04:18,02 --> 00:04:19,07 In this case, we don't need an agent, 90 00:04:19,07 --> 00:04:21,08 we just need a call to a simple model. 91 00:04:21,08 --> 00:04:26,04 So look for Gemini and select this Google Gemini node. 92 00:04:26,04 --> 00:04:29,02 This will allow us to message a model 93 00:04:29,02 --> 00:04:32,03 and just send text to it and get some text back. 94 00:04:32,03 --> 00:04:35,01 Select message a model, make sure it's connected 95 00:04:35,01 --> 00:04:37,06 to your Gemini API key. 96 00:04:37,06 --> 00:04:41,02 The resource should be text, operation is message a model. 97 00:04:41,02 --> 00:04:43,01 And then let's pick a model from list. 98 00:04:43,01 --> 00:04:46,02 We are also using Gemini 2.5 flash here. 99 00:04:46,02 --> 00:04:49,09 These models support context windows up to 1 million tokens. 100 00:04:49,09 --> 00:04:53,01 So there's plenty of text you can put in here. 101 00:04:53,01 --> 00:04:55,09 Now, as a prompt, we want to insert the question 102 00:04:55,09 --> 00:04:58,02 that we got at the beginning of the workflow. 103 00:04:58,02 --> 00:05:02,06 Let's pull that over and you can see the user 104 00:05:02,06 --> 00:05:05,02 asks now what halls are available. 105 00:05:05,02 --> 00:05:07,03 And to answer that, of course, we need the context, 106 00:05:07,03 --> 00:05:09,06 which is the document information. 107 00:05:09,06 --> 00:05:14,03 And to do this, let's add options, the system message, 108 00:05:14,03 --> 00:05:16,01 and you can see the system message prompt here. 109 00:05:16,01 --> 00:05:19,04 Let's make this a little bigger and leave this open 110 00:05:19,04 --> 00:05:22,04 and go to our GitHub repository. 111 00:05:22,04 --> 00:05:26,07 So in here, under tools, knowledge, 112 00:05:26,07 --> 00:05:29,07 you will see the knowledge system prompt text file. 113 00:05:29,07 --> 00:05:32,09 This is a pretty short system prompt to just prompt the LLM 114 00:05:32,09 --> 00:05:35,06 to behave like a Q&A chatbot in this case. 115 00:05:35,06 --> 00:05:36,09 So given a question, 116 00:05:36,09 --> 00:05:40,05 it'll provide an answer given the provided document. 117 00:05:40,05 --> 00:05:42,08 So let's copy this one. 118 00:05:42,08 --> 00:05:48,03 Go over here and put it into the system message. 119 00:05:48,03 --> 00:05:49,01 There you go. 120 00:05:49,01 --> 00:05:52,04 So this is how the system message right now looks. 121 00:05:52,04 --> 00:05:56,00 It contains the original prompt and our information here 122 00:05:56,00 --> 00:05:58,08 because it pulls that from the previous node. 123 00:05:58,08 --> 00:06:00,05 Now, let's try this out. 124 00:06:00,05 --> 00:06:03,01 Click execute step. 125 00:06:03,01 --> 00:06:05,01 And you can see the answer to our question 126 00:06:05,01 --> 00:06:08,00 that the convention center features two, exhibition halls 127 00:06:08,00 --> 00:06:09,07 A and B. 128 00:06:09,07 --> 00:06:11,05 Great, the heavy lifting is done. 129 00:06:11,05 --> 00:06:14,00 What's remaining now is to return this information 130 00:06:14,00 --> 00:06:15,09 in a nice and clean way. 131 00:06:15,09 --> 00:06:22,05 So what we wanna do is to add a simple set field node 132 00:06:22,05 --> 00:06:26,07 where we define a field that is maybe named response, 133 00:06:26,07 --> 00:06:31,02 and it contains the text value from the LLM. 134 00:06:31,02 --> 00:06:32,07 Execute this step. 135 00:06:32,07 --> 00:06:36,02 And you can see this is the output of our whole workflow. 136 00:06:36,02 --> 00:06:37,06 So if we zoom out a little bit, 137 00:06:37,06 --> 00:06:41,05 what this workflow is doing is it takes a question 138 00:06:41,05 --> 00:06:44,00 that is coming in, it pulls information 139 00:06:44,00 --> 00:06:45,02 from an external file. 140 00:06:45,02 --> 00:06:46,09 In this case GitHub. 141 00:06:46,09 --> 00:06:49,02 The model will generate the answer, 142 00:06:49,02 --> 00:06:51,00 the question given the information, 143 00:06:51,00 --> 00:06:54,05 and then it returns the answer as a simple text response. 144 00:06:54,05 --> 00:06:57,00 And that's exactly the answer that our agent needs. 145 00:06:57,00 --> 00:06:58,08 When it asks a question to their tool, 146 00:06:58,08 --> 00:07:00,02 it gets the answer back. 147 00:07:00,02 --> 00:07:02,03 In the next video, we will give our agent 148 00:07:02,03 --> 00:07:04,00 access to this tool.