Summary
The current Deep Research module is a UI-only implementation that searches PubMed/Semantic Scholar directly from the Reflex frontend process, concatenates article abstracts into a massive prompt, and sends it to the generic /api/v1/query endpoint for LLM synthesis. There is no dedicated backend, no screening, no bias assessment, no evidence grading, and no traceability. It frequently times out and silently swallows errors.
Proposal: Replace the entire module with an integration of CDR (Clinical Deep Research) — a production-grade systematic review engine with PICO parsing, automated screening, RoB2 bias assessment, GRADE certainty, claim verification, and PRISMA-compliant report generation.
Current Architecture (Broken)
UI (state.py) → perform_scientific_research() → PubMed/SemanticScholar/DuckDuckGo
↓
build_scientific_research_prompt() → giant prompt (~6000 tokens)
↓
POST /api/v1/query → generic LLM → markdown blob
Current Problems
- Frequent timeouts — The prompt is enormous (all article abstracts + a massive template), and HuggingFace inference has limited throughput.
max_tokens: 6000 with a huge input regularly exceeds the 240s timeout.
- Silent API failures — PubMed and Semantic Scholar errors are caught with bare
except and print(). If both APIs fail, the LLM receives an almost empty prompt with no warning.
duckduckgo_search may not be installed — Conditional import (HAS_DDGS). If missing, web fallback silently returns empty.
research_phase never transitions to "complete" — State machine is broken; stays at "researching" forever.
- No screening — Every retrieved article is included regardless of relevance.
- No evidence grading — Heuristic title-based classification only.
- No traceability — Claims in the output cannot be traced to source articles.
- No server-side orchestration — Everything runs in the browser's Reflex state process.
Proposed Architecture (CDR Integration)
UI (new research panel) → POST /api/v1/research/run {pico, config}
↓
CDR Pipeline (LangGraph DAG):
PICO Parsing → Search Plan → PubMed/SemanticScholar Retrieval
↓
Automated Screening (inclusion/exclusion)
↓
Data Extraction + RoB2 Bias Assessment
↓
Evidence Synthesis + GRADE Certainty + Claim Verification
↓
PRISMA-Compliant Report Generation
↓
UI polls GET /api/v1/research/{run_id}/status → progress updates
UI fetches GET /api/v1/research/{run_id}/report → final report
CDR vs Current Deep Research
| Capability |
Current |
CDR |
| Question parsing |
Basic sub-question generation |
PICO framework extraction |
| Literature search |
PubMed + Semantic Scholar (basic) |
PubMed + Semantic Scholar + fulltext |
| Screening |
None |
LLM-based inclusion/exclusion with reasons |
| Bias assessment |
None |
RoB2 + ROBINS-I |
| Evidence grading |
Heuristic (title-based) |
GRADE certainty framework |
| Synthesis |
Single LLM prompt |
Multi-step: synthesis → critique → verification |
| Output |
Markdown blob |
PRISMA-compliant report (MD/HTML/JSON) |
| Orchestration |
Sequential async in UI state |
LangGraph DAG with state management |
| Traceability |
None |
Full claim → source traceability |
| Quality metrics |
None |
RAGAs-inspired evaluation |
Technical Tasks
A. Backend — CDR Integration
B. UI — Complete Rebuild
The current UI (scientific_search.py, web_search.py, research portions of state.py and app.py) is designed around a "search + prompt LLM" flow and cannot be adapted for CDR. Build new:
C. Cleanup
Files Affected
| File |
Change |
run_api.py |
Add 3 new research endpoints |
ui/medex_ui/state.py |
Replace research state + handlers |
ui/medex_ui/app.py |
New research panel components |
ui/medex_ui/scientific_search.py |
Deprecate |
ui/medex_ui/web_search.py |
Deprecate |
requirements.txt |
Add CDR dependencies |
New: src/medex/research/ |
CDR integration service layer |
Dependencies
- CDR repository must be packaged or HTTP-accessible
- LLM provider configuration (Gemini/Groq/HuggingFace) shared with CDR
- PubMed E-utilities and Semantic Scholar APIs (free, no keys)
Summary
The current Deep Research module is a UI-only implementation that searches PubMed/Semantic Scholar directly from the Reflex frontend process, concatenates article abstracts into a massive prompt, and sends it to the generic
/api/v1/queryendpoint for LLM synthesis. There is no dedicated backend, no screening, no bias assessment, no evidence grading, and no traceability. It frequently times out and silently swallows errors.Proposal: Replace the entire module with an integration of CDR (Clinical Deep Research) — a production-grade systematic review engine with PICO parsing, automated screening, RoB2 bias assessment, GRADE certainty, claim verification, and PRISMA-compliant report generation.
Current Architecture (Broken)
Current Problems
max_tokens: 6000with a huge input regularly exceeds the 240s timeout.exceptandprint(). If both APIs fail, the LLM receives an almost empty prompt with no warning.duckduckgo_searchmay not be installed — Conditional import (HAS_DDGS). If missing, web fallback silently returns empty.research_phasenever transitions to"complete"— State machine is broken; stays at"researching"forever.Proposed Architecture (CDR Integration)
CDR vs Current Deep Research
Technical Tasks
A. Backend — CDR Integration
/api/v1/research/runendpoint — accepts PICO input, starts async CDR pipeline, returnsrun_id/api/v1/research/{run_id}/status— returns pipeline progress (current node, articles screened, etc.)/api/v1/research/{run_id}/report— returns final PRISMA reportrequirements.txt(langgraph,langchain-core, provider packages)B. UI — Complete Rebuild
The current UI (
scientific_search.py,web_search.py, research portions ofstate.pyandapp.py) is designed around a "search + prompt LLM" flow and cannot be adapted for CDR. Build new:C. Cleanup
ui/medex_ui/scientific_search.py(1092 lines)ui/medex_ui/web_search.py(343 lines)perform_scientific_research/build_scientific_research_promptimports fromstate.pyresearch_*state variables that no longer applyFiles Affected
run_api.pyui/medex_ui/state.pyui/medex_ui/app.pyui/medex_ui/scientific_search.pyui/medex_ui/web_search.pyrequirements.txtsrc/medex/research/Dependencies