File size: 9,566 Bytes
bdcfc58
 
 
 
 
ceb4fb2
 
bdcfc58
 
 
 
 
ceb4fb2
bdcfc58
 
 
 
 
ceb4fb2
bdcfc58
ceb4fb2
bdcfc58
ceb4fb2
 
 
 
 
 
bdcfc58
ceb4fb2
bdcfc58
 
 
ceb4fb2
 
bdcfc58
 
 
ceb4fb2
bdcfc58
 
ceb4fb2
 
 
 
 
 
 
 
 
 
 
bdcfc58
 
 
 
 
 
ceb4fb2
 
 
 
 
bdcfc58
 
 
ceb4fb2
bdcfc58
ceb4fb2
bdcfc58
ceb4fb2
bdcfc58
 
ceb4fb2
 
 
 
 
 
bdcfc58
 
ceb4fb2
bdcfc58
ceb4fb2
 
 
 
 
 
bdcfc58
ceb4fb2
bdcfc58
ceb4fb2
 
 
 
 
 
 
 
 
bdcfc58
 
 
ceb4fb2
bdcfc58
ceb4fb2
bdcfc58
ceb4fb2
 
bdcfc58
ceb4fb2
 
 
 
 
 
bdcfc58
 
 
ceb4fb2
bdcfc58
ceb4fb2
bdcfc58
ceb4fb2
bdcfc58
ceb4fb2
 
 
 
 
 
 
 
 
bdcfc58
 
 
 
 
 
ceb4fb2
bdcfc58
 
 
ceb4fb2
 
 
 
 
bdcfc58
 
 
 
 
ceb4fb2
bdcfc58
 
 
 
 
 
 
 
ceb4fb2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bdcfc58
ceb4fb2
 
 
 
bdcfc58
 
 
 
 
 
 
 
ceb4fb2
 
 
 
 
bdcfc58
 
ceb4fb2
bdcfc58
 
 
 
 
 
 
ceb4fb2
bdcfc58
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# πŸ” GraphRAG Inference Hackathon β€” Dual Pipeline System

<div align="center">

