""" GraphRAG vs Flat RAG — Professional Demo Author: Aravind Kumar Nalukurthi """ import gradio as gr import plotly.graph_objects as go import os from rag.flat_rag import FlatRAG from rag.graph_rag import GraphRAG from rag.evaluator import PRECOMPUTED_BENCHMARK OPENAI_KEY = os.getenv("OPENAI_API_KEY", "") CSS = """ * { box-sizing: border-box; } body, .gradio-container { background: #000 !important; font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif !important; color: #f5f5f7 !important; } .hero { padding: 64px 32px 48px; text-align: center; border-bottom: 1px solid rgba(255,255,255,0.07); } .hero-badge { display: inline-block; background: rgba(48,209,88,0.12); color: #30d158; font-size: 11px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; padding: 5px 14px; border-radius: 20px; border: 1px solid rgba(48,209,88,0.2); margin-bottom: 22px; } .hero-title { font-size: 48px; font-weight: 700; color: #f5f5f7; line-height: 1.06; letter-spacing: -0.025em; margin: 0 0 18px; } .hero-sub { font-size: 19px; color: #86868b; max-width: 620px; margin: 0 auto; line-height: 1.55; } .stats-bar { display: flex; justify-content: center; gap: 48px; flex-wrap: wrap; padding: 32px; background: #0a0a0a; border-bottom: 1px solid rgba(255,255,255,0.07); } .stat { text-align: center; } .stat-val { font-size: 30px; font-weight: 700; color: #30d158; letter-spacing: -0.02em; } .stat-label { font-size: 12px; color: #6e6e73; margin-top: 3px; font-weight: 500; } .section { padding: 36px 32px; border-bottom: 1px solid rgba(255,255,255,0.06); } .sec-label { font-size: 12px; font-weight: 600; color: #6e6e73; letter-spacing: 0.09em; text-transform: uppercase; margin: 0 0 18px; } .card { background: #111; border: 1px solid rgba(255,255,255,0.08); border-radius: 14px; padding: 22px 24px; margin-bottom: 10px; } .card-title { font-size: 16px; font-weight: 600; color: #f5f5f7; margin: 0 0 8px; } .card-body { font-size: 14px; color: #86868b; line-height: 1.6; margin: 0; } .compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0; } .compare-card { background: #111; border: 1px solid rgba(255,255,255,0.08); border-radius: 14px; padding: 20px; } .compare-label { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 8px; } .flat-label { color: #ff453a; } .graph-label { color: #30d158; } .answer-text { font-size: 14px; color: #e0e0e0; line-height: 1.6; } .tag-flat { display: inline-block; background: rgba(255,69,58,0.12); color: #ff453a; border: 1px solid rgba(255,69,58,0.2); padding: 3px 10px; border-radius: 8px; font-size: 11px; font-weight: 600; } .tag-graph { display: inline-block; background: rgba(48,209,88,0.12); color: #30d158; border: 1px solid rgba(48,209,88,0.2); padding: 3px 10px; border-radius: 8px; font-size: 11px; font-weight: 600; } .metrics { display: flex; gap: 10px; flex-wrap: wrap; margin: 16px 0; } .metric { flex: 1; min-width: 110px; background: #111; border: 1px solid rgba(255,255,255,0.08); border-radius: 12px; padding: 16px; text-align: center; } .metric-val { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; } .metric-label { font-size: 12px; color: #6e6e73; margin-top: 4px; } footer { display: none !important; } """ flat_rag = None graph_rag = None SAMPLE_QUESTIONS = [ "Who founded the company that developed the transformer architecture?", "What programming language was created by the inventor of Python?", "Which university did the creator of Linux attend?", "What is the capital of the country where PyTorch was primarily developed?", "Where was the creator of Linux studying when he built the Linux kernel?", ] DEMO_ANSWERS = { SAMPLE_QUESTIONS[0]: { "flat": "The transformer architecture was introduced in the 2017 paper 'Attention Is All You Need'. Google Brain developed key components of transformer research.", "graph": "The transformer architecture was introduced in the paper 'Attention Is All You Need' (2017) by researchers at Google Brain. Google was founded by Larry Page and Sergey Brin at Stanford University in 1998.", "flat_correct": False, "graph_correct": True, }, SAMPLE_QUESTIONS[1]: { "flat": "Python is a programming language created by Guido van Rossum. It is widely used in data science and machine learning.", "graph": "Python was created by Guido van Rossum. He also created ABC, an earlier programming language that influenced Python's design.", "flat_correct": False, "graph_correct": True, }, } def build_benchmark_chart(): categories = ["Single-hop questions", "Multi-hop questions"] flat = [0.71, 0.34] graph = [0.69, 0.61] fig = go.Figure([ go.Bar(name="Standard RAG", x=categories, y=flat, marker_color="#ff453a", text=["71%", "34%"], textposition="outside", textfont=dict(color="#f5f5f7")), go.Bar(name="GraphRAG", x=categories, y=graph, marker_color="#30d158", text=["69%", "61%"], textposition="outside", textfont=dict(color="#f5f5f7")), ]) fig.update_layout( barmode="group", template="plotly_dark", paper_bgcolor="rgba(0,0,0,0)", plot_bgcolor="rgba(0,0,0,0)", font=dict(color="#86868b"), yaxis=dict(title="Exact Match %", range=[0, 0.85], gridcolor="rgba(255,255,255,0.05)"), height=340, legend=dict(x=0.02, y=0.98), margin=dict(t=20, b=20), ) return fig def run_comparison(question: str, api_key: str): if not api_key: return "
Demo for: {q}
Standard AI search retrieves relevant paragraphs — but fails when the answer requires connecting facts across multiple documents. This project builds both systems and shows exactly where each breaks down.
RAG (Retrieval-Augmented Generation) is how AI assistants answer questions about your documents. You ask a question, the system finds the most similar paragraphs, and feeds them to a language model. This works well for direct questions — but breaks on questions that require reasoning across multiple facts.
Q: "Who founded the company that created the transformer architecture?"
Standard RAG finds the paragraph about transformers, but it doesn't connect the fact that Google made transformers to the fact that Larry Page founded Google. GraphRAG builds a knowledge graph and traverses connections between entities — finding the chain: transformer → Google → Larry Page.
No API key needed: Click the "Example Questions" tab to see pre-computed comparisons.
With API key: Go to "Live Comparison", enter your OpenAI key, and ask your own questions.
For direct questions ("What year was Python created?"), both systems perform nearly identically. The graph traversal overhead adds no value when the answer lives in a single paragraph. GraphRAG's advantage only appears when connecting multiple facts is required.