From Ancient Epic to Modern Marvel: Demystifying the Mahabharata Chatbot with GraphRAG (Part 3)

Source: DALL-E

Prepare to be further enthralled by the Mahabharata! We embarked on a fascinating journey through the Mahabharata in our previous explorations. We harnessed the power of graph databases and chatbots to unravel the intricate relationships and characters that lie at the heart of this epic Indian tale.

I suggest reading Part 1 of this series if you haven’t already:

Unveiling the Mahabharata’s Web: Analyzing Epic Relationships With Neo4j Graph Database (Part 1)

And don’t forget to read Part 2 as well for better understanding if you haven’t already:

Bringing the Mahabharata Epic to Life: A Neo4j-Powered Chatbot using Google Gemini (Part 2)

Now, we delve deeper into the technological marvel that brings the Mahabharata to life: a context-rich and intuitive chatbot. We’ll dissect the inner workings of this innovative system, focusing on a revolutionary approach called GraphRAG that helped me achieve this.

Supercharging Chatbots: The Power of RAG Explained

Imagine having a conversation with a friend who’s an expert on the Mahabharata. They can tell you about the characters and events and explain their connections. Now, of course, a person who is an expert on this Indian epic is tough to find. This is what we’re aiming for with our chatbot! However, traditional chatbots built with Large Language Models (LLMs) can sometimes struggle with this.

LLMs are like super-powered language learners, trained on massive amounts of text data. They can generate impressive responses, but they also tend to make things up — something we in the tech world call hallucination. This means they might weave in details that aren’t quite right or miss the mark entirely with complex narratives like the Mahabharata.

This is where a cool approach called Retrieval-Augmented Generation (RAG) comes in. You can think of RAG as a way to give LLMs a helping hand. RAG combines retrieval-based models with LLMs. Retrieval models work like super-powered search engines, scouring vast amounts of information to find the most relevant bits for a specific question. RAG leverages these retrieved snippets to inform the LLM’s response, grounding it in real information and making it more accurate.

Want to dive deeper into RAG? Check out this 3-minute video explaining RAG for LLMs for a more technical explanation. But for now, let’s just say RAG helps our Mahabharata chatbot stay on track and deliver creative and factually accurate responses.

Demystifying GraphRAG: Beyond the Vector

Now, let’s talk about the GraphRAG approach. Traditional chatbots often rely on RAG models. These models function by retrieving relevant information (like text passages or dialog snippets) based on user queries and generating responses by manipulating these retrieved vectors. While effective, this approach can have limitations. Vector-only representations may not fully capture the rich context and relationships inherent in complex narratives like the Mahabharata.

Source: DALL-E

This is where GraphRAG steps in. It expands upon the traditional RAG model by incorporating the power of graph databases like Neo4j. GraphRAG uses the interconnectedness of data within a graph structure to retrieve relevant information and understand the relationships among entities. This allows the chatbot to generate more nuanced and contextually aware responses, bringing the Mahabharata’s characters and their intricate relationships to life more meaningfully.

Learn more about knowledge graphs and RAG using Neo4j at the GraphAcademy.

Neo4j LLM Knowledge Graph Builder

So, we’ve established that GraphRAG gives our chatbot a much-needed boost, but how do we actually put it all together? Here’s where a nifty tool called Neo4j LLM Knowledge Graph Builder comes in.

Think of it as a magic kitchen where you can cook up the perfect knowledge graph for your chatbot. This online tool lets you feed it all sorts of information about the Mahabharata — text passages, character descriptions, even those intricate family relationships! The Neo4j LLM Knowledge Graph Builder then uses clever AI (basically one of the chosen LLMs — OpenAI’s GPT-4o, 4 and 3.5, Diffbot or Gemini 1.5 Pro) to analyze all this data and build a powerful knowledge graph: a web of interconnected information that captures the essence of the epic. Read more about the tool at Neo4j Labs.

This knowledge graph becomes the secret weapon of our RAG-powered chatbot. When a user asks a question, the chatbot can tap into the retrieved snippets from RAG and consult this detailed knowledge graph to understand the relationships among characters, events, and locations. This lets the chatbot provide truly insightful and contextually rich responses, making your Mahabharata adventure all the more engaging.