[![TigerGraph](https://img.shields.io/badge/Graph_DB-TigerGraph-orange?style=for-the-badge)](https://www.tigergraph.com/)
[![Claude](https://img.shields.io/badge/LLM-Claude_Sonnet_4-coral?style=for-the-badge)](https://anthropic.com/)
[![Next.js](https://img.shields.io/badge/Frontend-Next.js_15-black?style=for-the-badge&logo=next.js)](https://nextjs.org/)
[![HotpotQA](https://img.shields.io/badge/Benchmark-HotpotQA-purple?style=for-the-badge)](https://hotpotqa.github.io/)
[![RAGAS](https://img.shields.io/badge/Evaluation-RAGAS-red?style=for-the-badge)](https://ragas.io/)

**Proving that graphs make LLM inference faster, cheaper, and smarter β€” with real numbers.**

[Web Dashboard](#-web-dashboard-nextjs) Β· [Architecture](#-architecture) Β· [Benchmarks](#-benchmark-results) Β· [Novelties](#-novel-features) Β· [Design System](#-design-system)

</div>

---

## 🎯 Overview

A **production-ready dual-pipeline GraphRAG system** with two interfaces:

| | **Next.js Web Dashboard** | **Python CLI + Gradio** |
|---|---|---|
| **LLM** | Claude Sonnet 4 (Anthropic) | GPT-4o-mini (OpenAI) |
| **Frontend** | React 19 + Recharts + Custom SVG | Gradio 6.x + Plotly |
| **Design** | TigerGraph Γ— Claude fused design system | Standard Gradio |
| **Best for** | Demos, presentations, judging | Benchmarking, batch eval |

Both interfaces run the same dual-pipeline comparison:

| | **Pipeline A: Baseline RAG** | **Pipeline B: GraphRAG** |
|---|---|---|
| **Flow** | Query β†’ Vector Search β†’ Top-K β†’ LLM | Query β†’ Keywords β†’ Entity Search β†’ Graph Traversal β†’ LLM |
| **Wins on** | Speed, cost, simple queries | Accuracy on complex multi-hop queries (+21% F1) |

---

## πŸ—οΈ Architecture

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  LAYER 4: EVALUATION β€” RAGAS + F1/EM + Cost/Token Tracking  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  LAYER 3: LLM β€” Claude Sonnet 4 Β· Entity/Keyword Extraction β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Pipeline A: Baseline  β”‚  Pipeline B: GraphRAG               β”‚
│  Query→Vector→LLM      │  Query→Keywords→Graph→Context→LLM   │
β”‚                        β”‚  🧠 Adaptive Router                 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  LAYER 1: GRAPH β€” TigerGraph Cloud Β· GSQL Β· Multi-hop BFS   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

---

## 🌟 Novel Features

1. **🧠 Adaptive Query Router** β€” Automatically routes simple queries to baseline (cheaper) and complex ones to GraphRAG (more accurate)
2. **πŸ“‹ Schema-Bounded Extraction** β€” Pre-defined 9 entity types + 15 relation types (~90% cheaper, ~16% more accurate)
3. **πŸ”‘ Dual-Level Keywords** β€” LightRAG-inspired high-level + low-level keyword routing
4. **πŸ”— Graph Reasoning Paths** β€” Step-by-step natural language explanation of graph traversal
5. **πŸ“Š Real-Time Cost Tracking** β€” Every LLM call tracked with tokens, cost, and latency

---

## πŸ–₯️ Web Dashboard (Next.js)

The flagship interface β€” a polished React app with the **TigerGraph Γ— Claude fused design system**.

### Quick Start

```bash
cd web
npm install
cp .env.example .env.local
# Add your Anthropic API key: ANTHROPIC_API_KEY=sk-ant-...
npm run dev
# Open http://localhost:3000
```

### 4 Tabs

| Tab | What It Does |
|-----|-------------|
| **πŸ”΄ Live Compare** | Side-by-side answers from both pipelines with real-time metrics, adaptive routing badges, entity/relation display |
| **πŸ“Š Benchmark** | Radar charts, bar charts, detailed comparison table with HotpotQA results |
| **πŸ’° Cost Analysis** | Interactive cost projections across 4 LLM models, cumulative cost area charts, ROI analysis |
| **πŸ•ΈοΈ Graph Explorer** | Interactive SVG knowledge graph with clickable nodes, reasoning path explanation, graph statistics |

### Tech Stack

| Layer | Technology |
|-------|-----------|
| Framework | Next.js 15 (App Router) |
| React | React 19 |
| LLM | Claude Sonnet 4 via `@anthropic-ai/sdk` |
| Charts | Recharts 2.15 |
| Graph Viz | Custom SVG with interaction |
| Styling | Tailwind CSS 4 + 14KB custom design system |
| Fonts | Cormorant Garamond (serif display) + Inter (sans body) + JetBrains Mono (code) |

---

## 🎨 Design System

The web dashboard uses a **fused design system** combining:

- **TigerGraph**: Orange `#FF6B00` (energy, CTAs), Navy `#002B49` (authority, text), Electric Blue `#0072CE` (baseline pipeline)
- **Claude/Anthropic**: Cream canvas `#faf9f5` (warmth), Coral `#cc785c` (intelligence), Dark surfaces `#181715` (product chrome)

### Key Principles
- Warm cream canvas (never cold white) β€” the Claude editorial feel
- Serif display headlines (Cormorant Garamond, weight 400, negative tracking) β€” literary voice
- Tiger Orange for primary CTAs β€” energy and action
- Dark surface code windows for architecture diagrams β€” product chrome
- Cream β†’ Dark alternating section rhythm

---

## 🐍 Python Backend + Gradio

The Python backend handles benchmarking, TigerGraph ingestion, and batch evaluation.

### Quick Start

```bash
pip install -r requirements.txt
cp .env.example .env
# Add: OPENAI_API_KEY=sk-...

python -m graphrag.main dashboard    # Gradio UI on :7860
python -m graphrag.main demo         # CLI demo
python -m graphrag.main benchmark --samples 50
python -m graphrag.main ingest --samples 100  # Requires TigerGraph
```

---

## πŸ“Š Benchmark Results

### HotpotQA (Distractor Setting, 100 samples)

| Metric | Baseline RAG | GraphRAG | Winner |
|--------|-------------|----------|--------|
| **Avg F1** | 0.5523 | **0.6241** | βœ… GraphRAG (+13%) |
| **Avg EM** | 0.3810 | **0.4230** | βœ… GraphRAG (+11%) |
| **Context Hit** | 0.4520 | **0.5830** | βœ… GraphRAG (+29%) |
| **Tokens/Query** | **952** | 2,387 | βœ… Baseline (2.5Γ—) |
| **Cost/Query** | **$0.000203** | $0.000518 | βœ… Baseline (2.6Γ—) |

### By Question Type

| Type | Baseline F1 | GraphRAG F1 | Ξ” |
|------|------------|-------------|---|
| **Bridge** | 0.52 | **0.63** | **+21%** |
| **Comparison** | 0.58 | **0.61** | +5% |

---

## πŸ“ Project Structure

```
graphrag-inference-hackathon/
β”œβ”€β”€ web/                            # Next.js Web Dashboard
β”‚   β”œβ”€β”€ src/app/
β”‚   β”‚   β”œβ”€β”€ page.tsx                # Main page
β”‚   β”‚   β”œβ”€β”€ layout.tsx              # Root layout
β”‚   β”‚   β”œβ”€β”€ globals.css             # 14KB fused design system
β”‚   β”‚   └── api/compare/route.ts    # Claude-powered API
β”‚   β”œβ”€β”€ src/components/
β”‚   β”‚   β”œβ”€β”€ Navbar.tsx              # TigerGraphΓ—Claude navbar
β”‚   β”‚   β”œβ”€β”€ Hero.tsx                # Editorial hero with stats
β”‚   β”‚   β”œβ”€β”€ DashboardTabs.tsx       # Tab controller
β”‚   β”‚   β”œβ”€β”€ Footer.tsx              # Dark footer
β”‚   β”‚   └── tabs/
β”‚   β”‚       β”œβ”€β”€ LiveCompare.tsx     # Tab 1: Side-by-side comparison
β”‚   β”‚       β”œβ”€β”€ Benchmark.tsx       # Tab 2: Radar + bar charts
β”‚   β”‚       β”œβ”€β”€ CostAnalysis.tsx    # Tab 3: Cost projections
β”‚   β”‚       └── GraphExplorer.tsx   # Tab 4: Interactive graph viz
β”‚   └── src/lib/design-tokens.ts    # Color + typography tokens
β”‚
β”œβ”€β”€ graphrag/                       # Python Backend
β”‚   β”œβ”€β”€ layers/
β”‚   β”‚   β”œβ”€β”€ graph_layer.py          # Layer 1: TigerGraph
β”‚   β”‚   β”œβ”€β”€ orchestration_layer.py  # Layer 2: Dual pipeline
β”‚   β”‚   β”œβ”€β”€ llm_layer.py            # Layer 3: LLM
β”‚   β”‚   └── evaluation_layer.py     # Layer 4: Evaluation
β”‚   β”œβ”€β”€ dashboard.py                # Gradio dashboard
β”‚   β”œβ”€β”€ benchmark.py                # Batch benchmark runner
β”‚   β”œβ”€β”€ ingestion.py                # Document ingestion
β”‚   └── main.py                     # CLI entry point
β”‚
β”œβ”€β”€ requirements.txt                # Python dependencies
└── README.md
```

---

## πŸ“š References

### Papers
1. [GraphRAG](https://arxiv.org/abs/2404.16130) β€” From Local to Global Graph RAG
2. [LightRAG](https://arxiv.org/abs/2410.05779) β€” Simple and Fast RAG (34K⭐)
3. [HotpotQA](https://arxiv.org/abs/1809.09600) β€” Multi-hop QA Dataset
4. [RAGAS](https://arxiv.org/abs/2309.15217) β€” RAG Evaluation Framework
5. [Youtu-GraphRAG](https://arxiv.org/abs/2508.19855) β€” Schema-Bounded Extraction

### Tools
[TigerGraph](https://tgcloud.io) Β· [Anthropic Claude](https://anthropic.com) Β· [Next.js](https://nextjs.org) Β· [Recharts](https://recharts.org) Β· [RAGAS](https://ragas.io) Β· [HotpotQA](https://huggingface.co/datasets/hotpotqa/hotpot_qa)

---

<div align="center">

**Built for the GraphRAG Inference Hackathon by TigerGraph** 🧑

*TigerGraph Γ— Claude Β· Next.js 15 Β· Recharts Β· RAGAS*

</div>