RAG Needs a Map: Using GraphRAG to Retrieve Connected Context — Nyah Macklin, Neo4j

AI Engineer · 52 min · 624 sentences · from YouTube's caption track

Each timecode opens YouTube at the start of that sentence. Line anchors (#s42) are the cue ids in the WebVTT, and every line carries its start and end seconds. All transcripts has every talk, and the whole corpus as one file.

  1. 00:13Hello everyone.
  2. 00:14Thank you so much for coming today and welcome to rag needs a map using graph rag to retrieve connected context.
  3. 00:23So before we get started today and I know there are people who are trickling in but before we get started today I just wanted to do a quick little poll to see who is already using rag in their pipelines regular vector-based rag.
  4. 00:34Okay cool perfect are there people who are already using graphbased rag in their pipelines.
  5. 00:39Okay
  6. 00:42got it still working on it.
  7. 00:44So I see just a few people.
  8. 00:46Um and for those who um are already using graph-based rag in their pipelines, could you explain what graph rag is?
  9. 00:56A couple sort of.
  10. 00:58Okay.
  11. 00:58People are like sort of that's perfectly okay.
  12. 01:00Um what we're going to do is for those who are new to the concept um this will be a sort of one-on-one graph rag um talk.
  13. 01:08So, if you're already an expert, this you'll already know what we're talking about just so that you can um level set.
  14. 01:14But, um all in all, I want to make sure that people know what we're going to be talking about today.
  15. 01:20So, just to shortly introduce myself, my name is Ny Mlin and I'm a senior software engineer and senior developer advocate here at Neo4j.
  16. 01:29Um my research focuses on graph theory, graph algorithms as well as uh context engineering while all trying to understand um the many architectures that are in place um to build out agents but also which architectures are best suited to break open this blackbox
  17. 01:45phenomenon um to be able to decipher and trace and explain how artificial intelligence systems work.
  18. 01:52So I um spend a lot of time thinking about AI governance and safety as well which also turns out to matter a lot when uh thinking about how your agent is making its decisions and how your agent is built.
  19. 02:03Um but I've been doing this work for about a decade now and I'm excited to bring you all bring us all back to basics to try and understand uh graph rag and so this is a graph rag 101 type of workshop for those who are newer to the concept.
  20. 02:20So today I have two incredible team members who are joining me as well as another team member who's joining me today.
  21. 02:26I have my colleagues uh Jeremy Adams Castanas who is here in the front.
  22. 02:31Jeremy's waving to everyone.
  23. 02:32If you have any questions whatsoever, please ask Jeremy.
  24. 02:35Um I also have my colleague Ryan Knight who is here I think somewhere.
  25. 02:40Oh great.
  26. 02:41Hey Ryan, great to see you.
  27. 02:43So Ryan's going to be joining me and I also have a special guest, the uh the speaker for the previous session as well, Zach, who is in the back.
  28. 02:50He's an incredible AI research engineer on the Neo Forj team.
  29. 02:53He is also here to join us and to help out with any questions that you need.
  30. 02:57So if you have any questions, just raise your hand during the uh the workshop and one of my colleagues will um will join you at your table and help you work through this.
  31. 03:07So, just a couple um uh housekeeping notes before we even get started.
  32. 03:13Today, we're going to be using this platform called Graph Academy in order to proceed through this workshop.
  33. 03:18Has anyone signed up or used Graph Academy before or even heard of Graph Academy?
  34. 03:23Okay.
  35. 03:23No, not at all.
  36. 03:24That's perfectly fine.
  37. 03:25So, Graph Academy is our completely free forever free online learning platform where you can learn about all the concepts that I'm going to be talking about today.
  38. 03:35It takes you through building out agents.
  39. 03:38It takes you through learning about agentic memory, about context graphs, if you've all heard of that phrase as well.
  40. 03:44Um, there are lots of different free courses that are online and completely available.
  41. 03:48These are not sit back and listen to a lecturer speak courses.
  42. 03:52These are handson keyboard start building type of courses.
  43. 03:56So, that's the main goal for Graph Academy and it's an absolutely excellent resource for you to use.
  44. 04:01Again, completely free at any time.
  45. 04:03So, we're going to be using that today.
  46. 04:05And what I want you all to do just so that we can start off is because we're using Graphacademy, I want you to create a Graphacademy account for me.
  47. 04:14And so, it should be a quick process.
  48. 04:15You're going to go to graphacademy.ne4j.com and then you can start to create this account.
  49. 04:23Um, and again, these are free resources.
  50. 04:25So you can take this and go um throughout your time either here at AI engineer or as you continue to learn about graph and rag.
  51. 04:34I also have a link here for all of the links that we are going to be talking about today.
  52. 04:39All of the um all of the notes that we have.
  53. 04:42I will also at the end be able to present with you all the slides from this deck.
  54. 04:47Um but um you'll go to dev.neforj.comworkshop-genai neo4j.comworkshop-genai-notes and that has all of the information that we need.
  55. 05:00I'm going to go to it right now actually.
  56. 05:03And you'll see here if I can I always have to fight with these things.
  57. 05:08So you'll see here this is what uh the document that you go to um if you actually click that link the dash notes.
  58. 05:15So here we have um a couple links that you'll see after you sign up for graphacademy.com.
  59. 05:22I also want you to create a Neo Forj Aura instance.
  60. 05:26This is our hosted cloud platform.
  61. 05:27We're doing this all for free.
  62. 05:29So please do not um uh click the instances that you're paying for.
  63. 05:33I want you to click the free instance.
  64. 05:35Um and so again remember that we're trying to do all this all for free.
  65. 05:39Click the free instance.
  66. 05:40If you want to have more um more tools in the future, then you can feel free to click the uh the professional instance or or what have you.
  67. 05:47But um we're going to create a free instance um and this will allow you to to hook up to what we are going to be diving in today, Aura agents as well.
  68. 05:56So building out or building out agents within the Aura platform.
  69. 06:01But you can see here now I know people love a good free API key.
  70. 06:06[laughter]
  71. 06:06Don't worry, I did not leak my leak leak my API key here.
  72. 06:10But we do have a um OpenAI API key that's going to give you access to be able to build today.
  73. 06:16So, we wanted to make this as simple as possible for you all and is easy to get started.
  74. 06:21So, we're giving you a free API key that you can use um in order to build.
  75. 06:25And um we do have limits on that.
  76. 06:27You can't just run up run up the bill, but um please do copy down that API key or save it on your computer.
  77. 06:35again it'll be here on this document as you view it um so that you can have access to it later but I just wanted to show off this uh this document for you all um there's some different ways in order to get started with Neoforj
  78. 06:47but that's all okay so while you all are working on um creating those instances and creating those accounts what we will do is just get started with some of the material that we're going to be talking about today
  79. 07:05and I'm just going to give you a a short primer and then we'll actually dive into what we'll be talking about in graph academy.
  80. 07:13So first of all and this will be uh something that many of you have already heard of because you're already working within uh rag and within vectorbased rag but to overcome this AI's blackbox problem right we often need knowledge itself and data itself to actually be transparent.
  81. 07:30So we can see here that we have a human view of an apple right in the center.
  82. 07:36And then we also have to the right the vectorzed view of an apple.
  83. 07:42And so for the vectorzed view of an apple you see this series of numbers here, right?
  84. 07:46It's floats for those who are engineers themselves.
  85. 07:49Um but these are not necessarily human readable and human understandable um uh vectors uh unless you've actually memorized the vector view of an apple yourself.
  86. 07:58Um but every single object you can represent both as a vector or or as data itself.
  87. 08:05Um but every single object that exists on earth can be represented here.
  88. 08:10But then on the left we see a knowledge graph view of an apple.
  89. 08:15Right?
  90. 08:15So this apple we can see that the apple itself it comes from a tree that the apple um has a specific body and a specific look.
  91. 08:24The apple is round.
  92. 08:27um this particular apple is red.
  93. 08:30Um and an apple itself is a fruit.
  94. 08:32We're not talking about the company.
  95. 08:34So knowledge graphs can make what is understood by humans also understood by machines and it creates knowledge graphs oftentimes create a fusion of both.
  96. 08:47So you're able to understand both this is both machine readable and human readable graph a view of an apple.
  97. 08:56And if you're coming in late and you don't have access to these uh the materials, Jeremy and Ryan are coming around.
  98. 09:02They have the QR codes.
  99. 09:03Um just raise your hand and they'll come around and give you the QR code for the materials that I had just had up on the slide.
  100. 09:13But most people right now you can either you'll either have your data structured as a um uh actually in structured as tables and rows or you might have your data structured in vectors like I had shown before.
  101. 09:27But if you're structuring your data in tables and rows, then you have to oftent times do a number of different complex joins on that data um in order to figure out how these rows and these tables are all related to
  102. 09:39and then we often understand that that is going to drastically slow down the performance of our application.
  103. 09:46And we can't have that especially mo most of us um deal with the uh the San Francisco mentality move fast and break things, right?
  104. 09:54just get it working halfway and then push it to production.
  105. 09:58We'll figure out, you know, we'll figure out any issues going forward.
  106. 10:01So, this is the slowest way to do things.
  107. 10:03We don't have time for that, right?
  108. 10:04We have to move fast.
  109. 10:05We have to be accurate and we have to be explainable.
  110. 10:08So, if you were to structure all of that same data in a knowledge graph, then the relationships and the connections and the groupings actually become much more clear.
  111. 10:19So now your agent can physically hop right from one node and when I say node I mean one circle to the next circle through this relationship that we see right and the line is the relationship.
  112. 10:32We can hop from one node to the next node um of information and be able to trace and explain what happened in the past.
  113. 10:40That's a massive improvement, right?
  114. 10:42Once you're being able to hop through nodes through things like agent memory, which I'm actually not going to get into in this talk.
  115. 10:48I have a whole another talk that talks that breaks down agent memory.
  116. 10:52But through this this concept of agent memory, you can now have this memory and have this context of how did that agent come to create the decision that it made in the past.
  117. 11:03And so that's that's incredible for dealing like uh dealing in regulated domains um like financial use cases.
  118. 11:11Um, y'all don't want Vibe Vibe banking, right?
  119. 11:14Nobody wants Vibe banking.
  120. 11:16You don't want your agent just having access to your money and then spending all of your money.
  121. 11:19I've seen those things happen before.
  122. 11:21But things like medicine as well, regulated spaces, legal spaces, this is where that um that uh context and that history and that memory is actually very very important.
  123. 11:32But once you have a knowledge graph representation, your possibilities for your agent to give you that explainable, traceable, and accurate responses actually become much more improved and some might say endless.
  124. 11:45So again, because this is a one-on-one workshop, I wanted to make sure that people understand the architecture of a graph-based rag system.
  125. 11:52So in a normal rack pipeline, you are not using knowledge graphs, right?
  126. 11:56in in the basic rag pipeline.
  127. 11:59Um in a normal rag pipeline, you could take a few PDFs, for example, and then chunk them and then index those chunks using a text embedding model.
  128. 12:07Um and then when it's time to query those text chunks, you get that same embedding model.
  129. 12:12Then you try to fetch the top k or top x number of relevant documents and you pass that in to an LLM.
  130. 12:19And then your LLM is going to give you back the final answer from those documents.
  131. 12:23and and that's what the pipeline looks like for that poker usually um most likely used to right but graph rag on the other hand is fundamentally it is rag but it's where the retrieval path actually includes the knowledge graph so graph rag is where the retrieval path actually includes a knowledge graph
  132. 12:44and so you'll see here the architecture is just slightly different so in the rag pipeline illustration that I showed before the normal rag pipeline did not use a knowledge graph But you see here down here, we actually have a knowledge graph incorporated into that space.
  133. 12:58So when people ask me when to use rag versus graph rag, usually I like to say that we're if you're trying to answer a question that can be solved
  134. 13:06um with a either a search engine, then uh for and that's the simplest term, right?
  135. 13:12Then vector-based rag is actually usually sufficient.
  136. 13:15However, if you want to ask a question that includes what we call these multiple hops.
  137. 13:20So we saw the act the example of a knowledge graph before we saw the nodes.
  138. 13:24If you're trying to do these multiple hops or at least three hops, then that's when graph rag actually becomes imperative because you're able to then see and able to then decipher
  139. 13:35where the agent had to um had to hop in order to get to its answer.
  140. 13:41But um if you're trying to do something for example source code analysis or if you're trying to have a supply chain question or anything that requires aggregation or concatenation
  141. 13:51of data then uh from different documents then that's when this graph rack actually be really helpful and I'm not going to necessarily knock vectorbased rag.
  142. 14:02think it is incredibly powerful for most of our use cases.
  143. 14:05But here are some of the examples where vector only um rag and vector only databases they might fall short with when it comes to these things where graph and being able to traverse nodes and get that that historical context
  144. 14:18um can be beneficial.
  145. 14:20I'm not going to go through all of these but I wanted people to be able to see where um where the differences might lie.
  146. 14:29And so all in all, when you're going to be when people ask, okay, should we use graph rag versus vector-based rag?
  147. 14:35I say that using both is actually the key here.
  148. 14:38We want to use both graph and vector.
  149. 14:40Um and uh graph we we're not saying that graph is going to completely um uh completely replace your vector layer.
  150. 14:46We're saying that if you use both, then you the benefits of both.
  151. 14:50So let's add on, right?
  152. 14:51Let's make sure that our agents are being as uh beneficial as possible.
  153. 14:55Okay.
  154. 14:56So, I'm going to pause there and we are going to go into uh Graphacademy.
  155. 15:01So, for Graphacademy, the first link, graphacademy.com, we're going to go into this workshop um.ji and what I want us to do is to we're going to skip the first few sections of this.
  156. 15:17So, um I have of course already done the course, but I can reset it.
  157. 15:22So, we're going to continue that course and what we're going to do is we're going to skip over some of this um more introductory stuff like what is generative AI.
  158. 15:30We don't need to know that.
  159. 15:31If you do need to know that, that's perfectly fine as well.
  160. 15:33Um but uh for this conversation, we're just going to skip down.
  161. 15:36We're going to skip down to the to the graph rag section.
  162. 15:40All right.
  163. 15:41So, we already went through the graph rag um the retrieval process and the differences between normal rag versus graph rag process.
  164. 15:48We're seeing that we're first of all we we see the typical process here which I already went through.
  165. 15:54You have your retrievers, your user, your application and your LLM and then your data store which is normally um a vector store.
  166. 16:02Um but then if we go down then we see a little bit of the difference um as well.
  167. 16:08And what I did want to touch upon here is this concept of retrievers.
  168. 16:12Many of you already know what retrievers are.
  169. 16:14Just get a quick hand so I don't have to go over it.
  170. 16:17Okay, well actually not as many as I thought.
  171. 16:20So that's okay.
  172. 16:20That's that's totally okay.
  173. 16:21Let's actually go over it then quickly.
  174. 16:23So a retriever is a key component of the rag process, right?
  175. 16:26A retrieval is actually responsible for searching and retrieving relevant information from your external data sources.
  176. 16:33And what I like to say, okay, let's let's make this um bigger.
  177. 16:37Thank you so much.
  178. 16:38Um what I like to say often or ways that I like to remember what retrievers are um the simple way um is that retrievers are the golden retriever, right?
  179. 16:48We we all know about golden retrievers, they like to catch balls.
  180. 16:51They like to catch things.
  181. 16:52So a retriever is some is uh if you would think of this golden retriever likes to go and fetch the necessary information.
  182. 16:59Um, and so the retriever usually takes in unstructured input like a question or a prompt like when we're using chat bots and then it searches the structured data to provide the context for the answer.
  183. 17:12And so this is just a little bit about what Neoforj specifically report supports full text search vector search and then uh text or cipher retrievers as well.
  184. 17:20And then we have a number of different data sources as well.
  185. 17:23So those data sources in uh regular rag pipelines and processes can vary um documents, APIs, knowledge graphs as well.
  186. 17:31Um but um if we were to use uh this uh this news agency chatbot for example, then the process would look like this, right?
  187. 17:40A news API is going to be used to retrieve the latest articles and headlines.
  188. 17:45The knowledge graph is then going to be used to understand the relationships between different topics um such as how they relate to each other in a historical context.
  189. 17:53And then the document database is going to store and retrieve uh articles or reports or textual information as well.
  190. 18:01So we that's just an example and a um architecture of what that could look like.
  191. 18:08But let's keep going, right?
  192. 18:10There's lots of different benefits to using graph rag.
  193. 18:12I'll touch upon this really quickly, but one of those is um having uh richer context specifically and then improved accuracy, explanability like we had actually seen within that knowledge graph.
  194. 18:23If you're able to actually um if you're able to traverse your knowledge graph um and then use that plus things like agent memory, then you can get this rich historical context
  195. 18:34that's really necessary and really beneficial for building out your agents.
  196. 18:39So, let's keep going.
  197. 18:42And then I heard a couple people um and my colleague had went through the line a little bit earlier to see like have people built knowledge graphs before.
  198. 18:49Can I get a couple hands to see has anyone built out knowledge graphs?
  199. 18:53Just a few.
  200. 18:54Okay.
  201. 18:54Just a few.
  202. 18:55Okay.
  203. 18:55A little bit.
  204. 18:56Yeah.
  205. 18:56Okay.
  206. 18:57Okay.
  207. 18:58Hello world.
  208. 18:58That's perfectly fine.
  209. 19:00No problem.
  210. 19:00This is why we're all here to learn more.
  211. 19:02Um so, uh just um making sure that we understand what is a knowledge graph.
  212. 19:07We went through this a little bit in the in the example, but a knowledge graph in general is a um organized representation of real world entities and their relationships.
  213. 19:16So if I am a node, right, I'm a circle, I'm a node, and then my colleague Jeremy is a node as well.
  214. 19:21Yes, Jeremy, we are nodes.
  215. 19:23And then we actually have relationship that we are colleagues and we are friends.
  216. 19:26So we have two different relationships here.
  217. 19:28Um but um that is that's the simplest architecture of a um of a knowledge graph.
  218. 19:35And then we can be connected to different people as well.
  219. 19:38We have our colleague Zach and then another colleague Ryan.
  220. 19:40There's so many different um ways, but that's just a represent.
  221. 19:43It's just a representation of data in its most simplest form.
  222. 19:47Um so uh what is a knowledge graph?
  223. 19:49You can see here another example of that knowledge graph.
  224. 19:52And so in the interest of time, I'm just going to skip down and we're going to get into this knowledge graph construction piece.
  225. 20:00So for everyone who's following um we're in the um knowledge graph construction section.
  226. 20:05So let's build out a knowledge graph quickly.
  227. 20:10So constructing knowledge graphs.
  228. 20:11In this lesson we'll review the process of constructing knowledge graphs from unstructured tests using an LLM.
  229. 20:18So the overall process is making sure that we're gathering data sources and then we're chunking that information and chunking that data.
  230. 20:24We're of course going to vectorize that data as well and then um extracting nodes and relationships from that and then generating the graph of course.
  231. 20:35So in this example, if we wanted to construct a knowledge graph based on the Neo Forj Wikipedia page, which we can see here, we're going to gather text from that page, right?
  232. 20:44Take all the text and then we're going to split that text into chunks.
  233. 20:47As you can see here, we would generate embeddings and vectors from each of those chunks and then extracting the entities and the relationships using an in LLM.
  234. 20:57Now, you can do that manual extraction if you wish.
  235. 21:00Um but we think that um using it in an LLM can cut down on the amount of time that it takes in order to do that extraction.
  236. 21:07Um and so we would send the LLM to with an appropriate prompt um a prompt example here.
  237. 21:13Your task is to identify the entities and the relationships requested with the prompt from a given text.
  238. 21:18And then you must generate the output um in a JSON format containing a list with JSON objects.
  239. 21:26And then we would paste oh sorry parse those um entities and relationships.
  240. 21:30the output into the LLM, paste that into as JSON, and then we would generate the graph from all of that.
  241. 21:37So, we see here we see here Cipher, which is a query language that's optimized for graphs.
  242. 21:43Has anyone used Cipher before?
  243. 21:46A couple.
  244. 21:46Okay.
  245. 21:47All right.
  246. 21:47A couple people.
  247. 21:48Um, so if you're a cipher expert,
  248. 21:50[laughter]
  249. 21:51then I have um uh if you answer some of my questions here, I have swag as well.
  250. 21:56So people as um as you are going through this workshop I want it to be more interactive than a normal workshop.
  251. 22:02So I'll be asking questions and if you're brave enough to answer one of my questions live it's also being live streamed but live then I have free uh unique
  252. 22:10swag for you.
  253. 22:12So that includes t-shirts that includes um uh special swag that you cannot get anywhere else as well socks etc but um special swag on top of that.
  254. 22:21So, um, thank you all for, uh, being willing to put yourself out on a limb and answer some questions that we might have.
  255. 22:28But you'll see here, uh, lastly, an example of a generated graph.
  256. 22:32So, we have a graph database was, uh, developed by Neo Forj, which is a company.
  257. 22:36Um, and, uh, Neo Forj didn't, uh, develop graph databases all in general, but just Neo Forj is the graph database that was developed by Neo Forj with the company.
  258. 22:46And then that's implemented in Java.
  259. 22:48And quick side note, Neo for J the name comes from Neo who is matrix.
  260. 22:52All right, those who know the matrix and then Neo for Java.
  261. 22:56So for those who have that quick little piece, you'll know that that note about Neo forj.
  262. 23:02So we can continue.
  263. 23:08Ah yes.
  264. 23:09Yes.
  265. 23:11Go for it.
  266. 23:12Yeah.
  267. 23:12Yeah, let's do it.
  268. 23:14Okay.
  269. 23:14So um because we're at half past the hour, we want you to get the most out of this.
  270. 23:18And people wanted to do building of the knowledge graph.
  271. 23:21There is a on your left sidebar it says graph rag for Python.
  272. 23:25That's right.
  273. 23:27That link there.
  274. 23:28So kind of navigate to that.
  275. 23:30That will take you if you scroll down.
  276. 23:33Um this is going to talk a little bit about the the graph rag for Python package an open source package that Neo4j provides for knowledge graph building and retrieval and agentic work
  277. 23:43and also on this page are all the credentials you'll need for all the examples we'll be using and then um Nia you want to take it away and talk about the credentials and the GitHub code space.
  278. 23:55Absolutely.
  279. 23:56So let's start off uh for let's start off.
  280. 23:59So, we had mentioned we're in the graph for Python section now and we want to um go scroll down and then click open in GitHub code spaces.
  281. 24:07Once we open that, we're um you you're going to have to sign into GitHub if you're not already, but once we open that, we're just we're going to leave all of these
  282. 24:15um uh system prompts the same.
  283. 24:17And then we're going to create the code space.
  284. 24:19It's going to take a little bit of time.
  285. 24:20So, we're going to do a little bit a couple of things ahead of um not necessarily ahead of time, but while this is generating.
  286. 24:28And so while this is generating, I just wanted to show you all that we're going to be creating this setup environment.
  287. 24:34And so we're going to create a copy of this m.example.
  288. 24:37And you can just click copy here.
  289. 24:39And we're going to actually create that um within our um code spaces section.
  290. 24:45And so this will continue.
  291. 24:48Of course, Wi-Fi is not always fun, but this will continue.
  292. 24:50Eventually, it's going to have an entire setup for the um uh for the folder structure, and it'll have a uh M.ample folder.
  293. 25:00So, we're going to instead create a M file, and we're going to paste all of these um uh um all these credentials in.
  294. 25:08And actually what we're going to do, we're not going to paste those exact credentials because what we want to do specifically is to and I had this in the notes is to create a Neo Forj Aura instance.
  295. 25:20And so I had that in the notes for us to get started on.
  296. 25:23So create a Neo Forj Aura instance.
  297. 25:25And again I mentioned we should be creating a free instance specifically for this workshop.
  298. 25:30You can create a professional instance as well.
  299. 25:32Um, but I already have one that's set up.
  300. 25:34And so this instance is um instance number three here.
  301. 25:39Um, yours should say type um aura I think or free.
  302. 25:43Um, but what we will do is that we're going to actually connect to set instance.
  303. 25:49And so um once you do create that instance actually you'll um have a the connection details that you'll be download directly to your computer so you don't lose it.
  304. 25:58And um uh what we'll do is then um connect that here.
  305. 26:04Yeah.
  306. 26:04And um so really there's a a fork in the road here.
  307. 26:08Don't feel bad if for whatever reason uh you aren't able to create the Aura instance in time.
  308. 26:14Um it'll be ideal for the last part of the exercise if you can.
  309. 26:19But those other credentials we saw in Graph Academy, they're in a a small uh free instance that's within Graph Academy itself.
  310. 26:28So you can use those.
  311. 26:30Either way, we want to have the connection details to a Neo4j database because that's where we're going to build that knowledge graph.
  312. 26:38That's right.
  313. 26:40Perfect.
  314. 26:41So, what I'm doing right now is I'm grabbing my um instance information and then I'm just going to paste that here into our um our graph.
  315. 26:51So, perfect.
  316. 26:52We see that there.
  317. 26:53And then I will also grab the open AI key.
  318. 26:56Yeah.
  319. 26:56And I'll make this bigger as well.
  320. 27:05Move this terminal down.
  321. 27:09Move this out the way.
  322. 27:11Perfect.
  323. 27:12So, we want that OpenAI key as well that we had C that we had grabbed and we'll grab that directly from the notes.
  324. 27:23So, just copy and paste the key and place it.
  325. 27:32Dope.
  326. 27:33All right.
  327. 27:33So, this will save uh if you have autosave or you have to save it yourself.
  328. 27:38And now we have this.
  329. 27:39And so once we have that M file, then we're actually going to want to test our environment really quickly.
  330. 27:44So we'll go down to um test environment.
  331. 27:47py and we'll just run this environment.
  332. 27:49You can actually if you're using VS Code and you can run it using this or you'll use run it using your um uh hopefully a Python virtual environment as well.
  333. 27:58But let's make sure we do it.
  334. 27:59Okay.
  335. 28:00So we can see down here it's trying to connect.
  336. 28:02Perfect.
  337. 28:02It ran five tests and it's positive.
  338. 28:04We're okay.
  339. 28:06So,
  340. 28:08anyone hitting a snag there?
  341. 28:10If you do, make sure you're actually you've actually created av file and you're not still just in the example.
  342. 28:17That's right.
  343. 28:18And uh you can rename the file or create a new one.
  344. 28:21And um that will essentially now we know we're connecting to the Neo4j database and our open AI key uh is successful.
  345. 28:32Perfect.
  346. 28:34So, Now um that the test environment is run.
  347. 28:40This is successful.
  348. 28:41Now we can take a look and we can see here um if you go under workshop.jai you can see here that we have a number of different solutions.
  349. 28:52So we have the d the raw data itself.
  350. 28:54We have solutions itself and then the agent and then the knowledgeraph builder and knowledger graph structured builder as well.
  351. 29:00So we're going to click on this knowledge graph structured uh builder and it's going to build out this knowledge graph right in our Aura instance.
  352. 29:08And so if you're again in VS code then we can just um p uh play that and then this process is going to take a little bit but it's actually going to generate the knowledge graph and we can see it populating live within the doj aura um aura instance
  353. 29:23and so let's go over back to aura and what I've done as well as um within here so again I'm going to connect we're going to go to query
  354. 29:37And we can see I've already done this.
  355. 29:39So I've already pre-populated it just because it'll take some while.
  356. 29:41So it's going to probably do some dduplication um based on the fact that I've already run it.
  357. 29:46Um however um all of that information is going to u populate within here.
  358. 29:52And then we can query this um and see what's uh what exists within the um within the instance.
  359. 29:59And we can see that this knowledge graph it will the more times you query you'll see um that it actually will uh continue to populate.
  360. 30:06So just right now we're just going to see what um relationships and um uh u and nodes are actually here already.
  361. 30:16So we have P and then so match P done a little syntax here.
  362. 30:39Oh, thank you.
  363. 30:41Match P equals.
  364. 30:43There we go.
  365. 30:53Beautiful.
  366. 30:57So now we can see and I'll sc I'll zoom in so that we can actually see what's going on here.
  367. 31:04But now we can see all of these different nodes and relationships just based on the data that we had um that we had ingested into the knowledge graph.
  368. 31:15And you can click on this data and you can inspect the data as well.
  369. 31:19This is not just a visualization tool, but it's also specifically a query tool, a way that you can um query your data itself.
  370. 31:27But this is the finished um knowledge graph.
  371. 31:29Your knowledge graph will be much smaller.
  372. 31:31And then the more times you run this particular query, match p equals um empty like a node actually.
  373. 31:38So empty node uh d-mpt node then return that p. Um you'll if the more times you run that, the more times you'll see that that knowledge graph grow.
  374. 31:46It's just uh in the query in general is just saying like show us all the nodes, right?
  375. 31:51Show us all the nodes and relationships.
  376. 31:56Wonderful.
  377. 31:59Okay.
  378. 32:02So once we've got that um those nodes and relationships and and uh for anyone who's having problems with that process um uh feel free to throw up your hand and we have colleagues who are who will come in and help you.
  379. 32:17Um but once you got that um that knowledge graph beginning to generate then what we want to do is actually go in and create an agent.
  380. 32:27Oh I see a couple hands right behind.
  381. 32:29Um, so you might not already see this agents um section.
  382. 32:34If you do not, let me see your hand in your um thing.
  383. 32:37Okay?
  384. 32:38But I do know a couple people probably are not there yet.
  385. 32:41Um, but if you don't see this agent section, what I want you to do is to go to your organization, your NearJ organization.
  386. 32:48Um, and then we're going to click all organizations.
  387. 32:51And what we're going to do is we're just going to enable um, Jedi um, capabilities onto this organization here.
  388. 32:58And so we're in this new organization.
  389. 33:03Then we'll go to settings.
  390. 33:04I already have it enabled, but for those who don't know how to enable it or have never used Neo forj A or before, um here we have um you're going to click these two.
  391. 33:14They'll be um they'll be grayed out, but I want you to click them in order to enable them.
  392. 33:19So generate AI assistance, generative AI assistance, and then Aura agent specifically because we're going to be building out an agent today.
  393. 33:29So, oh, got a couple hands.
  394. 33:32Perfect.
  395. 33:36So, once we have that organization, we're going to go back to our specific organization.
  396. 33:40We're going to go back to our instance.
  397. 33:44We're going to open our instance within query mode.
  398. 33:49See our agent um see our knowledge graph populating.
  399. 33:54And then we're going to click here, agents.
  400. 33:56and this agent here.
  401. 33:59So, I already have an agent here, but what we're going to do is you are going to create an agent.
  402. 34:04So, I'm going to create an agent from scratch and we're going to tie that agent to this specific instance.
  403. 34:11It should autoop populate based on the latest instance that you had created and we will configure.
  404. 34:25And so what we want this agent to do, uh, we're going to call this agent, we're going to call it a, um, uh, genai fundamentals.
  405. 34:37Um, actually, we'll call it graph rag Graph rag fundamentals agent.
  406. 34:51Perfect.
  407. 34:52And then for the description uh to describe this agent, we're going to say that this agent provides um forj graph rag information grounded in this specific graph academy course that we have.
  408. 35:25So we have this agent and again for those who are following along it's going to uh provide neo forj graph information grounded in this specific graph academy course and then lastly we're going to um provide the instruction for that agent here.
  409. 35:44So um that instruction will be that um and we can really just copy paste and what I'll do is I'll also include this in the geni notes section so that you can all see it.
  410. 35:57I'll go over to the notes.
  411. 36:04But this is an easy way to um create your agent agent description for you all so that you can copy and paste it and have your agent actually be working with us here.
  412. 36:19And if you have questions, please feel free to put up your hands.
  413. 36:22Okay.
  414. 36:23So, we'll just copy that over to our agent as well.
  415. 36:26We have the um instruction and then we're going to keep everything pretty much the same.
  416. 36:31the instance um agent location as well and then internal and what we want to do.
  417. 36:42Perfect.
  418. 36:43Is um create that agent.
  419. 36:51But actually, do we want to Yeah.
  420. 36:53Okay.
  421. 36:54So, before we create that agent, we're actually going to try and um add similarity search to it.
  422. 36:58So if you don't already have um um similarity search added to your agent or vector search or vector insects is specifically added to your agent then we actually have to do that in order for this u this prompt to come up.
  423. 37:13So you'll get a separate prompt that says um vector search is necessary in order to um to do that.
  424. 37:18So, where we get a good a good place to get that information, we're going to close out this.
  425. 37:23Oh, we can keep it open.
  426. 37:24But what we're going to do is we're going to go to um the Python um Python section.
  427. 37:32There is another let's see in the graph for Python section.
  428. 37:37Here we go.
  429. 37:38And I'm going to paste this into the uh notes for you all as well.
  430. 37:45I gotta love being in full screen mode.
  431. 37:48Come on.
  432. 37:49Come on.
  433. 37:51I'mma just I might just exit out full screen.
  434. 37:54Okay.
  435. 37:56And let me paste this for you all.
  436. 37:57So, we're going to create a vector index.
  437. 37:59So, we want to go to this link here.
  438. 38:03Create vector index.
  439. 38:06Cool.
  440. 38:07And that's what you're going to do.
  441. 38:08You want to click that link and that allows you to um that just gives you a sample code um in order to create the vector index.
  442. 38:14And I'll show you where we're going to put that information right now.
  443. 38:18So we have this create a vector index here.
  444. 38:21You're just going to copy that and then we're going to include that.
  445. 38:35So for the vector index and I'm going to ask Jeremy, do you remember where oh where we put our um vector index?
  446. 38:41Yes.
  447. 38:41Right.
  448. 38:42Right in as the cipher query window.
  449. 38:45Yes, you're right.
  450. 38:45You're absolutely right.
  451. 38:46Okay.
  452. 38:47So, let's go back.
  453. 38:54So, we'll go out of here.
  454. 38:57So, this will depend on which instance you're using.
  455. 39:00If you're using an Aura instance, you're going to go in your Aura console into the query interface.
  456. 39:06So, you might want to either open another window.
  457. 39:09Yep.
  458. 39:10So, you can leave your agent or you'll have to close your agent for a minute and go to query,
  459. 39:14right?
  460. 39:15And then you can create that vector index.
  461. 39:17So just like Jeremy had mentioned, we're going to actually paste that vector index right here in the cypher query window.
  462. 39:23And so you'll run that and then you will see that we'll um extend this.
  463. 39:29Okay, this command and this I think it's this is specifically because I had already no successful.
  464. 39:36Oh yeah, it already exists.
  465. 39:37Exactly.
  466. 39:37Because I had already run this.
  467. 39:38What you're going to do, you're going to create, you're going to run that command and then it will actually show you the vector index that has been created.
  468. 39:45So once you have that vector index already created, then you can then go into the um agent section and then uh access that prompt that we saw there.
  469. 39:56So I'm going to do the same thing again.
  470. 39:58Create from scratch, configure, and we're going to do the same thing.
  471. 40:07Graph rag.
  472. 40:07Great.
  473. 40:08Autopop populate.
  474. 40:10Beautiful description.
  475. 40:11Yep.
  476. 40:13Beautiful.
  477. 40:13And then we have that same prompt.
  478. 40:22Sweet.
  479. 40:23And then we're going to do the add tool section.
  480. 40:26Now, similarity search.
  481. 40:27Now you should be able to see this uh the same prompt.
  482. 40:32But for this similarity search tool, we're going to create this tool which will say we're going to search this lesson content and be able to actually gather insights from this lesson without having to take the lesson.
  483. 40:44Search lesson content.
  484. 40:48Um and then we have a description that I'll also paste as well.
  485. 40:57And I'll paste that.
  486. 40:58Make sure that you all have that description as well.
  487. 41:04Similarity search description.
  488. 41:12Perfect.
  489. 41:12So now it's in the notes so that you can also use it.
  490. 41:19And then we're going to select the V vector index specifically that we had just created that is chunk embedding.
  491. 41:24We're going to say we're going to use about the top five um uh as well.
  492. 41:29And then we're going to select our embedding provider that's open AI.
  493. 41:32The embedding model we're just going to use text embedding three small.
  494. 41:36It's perfectly fine.
  495. 41:37And then the default dimensions is 1536.
  496. 41:40And then we want to make sure that we are uh returning this connected graph data which is very very important especially because we're using this uh graph interface.
  497. 41:50So we're going to return this graph data and what you want to do we can use natural language here but you can also use cipher specifically but um cipher
  498. 41:59for this cipher query um we have there's a cipher query that we already have.
  499. 42:05I'm trying to remember where it is.
  500. 42:08Oh is there a light mode?
  501. 42:09That's a great question.
  502. 42:11Oh, because it is so hard to see.
  503. 42:14Yeah, let make it bigger.
  504. 42:18Awesome.
  505. 42:22So, for this cipher query, we're going to take this cipher here, and I'll make sure to paste it for you all.
  506. 42:35This is the cipher query that we're going to use.
  507. 42:47So, it's it's um Oh, actually, I should just paste the actual cipher query itself, not just a link to the cipher query.
  508. 42:55Cool.
  509. 42:58All right.
  510. 42:59So, here's the cipher that we're going to include in our agent.
  511. 43:03And what we're going to do is we're going to paste that in our Aura agent here.
  512. 43:07same cipher query don't change anything but the the point here is if you look at the cipher query we need that cipher query to include nodes you can see here nodes and then scores
  513. 43:18as well so nodes and then scores or similarity and so we can see that this cipher query specifically uses nodes and scores within its query um but this is a very helpful query and I'll also make sure that I link where we got that query as well for you small
  514. 43:37just so you can have it for later.
  515. 43:40Perfect.
  516. 43:40All right.
  517. 43:41Now, we can create this agent, right?
  518. 43:43Or we can add this specific tool.
  519. 43:47All right.
  520. 43:48So, we have everything here.
  521. 43:50We're going to use internal which is for free.
  522. 43:52Um, we have these two tools, search lesson content, and then the similarity search and then the natural language for cipher tool.
  523. 44:00And we're going to create the agent.
  524. 44:02So we can see graph fundamentals agent right here.
  525. 44:09So we no longer have to configure it.
  526. 44:12But if you need to um as we were building out that knowledge graph, you can update that agent.
  527. 44:16You can press that update agent which will take in all the information from the knowledge graph.
  528. 44:20So now we can have a chat with that specific agent and we can ask different uh questions with regard to um that agent.
  529. 44:28And I wish I can slide this over but I can't but that's okay.
  530. 44:31So these particular questions we can ask lots of different questions um and um you can now learn anything that is actually in the graph academy course.
  531. 44:40So for example, we have information about um how does um temperature for example uh affect a LLM and this will take in all the information based on the knowledge graph that we had created within Neo4j
  532. 44:58and only that information within the knowledge graph in order to um give you an answer.
  533. 45:03And I'll make sure that I
  534. 45:06Here we go.
  535. 45:06The fun thing is uh for folks that go back later and look in that data directory, you'll notice that all those PDF files were from an intro to Genai
  536. 45:15course in Graph Academy.
  537. 45:17That's right.
  538. 45:17So we trained this on Graph Academy in Graph Academy.
  539. 45:20Kind of meta but
  540. 45:21exactly it works.
  541. 45:22No, that's perfect.
  542. 45:24And like like Jeremy had mentioned, all this information is trained on Graph Academy.
  543. 45:28So you have all the information within graph academy at your fingertips here within this agent itself.
  544. 45:33But it answered that um temperature is a parameter that controls the amount of randomness in the generated text.
  545. 45:38Right?
  546. 45:39You have tire temperature, lower temperature and what that um is based on and then as well as the sources of information where you can learn more um within graph academy as well.
  547. 45:48But you don't you not only are able to ask about the content of the graph academy but you're able to do things like get that aggregated information um based on graph academy as well.
  548. 45:58Um, so we can ask questions um like how many lessons are there in this course and so usually when you're building out agents they or when you're building out rag pipelines they're often pretty bad at doing this like I had mentioned this aggregation and concatenation
  549. 46:14piece but um let's see we can see that within this specific course there are 30 different lessons and it's actually 15 lessons but it's counting 30 right now because I had rerun run the um
  550. 46:28uh the knowledge graph builder which had the initial 15 lessons and then I reran that builder which created the 30 different lessons.
  551. 46:36So if we were to um then check within Aura make sure where we are.
  552. 46:45Oh yeah.
  553. 46:46So, if we were to go back and just uh query, right, we're outside of this and we were to just like figure out how many lessons, then we could see that it would actually give us the correct number.
  554. 46:59And you can even just click on the lesson no type on the left as well.
  555. 47:03That's right,
  556. 47:04for the cheat code.
  557. 47:06So, we'll see the correct answer, which is the 15 lessons here within this space.
  558. 47:11And then the um uh the because I had reran that but I did not repopulate that within the within the thing.
  559. 47:19So it says 15 lessons which is how many lessons are in the um or within this graph academy course.
  560. 47:26So Nia I had some folks that were wondering now that we've gone kind of end to end we built a knowledge graph from some raw data.
  561. 47:34We were hooked up an agent that can use this now using graph rag combination of vector and cipher queries.
  562. 47:42They were wondering could we look at the code that does this really quick
  563. 47:47and so um could we look at the code of that knowledger graph structured builder file
  564. 47:53and just just do a quick walk through just so we see the elements of it.
  565. 47:57Absolutely.
  566. 47:58So let's go into our um knowledge graph structured builder.
  567. 48:02Perfect.
  568. 48:03So here is all the code that's that's creating and generating this knowledge graph in itself.
  569. 48:08So we're seeing and I'll try to make it as big as possible without also cutting.
  570. 48:12I would like to do a word wrap.
  571. 48:14Um
  572. 48:14I think you can hide the uh the left hand.
  573. 48:16Oh yes, absolutely.
  574. 48:19Perfect.
  575. 48:19All right.
  576. 48:20So we can see that here um that we are importing all of our necessary um uh portions.
  577. 48:26So OpenAI LLM, the OpenAI embeddings, the simple KG pipeline which is our simple knowledge graph pipeline.
  578. 48:32um as well as fixed size splitter.
  579. 48:35But we have here which is our Neo Forj driver which is pretty much your um your core and when we say driver we really do mean driver the thing that's generating all of this right.
  580. 48:45So we're connecting to our um our graph database using that Neoraj driver.
  581. 48:50It's the simplest way in order to get connected.
  582. 48:52But then we see here that we have the LLM.
  583. 48:54We're stating that that LLM is actually the OpenAI LLM that we have here.
  584. 48:58We have our embedders here as well which is those open AI embeddings.
  585. 49:02And then we are of course going to use that text splitter fix um fixed size um splitter and we have that chunk size being um 500 and then a choke overlap just in case we miss anything from those specific chunks.
  586. 49:15And then we have some sample node types.
  587. 49:17So those node types here remember nodes are the circles um and then we have relationships but the nodes here are technology concept example process um challenge and benefit.
  588. 49:28And then we have relationship types that we think are really important to this uh this knowledge graph.
  589. 49:34So these relationship types we are populating but we want those relationships to focus on this related to piece the part of used in etc. And then we can see that these patterns
  590. 49:46these patterns um which is this node relationship node pattern that we're seeing here.
  591. 49:51Um and so we have for example technology related to specific technology right or example used in specific uh technology.
  592. 50:01So then after we we've put all of that sample information we can see that this knowledge graph builder is taking in this knowledge graph pipeline and all the information in order to generate the knowledge graph itself.
  593. 50:13I mean, and that's re really a cool part here is that of course we we did Graph Academy data here and a schema appropriate for that, but most of you will be using like a bunch of documents from your business or whatever.
  594. 50:25And you can use the LLM to help you figure out the right schema.
  595. 50:28But once you got it, that using that schema like that will guide the LLM so it won't just make up new node and relationship types.
  596. 50:36It'll stick to that.
  597. 50:38That's right.
  598. 50:38Excellent.
  599. 50:39So then we can see that we're taking in those uh CS we have different CSV files within our data as well right under data a different CSV file as well as all the general PDFs
  600. 50:50from um this lesson and then it's going to parse that CSV um and then create and generate that knowledge graph all in all.
  601. 50:58So that's the background behind this builder this knowledge graph builder that's using graph rag on the back end in order to create the knowledge graph that we saw within
  602. 51:06um Aura.
  603. 51:08Perfect.
  604. 51:09All right.
  605. 51:11Yeah.
  606. 51:12Um, so that is what we wanted to show you all today um, for Genai.
  607. 51:17I'll finish off with a couple last slides and a couple calls to action as well.
  608. 51:21These are some last some benefits of using graph rag.
  609. 51:23Again, I had mentioned higher accuracy, easier development, and then explanability.
  610. 51:28But all in all, the best places to learn more about graph and graph rag is Graph Academy where you'll see all of these different um, resources completely free and hands-on courses.
  611. 51:38um cipher fundamentals if you want to become an expert at cipher um and uh building out knowledge graphs and context graphs.
  612. 51:45And then on Tuesday or yes on Tuesday of this week um we are actually going to be or Wednesday um but on July 1st we're going to be having a meetup down at the digital garage in San Francisco from 5 to 8. Please feel free to join us and please feel free to register.
  613. 52:01Just make sure you come by our booth if you want to register for that meetup.
  614. 52:04We're going to have some incredible experts within the graph and knowledge graph space including our founder and CEO Emil Efim who is going to be there and you can ask him different questions about building knowledge graphs as well as the technical team myself Jeremy Zach um we're all going to be there to answer your questions about your
  615. 52:20use cases.
  616. 52:21Um but this specific talk is about teaching the why behind decisions.
  617. 52:26So context graph decisions that are being made.
  618. 52:29And then please feel free to come by and see us at booth um P3 which is right by the Microsoft booth.
  619. 52:34Um we'll be there to answer any questions that you have.
  620. 52:37And thank you so much for coming today.
  621. 52:38We appreciate it.
  622. 52:40[applause]
  623. 52:40Thank you.
  624. 52:56[music]