Spaces:
Runtime error

Meshyboi commited on
Commit
f7ec828
Β·
verified Β·
1 Parent(s): ffa34a9

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +8 -626
README.md CHANGED
@@ -1,629 +1,11 @@
1
- # Scientific Paper Q&A β€” GraphRAG with TigerGraph
2
-
3
- A multi-pipeline retrieval-augmented generation (RAG) system for answering factual and multi-hop questions over a corpus of AI/ML research papers. Built for the TigerGraph Hackathon, the project explores three progressively more sophisticated retrieval architectures and evaluates them against a hand-crafted golden benchmark set.
4
-
5
- ---
6
-
7
- ## Table of Contents
8
-
9
- - [Dataset](#dataset)
10
- - [Corpus Token Counts](#corpus-token-counts)
11
- - [Project Structure](#project-structure)
12
- - [Architecture Overview](#architecture-overview)
13
- - [Pipeline 1 β€” LLM-Only Baseline](#pipeline-1--llm-only-baseline)
14
- - [Pipeline 2 β€” Hybrid RAG](#pipeline-2--hybrid-rag)
15
- - [Pipeline 3 β€” GraphRAG (TigerGraph)](#pipeline-3--graphrag-tigergraph)
16
- - [Evaluation & Benchmark](#evaluation--benchmark)
17
- - [Comparative Results](#comparative-results)
18
- - [Example Queries](#example-queries)
19
- - [Setup & Installation](#setup--installation)
20
- - [Running the Server](#running-the-server)
21
-
22
- ---
23
-
24
- ## Dataset
25
-
26
- ### Source
27
-
28
- Papers are sourced from **[OpenAlex](https://openalex.org/)**, a fully open catalog of scholarly works. The corpus is filtered to high-quality AI/ML research published between **2018–2024** with a minimum of 20 citations, covering two OpenAlex topic clusters:
29
-
30
- | Topic ID | Description |
31
- | -------- | --------------------------------- |
32
- | `T12072` | Machine Learning and Algorithms |
33
- | `T11948` | Deep Learning and Neural Networks |
34
-
35
- ### Download
36
-
37
- The `utils/download_aiml_data.py` script uses the `openalex` CLI to batch-download papers as individual JSON files into a local `data/` directory. The download is resumable (`--resume`) and parallelized across 10 workers.
38
-
39
- ```bash
40
- python utils/download_aiml_data.py
41
- ```
42
-
43
- ### Paper Format
44
-
45
- Each paper is stored as a raw OpenAlex JSON file (`<work_id>.json`) containing:
46
-
47
- - `title`, `abstract_inverted_index` (reconstructed to plain text at index time)
48
- - `publication_year`, `cited_by_count`, `doi`
49
- - `best_oa_location.pdf_url` β€” open-access full text URL
50
- - `authorships` β€” author names, IDs, and corresponding author flag
51
- - `topics` β€” up to 3 OpenAlex topic objects with relevance scores
52
- - `referenced_works` β€” list of cited work IDs (used for CITES edges in Pipeline 3)
53
-
54
- ### Evaluation Set
55
-
56
- `evaluation_set.json` contains **16 human-authored questions** across two difficulty tiers:
57
-
58
- | Type | Count | Description |
59
- | ----------- | ----- | ------------------------------------------------------------------------- |
60
- | `factual` | 10 | Single-paper questions requiring precise, specific answers |
61
- | `multi_hop` | 6 | Questions referencing 2 distinct papers that must be synthesized together |
62
-
63
- Each entry includes:
64
-
65
- - `work_id` / `work_ids` β€” the source paper(s) being tested
66
- - `question` β€” the natural language question
67
- - `correct_answer` β€” the gold-standard answer used for LLM judging and BERTScore
68
-
69
- ---
70
-
71
- ## Corpus Token Counts
72
-
73
- Measured across all **14,247 papers** in the corpus using `utils/token_count.py` (1 token β‰ˆ 4 chars, GPT/Llama heuristic). Three tiers reflect what the pipeline actually touches at each stage.
74
-
75
- | Tier | What it measures | Size (MB) | Est. Tokens | Reduction vs Raw |
76
- | ------------------------ | ------------------------------------- | :-------: | :---------: | :--------------: |
77
- | **Tier 1 β€” Raw** | Full OpenAlex JSON as-is on disk | 428.1 MB | **107.02M** | β€” |
78
- | **Tier 2 β€” Optimised** | Pipeline-relevant fields only ΒΉ | 49.6 MB | **12.37M** | βˆ’88.4% |
79
- | **Tier 3 β€” LLM Context** | What the embedding model + LLM sees Β² | 14.7 MB | **3.66M** | βˆ’96.6% |
80
-
81
- > ΒΉ **Optimised fields:** `id`, `title`, `abstract` (reconstructed from inverted index), `authorships` (name + position only), `topics` (display names), `keywords`, `referenced_works` (short IDs), `doi`, `publication_year`, `cited_by_count`, `best_oa_location.pdf_url`
82
- >
83
- > Β² **LLM context format:** `"Title: {title}\n\nAbstract: {abstract}"` β€” the exact string passed to `BAAI/bge-large-en-v1.5` for indexing and used as the base context when no full-text PDF is available.
84
-
85
- The 96.6% reduction from raw to LLM context (107M β†’ 3.66M tokens) reflects how much of the OpenAlex metadata (citation lists, institution affiliations, grant details, hosting platform metadata, etc.) is never fed to the model β€” only title and abstract matter for retrieval and synthesis.
86
-
87
- ---
88
-
89
- ## Project Structure
90
-
91
- ```
92
- TigerGraph-Hack/
93
- β”œβ”€β”€ app.py # FastAPI server exposing all 3 pipeline endpoints
94
- β”œβ”€β”€ run_benchmarks.py # Benchmark harness β€” runs pipelines against evaluation set
95
- β”œβ”€β”€ evaluation_set.json # 16-question golden test set
96
- β”œβ”€β”€ benchmark_results.json # Benchmark output (per-question results)
97
- β”œβ”€β”€ requirements.txt
98
- β”œβ”€β”€ utils/
99
- β”‚ β”œβ”€β”€ download_aiml_data.py # OpenAlex corpus downloader
100
- β”‚ └── token_count.py
101
- β”œβ”€β”€ services/
102
- β”‚ β”œβ”€β”€ paper_fetcher.py # Fetches full-text PDF/HTML from open-access URLs
103
- β”‚ └── metrics_service.py # LLM-as-a-judge + BERTScore + cost/latency metrics
104
- β”œβ”€β”€ core/
105
- β”‚ β”œβ”€β”€ pipeline_1/ # Baseline: LLM-only (Gemini)
106
- β”‚ β”‚ β”œβ”€β”€ logic.py
107
- β”‚ β”‚ β”œβ”€β”€ filter.py
108
- β”‚ β”‚ └── main.py
109
- β”‚ β”œβ”€β”€ pipeline_2/ # Hybrid RAG (Qdrant + Groq)
110
- β”‚ β”‚ β”œβ”€β”€ logic.py
111
- β”‚ β”‚ β”œβ”€β”€ indexer.py # One-time: embed papers into Qdrant
112
- β”‚ β”‚ └── retriever.py # HybridRetriever: dense + BM25 + cross-encoder
113
- β”‚ └── pipeline_3/ # GraphRAG (Qdrant + TigerGraph + Groq)
114
- β”‚ β”œβ”€β”€ logic.py
115
- β”‚ β”œβ”€β”€ setup.py # One-time: TigerGraph schema + data ingestion
116
- β”‚ └── queries.py # GSQL query definitions + install helpers
117
- └── data/ # Downloaded OpenAlex paper JSONs (gitignored)
118
- ```
119
-
120
  ---
121
-
122
- ## Architecture Overview
123
-
124
- All three pipelines share the same **evaluation harness** (`run_benchmarks.py`) which measures:
125
-
126
- - **Pass/Fail** β€” Llama-3.1-8B-Instruct acting as LLM judge
127
- - **BERTScore F1** β€” semantic similarity between system answer and gold answer (rescaled with baseline)
128
- - **Latency** β€” wall-clock time in seconds
129
- - **Token count** β€” total prompt + completion tokens
130
- - **Cost (USD)** β€” computed from Groq pricing tiers
131
-
132
- ---
133
-
134
- ### Pipeline 1 β€” LLM-Only Baseline
135
-
136
- The simplest approach: keyword-based metadata filtering over the paper corpus followed by direct full-text injection into a Gemini prompt. No vector search, no reranking.
137
-
138
- ```
139
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
140
- β”‚ Pipeline 1: LLM-Only β”‚
141
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
142
-
143
- User Query
144
- β”‚
145
- β–Ό
146
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
147
- β”‚ Metadata β”‚ Keyword match on title/abstract
148
- β”‚ Filter β”‚ Returns top-N papers by relevance score
149
- β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
150
- β”‚ top-N paper IDs
151
- β–Ό
152
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
153
- β”‚ Full Text β”‚ Fetches open-access PDFs/HTML via OpenAlex URLs
154
- β”‚ Fetch β”‚ Falls back to abstract if unavailable
155
- β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
156
- β”‚ paper content strings
157
- β–Ό
158
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
159
- β”‚ Context β”‚ Concatenate: "--- PAPER i ---\n{content}\n"
160
- β”‚ Assembly β”‚
161
- β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
162
- β”‚ context (up to max_full_text papers)
163
- β–Ό
164
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
165
- β”‚ Gemini β”‚ gemini-1.5-flash
166
- β”‚ Flash LLM β”‚ System: "Answer from provided papers only"
167
- β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
168
- β”‚
169
- β–Ό
170
- Answer + Metrics
171
- ```
172
-
173
- **Key characteristics:**
174
-
175
- - Model: `gemini-1.5-flash`
176
- - No semantic search β€” purely lexical filtering
177
- - Suited as a cost/latency baseline
178
- - No query decomposition for multi-hop questions
179
-
180
- ---
181
-
182
- ### Pipeline 2 β€” Hybrid RAG
183
-
184
- A production-grade RAG pipeline built on Qdrant with dense + sparse hybrid retrieval, cross-encoder reranking, LLM query decomposition, and structure-aware passage extraction.
185
-
186
- ```
187
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
188
- β”‚ Pipeline 2: Hybrid RAG β”‚
189
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
190
-
191
- User Query
192
- β”‚
193
- β–Ό
194
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
195
- β”‚ Query β”‚ llama-3.1-8b-instant (cheap classifier)
196
- β”‚ Decomposition β”‚ β†’ is_multi_hop? + sub_queries[]
197
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
198
- β”‚
199
- β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
200
- β”‚ single-hop β”‚ multi-hop
201
- β–Ό β–Ό
202
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
203
- β”‚ Qdrant β”‚ β”‚ Parallel Sub-Query β”‚
204
- β”‚ Search β”‚ β”‚ Retrieval (threaded) β”‚
205
- β”‚ (top-50) β”‚ β”‚ β†’ merge candidates β”‚
206
- β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
207
- β”‚ β”‚
208
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
209
- β”‚ candidate papers
210
- β–Ό
211
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
212
- β”‚ Cross-Encoder β”‚ BAAI/bge-reranker-v2-m3
213
- β”‚ Rerank (top-10) β”‚ scores title + abstract pairs
214
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
215
- β”‚
216
- β–Ό
217
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
218
- β”‚ Sub-Query β”‚ For multi-hop: ensure each sub-query
219
- β”‚ Coverage Check β”‚ has at least one representative paper
220
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
221
- β”‚ top papers (up to 10)
222
- β–Ό
223
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
224
- β”‚ Full-Text Fetch β”‚ Parallel fetch (ThreadPoolExecutor)
225
- β”‚ (top-2/3 papers) β”‚ Falls back to abstract on failure
226
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
227
- β”‚
228
- β–Ό
229
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
230
- β”‚ Structure-Aware β”‚ 1. Split text into sentences
231
- β”‚ Passage Extract β”‚ 2. Group into ~600-char passages
232
- β”‚ β”‚ 3. Bi-encoder stage: top-30 by cosine
233
- β”‚ β”‚ 4. Cross-encoder rerank: select top-k
234
- β”‚ β”‚ 5. Prepend [Source: title] to each
235
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
236
- β”‚ curated context string
237
- β–Ό
238
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
239
- β”‚ Groq LLM β”‚ llama-3.3-70b-versatile
240
- β”‚ Synthesis β”‚ temperature=0.1, max_tokens=1024
241
- β”‚ β”‚ API key rotation on rate limit
242
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
243
- β”‚
244
- β–Ό
245
- Answer + Sources + Metrics
246
- ```
247
-
248
- **Key components:**
249
-
250
- | Component | Model / Tool | Purpose |
251
- | ---------------- | ----------------------------------- | -------------------------------------- |
252
- | Vector index | Qdrant (local) | Dense + BM25 hybrid storage |
253
- | Dense encoder | `BAAI/bge-large-en-v1.5` (1024-dim) | Semantic similarity |
254
- | Sparse encoder | `Qdrant/bm25` | Lexical overlap |
255
- | Fusion | RRF (Reciprocal Rank Fusion) | Merge dense + sparse rankings |
256
- | Reranker | `BAAI/bge-reranker-v2-m3` | Query-document cross-attention scoring |
257
- | Query decomposer | `llama-3.1-8b-instant` | Detect multi-hop, generate sub-queries |
258
- | LLM | `llama-3.3-70b-versatile` via Groq | Final answer synthesis |
259
-
260
  ---
261
 
262
- ### Pipeline 3 β€” GraphRAG (TigerGraph)
263
-
264
- Extends Pipeline 2 with a **knowledge graph layer** powered by TigerGraph. Beyond vector search, the pipeline traverses citation (`CITES`) and topic (`HAS_TOPIC`) edges to surface papers that are graph-adjacent to the initial retrieval seeds. Graph signals are activated selectively based on query type.
265
-
266
- #### TigerGraph Schema
267
-
268
- ```
269
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
270
- β”‚ Author β”‚
271
- β”‚ author_id β”‚
272
- β”‚ display_nameβ”‚
273
- β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
274
- β”‚ AUTHORED_BY (directed)
275
- β”‚
276
- β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
277
- β”‚ Paper β”‚
278
- β”‚ paper_id, title, abstract, year β”‚
279
- β”‚ cited_by_count, doi, pdf_url, venue β”‚
280
- β”‚ embedding VECTOR(1024) β”‚
281
- β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
282
- β”‚ CITES (directed) β”‚ HAS_TOPIC (directed, score: FLOAT)
283
- β–Ό β–Ό
284
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
285
- β”‚ Paper β”‚ β”‚ Topic β”‚
286
- β”‚ ... β”‚ β”‚ topic_id β”‚
287
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ display_nameβ”‚
288
- β”‚ subfield β”‚
289
- β”‚ field β”‚
290
- β”‚ domain β”‚
291
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
292
- ```
293
-
294
- **GSQL Queries installed at runtime:**
295
-
296
- | Query | Purpose |
297
- | --------------------------- | ----------------------------------------------------------------------- |
298
- | `get_papers_by_ids` | Fetch Paper vertices by ID set |
299
- | `expand_paper_neighborhood` | 1-hop CITES expansion from seed paper IDs |
300
- | `search_papers_by_topic` | Pattern-match Topic vertices; return papers ranked by `HAS_TOPIC` score |
301
-
302
- #### Full Pipeline Flow
303
-
304
- ```
305
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
306
- β”‚ Pipeline 3: GraphRAG β”‚
307
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
308
-
309
- User Query
310
- β”‚
311
- β–Ό
312
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
313
- β”‚ Query Decomposition β”‚ llama-3.1-8b-instant
314
- β”‚ β”‚ β†’ is_multi_hop?
315
- β”‚ β”‚ β†’ use_topic? (broad survey queries)
316
- β”‚ β”‚ β†’ use_cites? (synthesis/multi-hop)
317
- β”‚ β”‚ β†’ sub_queries[]
318
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
319
- β”‚
320
- β–Ό
321
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
322
- β”‚ Qdrant Hybrid β”‚ BAAI/bge-large-en-v1.5 (dense)
323
- β”‚ Retrieval (top-50) β”‚ Qdrant/bm25 (sparse)
324
- β”‚ β”‚ RRF fusion β†’ normalized paper IDs
325
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
326
- β”‚ qdrant_results
327
- β”‚
328
- β”œβ”€β”€β”€β”€ use_topic=true? ──────────────────┐
329
- β”‚ β”‚
330
- β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
331
- β”‚ β”‚ TigerGraph β”‚
332
- β”‚ β”‚ Topic Search β”‚
333
- β”‚ β”‚ (HAS_TOPIC) β”‚
334
- β”‚ β”‚ extract keywordsβ”‚
335
- β”‚ β”‚ β†’ parallel kw β”‚
336
- β”‚ β”‚ GSQL queries β”‚
337
- β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
338
- β”‚ β”‚
339
- β”œβ”€β”€β”€β”€ use_cites=true? ───────────────────
340
- β”‚ β”‚
341
- β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
342
- β”‚ β”‚ TigerGraph β”‚
343
- β”‚ β”‚ Citation Expand β”‚
344
- β”‚ β”‚ (CITES edges) β”‚
345
- β”‚ β”‚ seeds: top-20 β”‚
346
- β”‚ β”‚ paper IDs β”‚
347
- β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
348
- β”‚ β”‚
349
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
350
- β”‚
351
- β–Ό
352
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
353
- β”‚ Weighted RRF β”‚ Qdrant: weight=4.0
354
- β”‚ Merge β”‚ Topic: weight=1.0
355
- β”‚ β”‚ Cites: weight=1.0
356
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
357
- β”‚
358
- β–Ό
359
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
360
- β”‚ Cross-Encoder β”‚ BAAI/bge-reranker-v2-m3
361
- β”‚ Rerank (top-10) β”‚ capped at 50 candidates
362
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
363
- β”‚
364
- β–Ό
365
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
366
- β”‚ Entity Pinning β”‚ Guarantee acronyms named in
367
- β”‚ β”‚ query (CGCNN, DPMD…) have
368
- β”‚ β”‚ at least one paper in top-10
369
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
370
- β”‚ top papers (up to 10)
371
- β–Ό
372
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
373
- β”‚ Full-Text Fetch β”‚ Parallel fetch with 30s timeout
374
- β”‚ (top-2/3 papers) β”‚ Falls back to abstract
375
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
376
- β”‚
377
- β–Ό
378
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
379
- β”‚ Multi-Query β”‚ bge-small-en-v1.5 (fast CPU)
380
- β”‚ Passage Extract β”‚ Each sub-query gets passage
381
- β”‚ β”‚ slots; dense scoring selects
382
- β”‚ β”‚ top-k passages
383
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
384
- β”‚ curated context string
385
- β–Ό
386
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
387
- β”‚ Groq LLM β”‚ llama-3.3-70b-versatile
388
- β”‚ Synthesis β”‚ temperature=0.1, max_tokens=1024
389
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
390
- β”‚
391
- β–Ό
392
- Answer + Sources + Metrics
393
- ```
394
-
395
- **Key differentiators over Pipeline 2:**
396
-
397
- | Feature | Pipeline 2 | Pipeline 3 |
398
- | ------------------- | ---------------- | ------------------------------------------------ |
399
- | Graph traversal | None | TigerGraph CITES + HAS_TOPIC |
400
- | Citation expansion | None | 1-hop neighborhood via GSQL |
401
- | Topic linking | None | Score-weighted HAS_TOPIC edges |
402
- | Graph signal gating | N/A | LLM-decided per query (`use_topic`, `use_cites`) |
403
- | RRF weighting | Unweighted | QdrantΓ—4, GraphΓ—1 (trust calibration) |
404
- | Passage encoder | bge-large (slow) | bge-small (10Γ— faster, same relative accuracy) |
405
- | Entity pinning | None | Acronym-based guaranteed inclusion |
406
-
407
- ---
408
-
409
- ## Evaluation & Benchmark
410
-
411
- ### Metrics
412
-
413
- | Metric | Method |
414
- | ---------------- | --------------------------------------------------------------------------------------------------------------------- |
415
- | **Pass Rate** | `meta-llama/Llama-3.1-8B-Instruct` via HuggingFace Inference API grades each answer PASS/FAIL against the gold answer |
416
- | **BERTScore F1** | `bert-score` library, `rescale_with_baseline=True`, English model |
417
- | **Latency** | Wall-clock time from query receipt to answer returned (seconds) |
418
- | **Token Count** | Total prompt + completion tokens (from Groq `usage` field) |
419
- | **Cost (USD)** | `(input_tokens / 1M) Γ— input_price + (output_tokens / 1M) Γ— output_price` |
420
-
421
- ### Cost Tiers
422
-
423
- | Model | Input ($/1M tokens) | Output ($/1M tokens) |
424
- | -------------------------------- | ------------------- | -------------------- |
425
- | `llama-3.3-70b-versatile` (Groq) | $0.59 | $0.79 |
426
- | `llama-3.1-8b-instant` (Groq) | $0.05 | $0.08 |
427
- | `gemini-1.5-flash` | $0.075 | $0.30 |
428
-
429
- ### Benchmark Configuration
430
-
431
- ```python
432
- # run_benchmarks.py
433
- RUN_HYBRID = True # Pipeline 2
434
- RUN_GRAPH = True # Pipeline 3
435
- retrieval_top_k = 50 # Qdrant candidate pool size
436
- rerank_top_n = 10 # Papers after cross-encoder reranking
437
- max_full_text = 3 # Max papers with full-text fetch
438
- ```
439
-
440
- ---
441
-
442
- ## Comparative Results
443
-
444
- Results computed over the full **16-question evaluation set** (10 factual + 6 multi-hop).
445
-
446
- > **BERTScore note:** Individual per-question scores shown below are computed in single-sample mode during the run. The official aggregated scores use batch BERTScore (`rescale_with_baseline=True` over all 16 predictions simultaneously).
447
-
448
- ### Summary Table
449
-
450
- | Metric | Pipeline 2 β€” Hybrid RAG | Pipeline 3 β€” GraphRAG |
451
- | ------------------------ | :---------------------: | :-------------------: |
452
- | **Pass Rate** | 93.75% (15 / 16) | 93.75% (15 / 16) |
453
- | **Avg BERTScore F1** | 0.5511 | **0.5576** |
454
- | **Avg Latency** | 229.20s | **60.94s** |
455
- | **Avg Tokens / Query** | 5,338 | **5,015** |
456
- | **Avg Cost / Query** | $0.003182 | **$0.002982** |
457
- | **Total Tokens (16 Qs)** | 85,409 | 80,238 |
458
- | **Total Cost (16 Qs)** | $0.0509 | $0.0477 |
459
-
460
- ### Analysis
461
-
462
- **Pass Rate (tie β€” 93.75%):** Both pipelines achieve identical pass rates, each failing on exactly one question. Pipeline 2 misses a factual question about de novo drug design architectures where the correct answer requires identifying VAEs specifically β€” the retrieved paper led the model to list Transformers instead. Pipeline 3 misses a multi-hop symmetry comparison question where citation expansion introduced an off-topic paper that diluted the evidence for one of the two required papers.
463
-
464
- **BERTScore (Pipeline 3 marginally better β€” +0.0065):** GraphRAG's graph-expanded retrieval surfaces more semantically aligned context for multi-hop questions, with the largest gains on drug-development synthesis questions where topic and citation edges pull in closely related papers. Broad topic expansion adds noise on some narrow factual questions, pulling the score back down.
465
-
466
- **Latency (Pipeline 3 wins β€” 3.8Γ— faster):** Pipeline 3 is dramatically faster (60.94s vs 229.20s average). The primary driver is that Pipeline 2 uses the heavy `bge-large-en-v1.5` model for passage scoring within documents, while Pipeline 3 switches to the 10Γ— faster `bge-small-en-v1.5` for that step. Pipeline 2 also accumulated two severe outlier latencies from sequential full-text fetch timeouts stacking up.
467
-
468
- **Tokens (Pipeline 3 slightly lower β€” βˆ’5.9%):** GraphRAG's multi-query passage selection tends to pick more focused passages per paper, slightly reducing the total context length fed to the LLM.
469
-
470
- **Cost (Pipeline 3 slightly cheaper β€” βˆ’6.3%):** Follows directly from token reduction; both pipelines use the same Groq model tier.
471
-
472
- ---
473
-
474
- ## Example Queries
475
-
476
- ### Single-hop
477
-
478
- **1. What three coupled functions does the neural network construct in the automatic chemical design paper and what does each one do?**
479
-
480
- ```bash
481
- curl -X POST http://localhost:8000/query/graph \
482
- -H "Content-Type: application/json" \
483
- -d '{"query": "What three coupled functions does the neural network construct in the automatic chemical design paper and what does each one do?"}'
484
- ```
485
-
486
- **2. What does ADMET stand for, why are these properties the primary reason for drug development failure, and what does ADMETlab 2.0 provide to address this?**
487
-
488
- ```bash
489
- curl -X POST http://localhost:8000/query/graph \
490
- -H "Content-Type: application/json" \
491
- -d '{"query": "What does ADMET stand for, why are these properties the primary reason for drug development failure, and what does ADMETlab 2.0 provide to address this?"}'
492
- ```
493
-
494
- **3. According to the 2021 review on de novo drug design by Bai et al., what are the three main types of deep learning architectures used for molecule generation, and how do they benefit molecular dynamics simulations?**
495
-
496
- ```bash
497
- curl -X POST http://localhost:8000/query/graph \
498
- -H "Content-Type: application/json" \
499
- -d '{"query": "According to the 2021 review on de novo drug design by Bai et al., what are the three main types of deep learning architectures used for molecule generation, and how do they benefit molecular dynamics simulations?"}'
500
- ```
501
-
502
- ### Multi-hop
503
-
504
- **1. The ADMETlab 2.0 paper and the de novo drug design review both describe ML applications to drug development. At what specific stage does ADMETlab 2.0 intervene, and how does this complement generative design described in the review?**
505
-
506
- ```bash
507
- curl -X POST http://localhost:8000/query/graph \
508
- -H "Content-Type: application/json" \
509
- -d '{"query": "The ADMETlab 2.0 paper and the de novo drug design review both describe ML applications to drug development. At what specific stage does ADMETlab 2.0 intervene, and how does this complement generative design described in the review?"}'
510
- ```
511
-
512
- **2. How does the challenge of screening de novo designed molecules relate to the integrated platform provided by ADMETlab 2.0?**
513
-
514
- ```bash
515
- curl -X POST http://localhost:8000/query/graph \
516
- -H "Content-Type: application/json" \
517
- -d '{"query": "How does the challenge of screening de novo designed molecules relate to the integrated platform provided by ADMETlab 2.0?"}'
518
- ```
519
-
520
- ---
521
-
522
- ## Setup & Installation
523
-
524
- ### Prerequisites
525
-
526
- - Python 3.11+
527
- - Docker (for TigerGraph, Pipeline 3 only)
528
- - OpenAlex API key β€” needed for corpus download **and** at runtime by `paper_fetcher.py` to resolve full-text URLs
529
- - Groq API key
530
- - HuggingFace token (for LLM judge)
531
-
532
- ### Install Dependencies
533
-
534
- ```bash
535
- python -m venv .venv
536
- source .venv/bin/activate
537
- pip install -r requirements.txt
538
- ```
539
-
540
- ### Environment Variables
541
-
542
- Create a `.env` file in the project root:
543
-
544
- ```env
545
- # Required for all pipelines
546
- OPENALEX_API_KEY=your_key
547
-
548
- # Pipeline 1
549
- GEMINI_API_KEY=your_key
550
- GEMINI_MODEL=gemini-1.5-flash
551
-
552
- # Pipelines 2 & 3
553
- GROQ_API_KEY=your_key
554
- GROQ_API_KEY_1=your_key # optional: rotated on rate limit
555
- GROQ_API_KEY_2=your_key
556
- GROQ_MODEL=llama-3.3-70b-versatile
557
-
558
- # Evaluation
559
- HF_TOKEN=your_huggingface_token
560
- ```
561
-
562
- ### One-Time Setup
563
-
564
- **Step 1 β€” Download corpus:**
565
-
566
- ```bash
567
- python utils/download_aiml_data.py
568
- ```
569
-
570
- **Step 2 β€” Build Qdrant index (Pipelines 2 & 3):**
571
-
572
- ```bash
573
- python core/pipeline_2/indexer.py
574
- ```
575
-
576
- **Step 3 β€” Set up TigerGraph (Pipeline 3 only):**
577
-
578
- Start the TigerGraph community container and wait ~60s for it to be ready:
579
-
580
- ```bash
581
- docker run -d --init -p 14240:14240 --name tigergraph tigergraph/community:4.2.2
582
- # wait ~60 seconds for the container to finish initialising before running setup
583
- ```
584
-
585
- Ingest the paper graph (schema creation + embeddings + edge upserts). Safe to re-run β€” resumes from the last checkpoint:
586
- th
587
- ```bash
588
- python core/pipeline_3/setup.py
589
- ```
590
-
591
- ---
592
-
593
- ## Running the Server
594
-
595
- ```bash
596
- uvicorn app:app --reload --port 8000
597
- ```
598
-
599
- ### Endpoints
600
-
601
- | Method | Path | Pipeline |
602
- | ------ | ----------------- | ----------------------- |
603
- | `POST` | `/query/baseline` | Pipeline 1 β€” LLM-Only |
604
- | `POST` | `/query/rag` | Pipeline 2 β€” Hybrid RAG |
605
- | `POST` | `/query/graph` | Pipeline 3 β€” GraphRAG |
606
-
607
- ### Example Request
608
-
609
- ```bash
610
- curl -X POST http://localhost:8000/query/graph \
611
- -H "Content-Type: application/json" \
612
- -d '{"query": "What symmetries does the DPMD neural network explicitly preserve?"}'
613
- ```
614
-
615
- ### Running Benchmarks
616
-
617
- ```bash
618
- python run_benchmarks.py
619
- ```
620
-
621
- Configure which pipelines to run and where to resume at the top of `run_benchmarks.py`:
622
-
623
- ```python
624
- RUN_BASELINE = False
625
- RUN_HYBRID = True
626
- RUN_GRAPH = True
627
- START_QUESTION = 1 # resume from this question (1-indexed)
628
- LIMIT_QUESTIONS = None # set to N to run only N questions
629
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: TigerGraph Hack
3
+ emoji: πŸ“ˆ
4
+ colorFrom: gray
5
+ colorTo: gray
6
+ sdk: docker
7
+ pinned: false
8
+ license: mit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  ---
10
 
11
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference