File size: 6,582 Bytes
b21ec59
2f25a40
 
 
 
b21ec59
 
2f25a40
 
b21ec59
 
2f25a40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3f31583
2f25a40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3f31583
 
2f25a40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3f31583
 
2f25a40
3f31583
 
 
 
 
2f25a40
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
title: ResearchPath
emoji: πŸ—ΊοΈ
colorFrom: blue
colorTo: indigo
sdk: docker
pinned: false
license: mit
short_description: Agentic RL reading-path planner with grounded Q&A
---

# ResearchPath

> An agentic research-onboarding companion. Give it a target paper and your background; it builds a personalized, dependency-ordered reading plan with grounded explanations.
>
> **Demo domain:** Reinforcement Learning. **Architecture:** domain-agnostic.

---

## The problem

Getting into a new research field is brutal. You open the SOTA paper, it assumes 8 prior concepts. You read those papers, they assume 5 more. Existing tools (Perplexity, Elicit, Consensus) retrieve papers but don't *plan* β€” they don't tell you what order to read things in *based on your specific background*.

## What ResearchPath does

Input:
- A target paper or topic (e.g., *"PPO"*)
- Your current background (e.g., *"basic supervised ML, calculus, no RL"*)

Output:
1. **Prerequisite reading plan** β€” a topologically-sorted reading list of foundational papers, with a "why this is next" justification grounded in the dependency chain
2. **Concept genealogy** β€” how each key concept evolved across the chain
3. **Notation glossary** β€” reconciles symbols across papers (X in paper A = ΞΈ in paper B)
4. **Grounded Q&A** β€” ask follow-ups, every claim cites a specific paper section
5. *(Stretch)* **Open problems surfacer** β€” clusters "Future Work" sections from recent papers in the subfield

## Why this is genuinely agentic (not RAG-with-extra-steps)

The reading-path builder is a real planning problem:

```
read(target_paper) β†’ extract assumed prerequisites
  for each prerequisite:
    if user_knows(prereq): skip
    else: retrieve canonical paper for prereq β†’ recurse
build dependency DAG β†’ topologically sort β†’ generate bridge explanations
```

Graph traversal + recursive retrieval + reasoning over user state. Not "embed query, return top-5 chunks."

---

## Evaluation

Eval is the differentiator. Every change ships with numbers.

**Gold dataset:** 30 hand-authored (question, expected source, key claim) triples across 10 canonical RL papers. Difficulty-stratified: 7 easy / 15 medium / 8 hard. Questions adapted from OpenAI Spinning Up, Sutton & Barto concepts, and paper-specific mechanism questions.

### v1 β€” 10-paper corpus (1,093 chunks)

| Metric | Baseline RAG | + Hybrid Retrieval |
|---|---|---|
| Retrieval Recall@5 | **90.0%** | **89.7%** |
| Citation Presence | **86.7%** | **86.2%** |
| Answer Correctness | **36.7%** | **72.4%** |
| Avg Latency (s) | **5.07** | **4.58** |
| RAG Tokens (in/out) | **33,498 / 7,000** | **31,439 / 6,905** |

*Hybrid BM25+FAISS via RRF fusion (n=29). Answer Correctness nearly doubled (+35.7 pp) with no latency regression β€” driven by hybrid correctly surfacing in-paper chunks that dense embeddings de-prioritized.*

### v2 β€” Full 17-paper corpus (1,789 chunks)

Corpus expanded to all 17 canonical RL papers (PER, PPO, SAC, IMPALA, MuZero, DreamerV3, Decision Transformer added). Prerequisite graph updated with 11 new edges.

| Metric | Baseline RAG | + Hybrid Retrieval | + Reranker |
|---|---|---|---|
| Retrieval Recall@5 | **84.0%** | pending | **83.3%** |
| Citation Presence | **80.0%** | pending | **83.3%** |
| Answer Correctness | **48.0%** | pending | **56.7%** |
| Avg Latency (s) | **4.63** | pending | **5.13** |
| RAG Tokens (in/out) | **27,027 / 6,336** | pending | **31,579 / 11,215** |

*v2 baseline n=25 (5 skipped, Groq 100k TPD hit). Reranker: BM25+FAISS+CrossEncoder, n=30. Hybrid v2 pending token reset. Reranker adds +8.7 pp over v2 baseline; larger corpus raises baseline from 37% β†’ 48% even without retrieval improvements.*

---

## Stack

| Layer | Choice | Why |
|---|---|---|
| Planning LLM | Gemini 2.5 Flash Lite (free tier) | Strong reasoning, generous free quota |
| Fast LLM | Groq Llama 3.3 70B (free) | Fast inference for inner-loop retrieval |
| Embeddings | BAAI/bge-small-en-v1.5 | CPU-friendly, strong on academic text, free |
| Vector store | FAISS IndexFlatIP | Local, free, exact cosine, fast at ~5k chunks |
| Retrieval | BM25 + FAISS via RRF + CrossEncoder rerank | Three tiers, each measurably better |
| Agent framework | Static DAG + BFS + Kahn's topo sort | Deterministic planning, no LLM cost |
| UI | Streamlit | Demo-grade, ships fast |
| Eval | Custom harness + LLM-as-judge | Citation recall, answer correctness, latency |
| Deploy | Hugging Face Spaces | Free public URL |

---

## Status

- [x] Week 1 β€” Repo scaffold + smoke test
- [x] Week 1 β€” arXiv corpus ingestion (10/17 RL papers, 1,093 chunks)
- [x] Week 1 β€” Baseline RAG (FAISS + bge-small + Gemini/Groq), smoke tested
- [x] Week 2 β€” Eval harness + 30-question gold dataset
- [x] Week 2 β€” Baseline RAG numbers (Recall@5 90%, Answer Correctness 37%)
- [x] Week 2 β€” Hybrid BM25+FAISS retrieval via RRF (Answer Correctness 72%, +35 pp)
- [x] Week 3 β€” Reranker (cross-encoder): +8.7 pp over v2 baseline
- [x] Week 3 β€” Agentic planning loop: offline prerequisite-chain planner, 7 tests passing
- [x] Week 3 β€” Full 17-paper corpus (1,789 chunks) + expanded prerequisite DAG (21 edges)
- [x] Week 4 β€” Streamlit UI + HF Spaces deploy (Docker)
- [x] Week 4 β€” Tier 1 corpus expansion: Sutton & Barto, RLHF Book, CS224R, 5 web tutorials β†’ **5,531 chunks**
- [ ] Week 4 β€” Hybrid v2 eval (pending Groq token reset), ablation table complete, demo video

---

## Local development

```powershell
# 1. Install uv (one-time): https://astral.sh/uv
# 2. Sync dependencies
uv sync

# 3. Set up env
copy .env.example .env
# Fill in GEMINI_API_KEY and GROQ_API_KEY in .env

# 4. Run smoke test
uv run python scripts/smoke_test.py

# 5. Build corpus β€” three sources (one-time, ~25 min total)
# 5a. Research papers (17 arXiv PDFs)
uv run python scripts/fetch_corpus.py
# 5b. Textbooks + course notes (Sutton & Barto, RLHF Book, CS224R)
uv run python scripts/fetch_pdfs.py
# 5c. Web tutorials (Spinning Up, Lilian Weng, HF blog)
uv run python scripts/fetch_web_sources.py
# 5d. Parse all sources β†’ embed β†’ FAISS index (5,531 chunks)
uv run python scripts/parse_corpus.py
uv run python scripts/build_index.py

# 6. Ask a question
uv run python scripts/ask.py "What is the key idea behind PPO?"
uv run python scripts/ask.py --hybrid --rerank "How does Rainbow combine Double DQN and PER?"

# 7. Get a reading plan
uv run python scripts/plan.py --target PPO
uv run python scripts/plan.py --target Rainbow --known DQN

# 8. Run the full eval
uv run python scripts/run_eval.py --groq --hybrid
```