LLM Graph Builder Tool in action

I absolutely love this tool! It empowers the chatbot to answer a whole spectrum of Mahabharata inquiries. From straightforward questions like:

Who killed Ghatotakach? (Spoiler alert — it was Karna!)

To the more intricate questions like:

Why did the Pandavas have to go live in the forest for 12 years? (That’s a story about deceit, exile, and a dice game gone wrong!)

The Neo4j LLM Knowledge Graph Builder helps the chatbot navigate these types of questions easily. It can efficiently pinpoint the relevant connections in the knowledge graph for the simpler ones. For the complex ones, it allows the chatbot to delve deeper, considering the web of relationships, motivations, and historical context to arrive at a well-rounded explanation. It’s like having a personal Mahabharata scholar at your fingertips, ready to unravel the epic’s mysteries!

Chatting with the Mahabharata: A New and Improved Experience

Now that we’ve explored the magic of GraphRAG and the Neo4j LLM Knowledge Graph Builder tool, let’s talk about the star of the show: the Mahabharata chatbot. To elevate your Mahabharata journey even further, a friend of mine, Vrijraj Singh, has designed a sleek and user-friendly web app specifically for this chatbot.

Mahabharata Chatbot

This web app significantly improves the previous Gradio chatbot hosted on Hugging Face Spaces (although it is just taking the IFrame from there). Here’s why:

  • Enhanced user interface — The web app boasts a more intuitive and visually appealing interface, making it easier to interact with the chatbot and explore the Mahabharata.
  • Seamless integration — The web app seamlessly integrates with the GraphRAG and knowledge graph components, ensuring a smooth and efficient user experience.
  • Accessibility — The app is designed to reach a wider audience, making the Mahabharata’s wisdom more readily available.

Head over to and embark on your own interactive Mahabharata adventure. Ask questions, delve into character relationships, and better understanding of this timeless epic.

The Ever-Evolving Mahabharata Journey: A Look Ahead

This is just the beginning of my Mahabharata chatbot’s odyssey. I am constantly seeking ways to improve and expand its capabilities. Here are some exciting possibilities on the horizon:

  • Enhanced storytelling — Integrating natural language generation techniques beyond GraphRAG that can allow the chatbot to answer questions, weave captivating narratives, and explore different facets of the Mahabharata.
  • Multilingual support — Making the chatbot multilingual will open its doors to a wider audience, fostering a global appreciation for the epic.
  • Advanced character interaction — Imagine engaging in conversations directly with characters from the Mahabharata! This could involve exploring their motivations, witnessing key events from their perspective, and gaining a deeper understanding of their personalities.

The future is bright for my Mahabharata chatbot. Currently, it leverages the power of code-bison and text-bison from Model Garden on Vertex AI from Google. However, I am gearing up to explore the potential of even more advanced LLMs like Gemini 1.5 Pro or Gemini 1.5 Flash. Additionally, I’ll be putting the chatbot through its paces with other LLM models like Anthropic’s Claude or OpenAI’s GPT-4o to see how they tackle the complexities of the Mahabharata narrative. This experimentation will allow me to identify the optimal LLM for this specific application.

I invite you to be a part of this exciting journey. Share your feedback, suggestions, and those burning Mahabharata questions you’ve always wanted answered. Together, let’s make this chatbot the ultimate resource for exploring the timeless world of the Mahabharata.

Enjoyed this post? Give it a 👏 below and follow me on Medium and LinkedIn to get updates on upcoming articles. And don’t forget to ★ the GitHub repo:

GitHub – sidagarwal04/mahabharata-genai: Unveiling the Mahabharata’s Web: A Graph Journey using Neo4j and a building a gen-ai chatbot for exploring the Mahabharata

From Ancient Epic to Modern Marvel: Demystifying the Mahabharata Chatbot with GraphRAG (Part 3) was originally published in Neo4j Developer Blog on Medium, where people are continuing the conversation by highlighting and responding to this story.