Building a Global HR Policy Assistant with GraphRAG: A Beginner’s Guide - Puneet Garg
About this talk
This talk explores the use of knowledge graphs and graph databases, particularly focusing on Neo4j, to enhance AI applications. The speaker discusses the vital role of relationships within data and how they can be represented as nodes in a graph to discover hidden connections. The presentation highlights the construction of a contextual graph, layering it with semantic information to enrich the data. Additionally, the speaker introduces the concept of an HR policy assistant, showcasing how unstructured and structured data can be integrated into a knowledge graph for better query handling. Emphasizing the importance of context and explainability in AI, the talk details how hybrid search techniques can improve data retrieval from these knowledge graphs.
Full transcript
We'll be covering on the the graphs, knowledge graphs, uh graph rack. You have been hearing a lot in the when when we are implementing the AI, yeah? So, I want to touch base on that plus then we'll be jumping on to the recent blog post I published on the HR policies assistant. So, how you will be able to build it using the graph rack, how you will
be build your knowledge graph, and then the agent using the Neo4j technologies. So, when I see right now here, all I see the rows and columns, yeah? Um uh that's how uh I was started my career like the rela- relational databases and all. So, what's missing here is that the relationships. Those are the hidden relationships, and they are ready to discover. That's how I see it. if
I will start connecting all of you in the graph, we call it nodes, so you are like nodes. Um everybody has their own attributes like the name, first name, last name. What I'm doing [snorts] here is just to make a uh basic graph. All I'm just connecting who is sitting next to each other. That gives you the core graph. So, you are already in a graph. That's
That's how I see it. You will be You will be connecting. So, what happens next is once you have the core graph, just a second. Yeah. Once you will start filling more Now, what I'm doing is within within each of those of you you some somebody might have joined the same college alumni and colleagues and what not. So so many so many of those relationships gets discovered
when you put that into the graph. So that is what I'm doing what I'm doing is here is the I am providing the more context in the form of relationships. How I am discovering it. So that makes this core graph the contextual graphs. Then after once you have that what I'm doing is semantic layer. I'm I am adding more relationship and more information in the form of
um two people Priya Vikram uh they they they like graph red. They are into the fintech industry. This is based on like based on we are in the IT conference and semantic like technology technology interest and industry interest or working industry. Those are the semantics of that graph for that domain. Yeah. So that is what we are doing. We are connecting them. So now you see that
we are able to connect more and more in the graph in the form of more bringing the relationships that brings the more deeper context among two people. Then after what I did is into this semantic graph I have added the agentic memory layer as well. So I was sitting in the the the speaker lounge and then two of the participants were were were part of the QA
panel. So that's how their relationships are getting connected. They are they are at the QA panel at 2:00 p.m. And that is what they are sharing a demo. And then there could be a possibility two people were talking and they They they they found a common interest about the graph rag. And they want to have a follow-up like right now after this session, some of you might
want to connect with me on graph rag, more techniques, some of the problem you might be having, want to discuss more. We are adding the layer and layers to it and this gives you the scalability, more deeper context, interconnection. So, once you have this graph, think about it like today you were you just came in and you just sit wherever you wanted to sit. If I was
having this pre-context, then I could have made the sitting arrangement more exciting. Yeah? You You might be sitting near to your colleague or maybe the area of interest in the technology or the problem you are solving, then this this could have been a more interesting conversation. So, that is how I I just wanted to introduce to you in the form of how we are seeing things. So,
in Neo4j, we live by the principles graphs are everywhere. Like how I I was able to see the graphs right now with you guys. Yeah? And we value relationships. Relationships are first-class citizens. It's not like foreign key or something cuz every node knows right away who are my next neighbors and that nodes again know who is my another next neighbor. So, the traversal become lot easier and
that is what the AI needs it. It wants to go deeper and deeper not only while you are retrieving the information, but when you are reasoning and when you want explainability as well cuz for all the AI projects where we are seeing people want more and more context so they can reason about it why they bought that answer to the end customer or to the end user.
So, this is this is the graph and this is how we write the Cypher queries to retrieve the information from the graph. Everything which is entities is called the node in the graph and every interaction is the relationship and properties are like first name, last name, any any any attributes of that particular node. And this gives you the deeper interconnected data and that is the need of
the AI. Hello everyone. Puneet Garg, as he has already introduced, I have started my career as a Java software developer. I have a 19 plus of experience in engineering and sales. Currently, I am a senior AI senior solutions architect working with very large enterprises in India globally. So we are seeing lot of lot of use cases, how the how how how things are moving in the AI
space. Uh and then similar like you, I am a tech enthusiast. I was in US for 10 years. Recently, last year I moved back to India, Pune. So now, as we touched upon on to the graphs, yeah, what is context graph, normal graph, knowledge graph. There is a n number of flavors. Pretty much it's end of the day is a graph where you are interconnecting the information.
Um you are layering with your use cases, agentic memory, this, that. But now, let's talk about the AI before I jump into my HR policy blog post. So the AI journey has been so exciting in the last 2 years. We have seen LLMs coming and then we knew like they are hallucinating and they they they they they can lie about the information and what not. Then uh
there is a architectural pattern came rag, retrieval augmented generation. And that that became a very big buzzword and that is where the Neo4j vector database, all of that uh uh uh the started moving and uh provided the solution, yeah. Then the graph rag after the rag, a lot of industry experts have used that in the enterprises, and it failed on the accuracy part, and that's how they
learned like the graph rag is the best. Microsoft has published that term, and the Neo4j was the best fit for that given we are the leading uh graph database provider. And uh intelligence platform. Then the agents came um like agents like the LLMs uh the the reasoning large language models, they were pretty good in reasoning like how can I break a big task and uh chunk into
a smaller task and call the right tools and all of that that that happened. MCP came, and then uh it's it's going on like now we are dealing with the skills MD files. Every day some of the other things are happening, yeah. It's sometime very hard to keep up. What I am seeing with the big large enterprises, their focus is to build use the AI to build
the autonomous intelligent system without less human intervention, where they can have the um their their their their system can reason, collaborate, and uh with a minimal human touch. That's the end game they are looking for, and how they will be able to do it is through the data which has the accuracy. When you are retrieving the information, you are not over fetching the information and giving that
information to the LLMs. Cuz when you will you can provide the entire PDF to the LLM, and it's going to hallucinate cuz you are dumping everything to it, yeah. And context, when you are retrieving the information, it should have the right context. How we have seen the graph when two people are sitting to each other, it should have the context they are sitting next to each other
as they have interest in the graph rack. They are in the financial industry and they shared a cup of coffee or the tea over some chat. So, that makes a stronger connection and when they will be start sitting when they will be sitting near to each other, they might be able to ask better questions or like talk more deeper into it. Yeah, so that is the context
explainability. That's everybody needs it. AI is giving the answer, should I believe? Should I not believe to it? So, the explainability graph is the natural fit for it cuz that's how we see the information. It's not like table and columns and you need to chart it again and do it stuff. Today in the Neo4j browser, you can just go and click on one note Puneet and then
you double click on it, it will give you all the relationships and then further how how how much you want to go, it's a natural. So, that is the that is the type of information you are going to provide to the LLM. LLM will be able to understand and reason to it. Why I bought that information and it will be able to give you the human readable
format. That's the ultimate goal. Scalability, as we have seen, we have built the core graph, then we have added more relationships to it to bring the context. Then we added more relationships to it or information or the nodes were so many stuff you can keep layering it. So, it is a scalable. You don't need to do it at the day one. It will scale based on how
you want to move with your progression of your AI project. You can also bring the agentic memory and all. There's those are the natural fits for those use cases in the form of the graph cuz then you can reason it again why I came to this decision. So, how you will do that all of that? So, your data should be AI ready and I'm just projecting the
graph model for the HR policy which I am going to show it to you is this. Where what you are doing HR policies are pure documents. That's unstructured data, yeah? Employee data is the structured data. Where you have employees, designation, its band, uh salary, and so many other things goes on. Yeah? That could be structured data. So, what you do you will for the AI, how you
are building the graph is you are building the lexical graph. This is where you are chunking your entire PDF into the multiple chunks and then you are storing the text as well as the vector of it into the chunks. Then from the chunks, you are extracting the entities and relationships. Like for an example, this is a sick leave policy. This is applicable to band four employees, yeah?
This is what you are like what is the benefit, what is the band? This is all the graph the structural information you are building out of that unstructured data. And what it is going to give you the deep dense interconnected data. So, tomorrow if I'll ask a query about like hey I am sick, I am band four employee in India, what are the policies applicable to me?
Can I build a Can I Can I Can I claim a insurance or how many extra days I am going to get? So, it's not going going to only look for the semantic information which you normally do with the vector rag. Uh it's going to look into the deeper context as well. First, it will try to find out the band four employees and then it will also
find out the sick as a benefit and then it can go into the textual data. First it will So, what you are doing you are providing more context plus you are able to filter it out the data more and more through the semantic search vector search, your text search and then the graph travels. How deep you can do it it's up to you. So, that is where
once you have the graph then you are looking for the graph rag means as simple as that rather the vector only database you are connecting to the graph database which which which is having the text, vector and the graph connectivity. So, it has a more deeper context and that thing. So, this is the how the LLM is getting the external data source, the enterprise data context for
the AI systems. Just wanted to highlight a overarching architecture how we are seeing into the big enterprise, how people are doing it. It's a two phase. One is like a structured data into the knowledge graph we have been seeing we are Neo4j is there since a more than decade. So, financial industry, supply chain industry they have been using us a lot. Yeah, cuz they have a deeper
context like where you want the people's people's friends those type of information. A graph is a natural fit. So, a structure we already know. Where is the beauty after the GenAI the LLM came is what you are able to do is like you can you use you start ingesting your unstructured data, you are chunking that data and then you are generating the embeddings out of that data
plus you are relationship. In the example I said like the benefit type, band, benefit category and all those whatever whatever whatever is a natural fit for your graph, you will extract those entities and the relationships along with those text. And that goes into the knowledge graph. So now you have a structured data and unstructured data into the knowledge graph, which is a pretty powerful story cuz you
have lot money deeper context with the interconnected data. Then you are getting the information from the knowledge graph to serve it to the user with the user query. So now you can perform a hybrid search. Vector search alone is not going to work cuz it it's looking for the nearest neighbor KNN and cosine similarity and whatnot. So here you are using the hybrid retrieval approach. You are
searching through the semantic search first, then you are filtering with the full text. Then you are also re-ranking those 10 records you have found into the similarity search using the graph like what is making more sense and only those three chunks out of the 10 chunks you are giving it to the LLM and LLM is giving you the more better accurate answers. So that's this is how
we are seeing the the architecture patterns and what you can ingest into the graph. You can ingest like vector, text, chunks, unstructured data, unstructured data, semi-structured data and whatnot. Yeah, pretty much whatever the data you want to ingest you can do it. And you the beauty is that unstructured data you can also bring the structured and plus you can connect to your structured data. Like employees, policies,
those could be structured data as you will bring into the knowledge graph. And then once you are extracting the entities, then those will start connecting to each other through the entity resolution and so many other techniques. So this is what I wanted to talk high-level like this is the best practices we are giving it to the big enterprises how you can build a robust knowledge graph. It's
not a simple like the plug-and-play. It it goes through the the the lot of phases into your pipeline. So what you do is you structure data yeah, that's fine. You are having you are doing transformation. Maybe you want to extract some graph schema and then load into the Neo4j. But with the unstructured data you have three four phases pipelines where you will do the chunking, entity extraction.
Sometime you will have a complex images into the PDFs. That is what you will extract using the OCR models and multi-modality LLMs. So that is what you will do it. You will load the data then the the critical phase is the post-processing. I will show you in a minute how I did it in the HR policies. But you will find variety of failures once you will first
ingest it. You will have to do the entity resolutions, yeah. Sometimes some information is only coming into the properties of the node not as a node. So those type of things you should be doing the post-processing and then finally you will be doing the validation as well. Then you are going to have the robust foundational graph and all you will have to do is just connect the
Neo4j MCP server and start interacting with it using the natural language uh format and it will be able to generate the text to Cypher in no time you are already there. And this is this is how the agent agentic rag you would typically see it. You have the retrievers, those are the tools. You could use the MCP server, external queries being asked and LLM is making the
decision which you are interacting with the graph database and then the information is coming. This is the typical architecture agentic react agent lang lang graph and all we are seeing Aura agent. This is I'm going to use it. Once your graph is there in the Neo4j database into our cloud hosted services then the Aura is our another service which allows you to build the agent react agent
in no time without any code. All you will be just giving some instructions and that's pretty much it. You can start exploring your knowledge graph in the natural language. this the let's build a global HR policy assistant and this is the blog post link. This is the GitHub repo. You guys can scan it. You can do it later on if you'll not be able to finish here.
But yeah, that is what we are going to build. So, this is the policy document. This is the this is this is a unstructured data where you are providing the band information, how many number of days. This could be so complex. Currently, I have global policies information. So, UK policies, US policies like the companies like big companies Infosys and all like they are all across the globe
and so many different policies. You may want to self-serving system. Let me just go to the data stress so I can I have created a Aura database already. So, this is what when you will go to the neo4j.com, you will be able to sign up for free and you can go there and what I have it right now is the GIDS session database, which doesn't have any
nodes and relationship. Yeah? So, while I'll be talking to you or for a couple of other uh stuff, let me just quickly uh run the pipeline, so we'll be able to save the time. Uh this has the example ENB. You will be able to put the Neo4j credentials after spinning up a database, and then you will have to put your OpenAI key, cuz this is what it
is doing. It is generating the embeddings plus entity and relationship extraction using the help of the LLMs. So, that that's why it is required. Requirements to text is there. We are using the Neo4j graph rate package. It does a lot of thing under the hood. You don't need to worry about it, but it has all the customizable knobs. You can do that. Um so, yeah. I am
going to run the custom pipeline. This is what more complex, and I wanted to give you the flavor of it. So, I'm just starting the pipeline, but what I'll do is I'll go into the detail here. So, this is the blog post, which takes you through the entire process of creating the agent to creating the graph uh but by the GitHub repository. So, you can go there.
So, what are we building? We are building the the the HR policy assistant for the transformation of the human capital management. Like for all the employees, all the employees related information go into a one system, talent and acquisition systems. Another goes into the compensation. Another goes into how the appraisal cycle happens. So, this is this is a big human capital management system. Every company uses it, and
you can transform that using the knowledge graph, and then you can put up a assistant to it, and that will be able to self-serve the employee most of their queries. If uh if so, that that can take up the load from the HR and that will be running 24/7 otherwise you will have to go and check with the HR. That's the complexity we want to reduce it.
That's the idea of it. Yeah, that's So, you do that. That is the problem statement and here I have provided all the how you can spin up the Aura free account, where is the GitHub repository, you need the OpenAI key and create a database instance and whatnot. And once you do that, then how is the data is connecting once you start relationship? This is how using the
classifier node like the benefit type, benefit category, your graph is going to be interconnected. We'll be having a more context to it. So, that's that's going to happen. So, this is this we already talked about it pipeline as I mentioned the PDF. You will be loading the PDF. This is all happening through the Neo4j graph right You will see in the code. You are loading the PDF,
you are chunking the PDF, then you are generating the embeddings of the PDF, then entities and relationship extraction through the guided schema. I'm just going to show you in a minute guided schema. Then you are writing to the knowledge graph, then you are doing the entity resolution cuz Apple as a company can have so many nodes when you are extracting them the information. AAPL is a ticker
symbol. Apple Inc. is another. So, you want to resolve them into a single entity cuz they mean the same. That's the single same company. So, that's the type of things you want to do it for the post processing. Then you will generate the index and and then you will do some another cleanup like the dangling nodes, the nodes those are not having any children. So, why to
keep them? Those type of cleanup you can and plus you can do the validation. So, here what I talked about is the guided schema. Uh you you are going to run this pipeline through this guided schema where you will be providing providing the property labels and whatnot. Um I wanted to show you once you will run this, this is into this knowledge graph. Uh sorry, GitHub repository.
So, this is a custom pipeline. Once you will go through it, uh you will see all the steps uh what it is doing, the guided schema, all the examples you can go through it and then start modifying it. It goes through all those steps, the steps one of PDF loader, and uh chunking, and extracting the information, and whatnot. Once you have that, one then the whole idea
is to create a agent. And how you will be able to create the agent once you have the knowledge graph, uh just to show here, this will be having now the data. Like you see the data has started loading benefit type, chunks. Uh you can explore this graph more in the interest of the time, I will jump into the uh all right agent. So, this is an
all right agent. You can like your graph database is already there. I'm using the create with AI feature. Okay. And I am going into this. I am just going to use this prompt. This is what I am going to give it to my AI. And then this is uh it contains the embeddings, embedding provider, open AI, and I am using the small. And then I just created.
So, what it is doing is it is doing two three interesting things. It is scanning the schema, the graph model which I have showed like the it has the benefit type, benefit and all. And then it is generating the tools for the react agent. So, those tools are like the find by category, find by band, find by location. All of that it is doing out of the
box. So, you don't need to do all of that. So, if you will look at it, this this tool has been generated. Like these are all the tools. So, it's doing the get benefits for band. And then it is also doing the semantic similarity search thing as well. Get policy document details, yeah. So, lot of lot of those tools are done out of the box. Like these
are all the ciphers been generated to access those things. So, you don't need to start from fresh. And after that you can install create more tools and what not. So, I will just jump into the existing tool. Sorry, assistant which I already have it. And this is how you are going to have it after you have generated through the AI. And one of the sample question we
can just ask. This is This is all is here. So, this is I'm just going to copy and paste what has been mentioned into the blog I'm I'm in India. I am band four. My stomach is hurting. Can I claim hospital bill then? Take some days rest. So, this is doing semantic search as stomach hurting. This is the sick leave type of things I need to look
into my vector chunks. And then band four is the thing we already have it. So, once you run it, you will see it is bringing It is going through multiple tools which we have already provided like the band information, country specific policies. This is all happening through the graph traversal. Then it is going for the sick leave and all those stuff in the form of semantic search.
So you are bringing more contextual information. This is what the answer it came. So it's it's gone through if you will look at the reasoning. Policy document by country. This is the graph traversal it did first and then it went by the benefits by band. Like I said like I am a band four employee. So then finally it went and did the text chunking. Similarity. So this
is this is it I GitHub repository. Please access it. The medium blog post have lot of information. It's hands-on guide. So go over it and let me know. Please connect over the LinkedIn and uh if you have any questions, queries, we We can solve it and after this session as well. If you are interested to talk more about your use case, what do you have tried and
where you are facing the issues, we can do some some some more detailed discussions. But here is the graph academy where we have lot of courses graph database as well as on the AI side of things what we are doing. And these are all the links which is going to be shared with you. And thank you. If you have any questions, let me know. >> [music]
More from this event
See all 126 talks →
AI Is Not the Risk. Architectural Drift Is - Sunil Kalkunte
17:39
Breaking the Monolith: Tesco’s Journey to Federated GraphQL with xAPI - Vishwas Chandrashekar
29:13
A Practical Introduction to LangChain4j - Venkat Subramaniam
1:01:28
Beyond the AI Models: How Lowe’s is Building the Store That Knows - Swaroop Shivaram
13:59