GraphRAG Agent
Build Agentic Assistant using GraphRAG
This lab focuses on developing an agentic chatbot that leverages GraphRAG (Graph-based Retrieval-Augmented Generation) for enhanced reasoning and contextual understanding. You will integrate graph databases, entity relationships, and retrieval mechanisms to enable intelligent, structured, and context-aware responses.
Use Case:
Build a Graph RAG solution to analyze resumes and ask questions about candidates
Pre-requisites
S3 bucket with Resumes
Optional Setup Neo4j AuraDB.
Neo4j AuraDB link : Click on the link. You will be directed to the Neo4j AuraDB Page.
Click on Start Free.
Select the Continue with Google option. Key in your Gmail ID and Password.
In the Neo4j Aura console, Click on New Instance. In the pop-up, select AuraDB Free.
A pop-up window will appear. Click on Download and Continue (mandatory).
Wait a few minutes (it typically takes 5 to 10 minutes) before your instance is up and running.
Neo4j Aura credentials
Step 1: Create a “Graph RAG” Recipe
Create GraphRAG recipe with Resume Dataset.
Visit the link (https://app.karini.ai/recipe ).
Click on the Add new button in the top right corner.
The recipe page will open. Give appropriate Recipe name (mandatory) and Description (optional). In the Type dropdown, select Graph RAG.
A Presets pop-up will appear on your screen, asking for your confirmation to initialize your recipe with default components. Click Yes to confirm.
Recipe Parameter Settings: Once your default Graph RAG recipe is set up, configure the following parameters.
Source Tile: Provide your dataset's S3 bucket path (mandatory) with appropriate credentials. In the Label (mandatory) field, provide a suitable name.
Dataset Tile: In Preprocessing Options, under OCR Options, select Amazon Textract from the Method dropdown. Leave Tables and Forms unchecked, as they are not required for this dataset. Leave the Dataset name with a default value; you can change it if needed.
Data Processing Preferences Tile: From the Embeddings model (mandatory) dropdown, select Amazon Titan Text Embeddings V2. Enable chunking is turned on by default. Choose the appropriate Chunk size and Chunk overlap.
Prompt Tile: Redirect to the prompt playground using the icon. From LLM Model dropdown, choose Anthropic Claude 3.5 Sonnet 20241022 v2 . Leave the default settings for Temperature : 0, Max tokens:4096. Test the prompt, save the prompt run, and publish the prompt. In the recipe configuration, deselect and again select this prompt to display the version along with the associated LLM. Keep the setting All pages: True, unchanged on prompt tile.
Knowledge base Tile: Provide your Neo4j AuraDB credentials URI, Database name, User name, and password. Refer to the Prerequisites section where you set up your Neo4j AuraDB. Database and User name by default are the same neo4j , unless changed.
Click on the Central Canvas portion of your recipe page. Click on the Upload descriptor button. Download the graph descriptor JSON provided here Graph Descriptor JSON and upload it.
The Graph Editor page opens, where you can edit the JSON. This JSON will guide the LLM in Metadata Extraction, which will be populated in your neo4j Knowledge Graph as Nodes and Relationships. Once you finalize the JSON, click the Save (mandatory) button. You can click Download JSON (optional) to save a local copy of the finalized JSON.
Save your recipe first. Then, Publish your recipe.
Run your recipe. (Full Run mode)
NOTE : Dry run mode will run the recipe on a minimum number of documents , whilst a Full run mode runs your recipe on all documents in your dataset.
Step 2: Create Agent Prompts
Prompt Playground: Navigate to your Prompt Playground page. Click on the Add new button at the top right corner.
A new page will open like the one below. Click on the Highlighted arrow (in green).
Click on the Prompt Templates button.
In the search bar, type in Graphrag Resume Agent 2.0, as shown in the figure below, and select it.
Click on Use template as shown below.
Increase the Max State Updates from 3 to 20.
Add your natural language question to the Agent Input (mandatory) text box.
Finally, your screen should look like this.
The split screen mode lets you seamlessly change (LEFT) and inspect your prompt (RIGHT).
Ensure you rename your prompt as loaded from the prompt template before saving it.
Now, to set up the tools for the Agent, follow these steps,
a. Click on Tools in your agent prompt.
Click on Add new; we will create the first tool for this agent now. It is a prompt tool.
Name the tool as Cyphergenerator.
In the Description text box, Add the following: Cypher generator tool that generates cipher queries from natural language user queries. Input is a natural language query; output is cypher query.
From the Type dropdown, select Prompt.
Select Cypher Generator (Resume) from the Prompt dropdown.
Finally, your screen should look like this: Click on Save.
Let’s add the second tool for the agent, which is also a prompt tool.
Name the tool as a fallback cypher generator.
In the Description text box, Add the following fallback cypher generator tool involving only chunk index. input is a user query; output is a fallback cypher.
From the Type dropdown, select Prompt.
Select Cypher Generator-Resume-CHUNK INDEX from the Prompt dropdown.
Finally, your screen should look like this: Click on Save.
NOTE: When you hover over the Description textbox, a Magic Button (Rephrase) appears. Click on it to rephrase your instructions to the agent.
f. Lastly, let's add our agent's third and final tool, the neo4jexecutor tool.
Name the tool as neo4jexecutor.
In the Description text box, add "executes cypher queries against the neo4j database." The input is a cypher query, and the output is a cypher response.
In the Type dropdown, select KnowledgeGraph.
Replace the default Input Schema with the following schema.
In the Embeddings model dropdown, select Amazon Titan Text Embeddings V2.
Key in the same Neo4j credentials you used while creating the GraphRAG recipe.
g. Finally, your screen should look like this: Click on Save.
h. Your Tools section should look like this.
i. In the Test & Compare tab, choose the preferred models, assess their outputs, and identify the most optimal model. Subsequently, click "Select as Best Answer" to designate it as the Primary Model. Additionally, if necessary, you may assign an alternative model as the Fallback Model. However, selecting a Primary Model is mandatory.
j. Click "Save prompt run" button provided at the right corner.
k. Save and publish the prompt.
Step 3: Create Agent 2.0 Recipe
Navigate to Recipe.
Click the Add New button in the top corner of Recipe.
Provide a suitable name and description of the recipe.
Select type Agent 2.0.
Setup following tiles.
Chat
Start - Connect the Chat tile to the Start tile.
Agent (Select the Agentic prompt created in Step 2)
Select All Messages in "Messages" dropdown agent state flag in the Agent tile.
Connect the Start tile to the Agent tile.
End - Connect Agent tile to End tile.
Save and Publish the recipe.
Click Test button on Chat tile to test the recipe
Ask questions in the recipe Test.
Tell me candidate with Land Surveying skills.
What are the skills of Kushal Ray?
Step 4: Create a copilot.
Click the "Export" button located at the top-right corner of the recipe interface.
Click Add new button.
Configure the export form by referring to the sample resource agent recipe provided below.
Save the export form.
The Copilot will be displayed in the Copilot section of the interface.
Step 5: Ask Questions in the chatbot
Go to the Copilot tab and open your chatbot.
Ask questions
Tell me candidate with Land Surveying skills.
What are the skills of Kushal Ray?
Sample resources
Prompts:
Cypher Generator (Resume)
Cypher Generator-Resume-CHUNK INDEX
Graphrag Resume Agent2.0
Recipes
Resume Analyst: GraphRAG starter recipe with Resume Dataset.
GraphRAG Resume KG Agent: GraphRAG Retriever Agent.
Copilots
Resume Chatbot: Resume Chatbot powered by Agentic GraphRAG for reference.
Refer the following video to create graphrag recipe.
Last updated