# dingzehu/arxiv-rag architecture

> Architecture diagram of the GitHub repository dingzehu/arxiv-rag, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dingzehu/arxiv-rag
- Repository: https://github.com/dingzehu/arxiv-rag

## Overview

arxiv-rag provides semantic search and cited Q&A over indexed machine-learning papers, with arXiv and PDF-upload ingestion, scheduled evaluation, and MLflow tracking. A user enters a question in the React interface; the app posts it to FastAPI, whose RAG service embeds it, retrieves similar pgvector chunks, and asks Gemini for a grounded answer returned with sources. Ingestion fetches or accepts documents, extracts and chunks text, embeds it, and stores it. The graph also shows batch evaluation and paper-management capabilities documented in the README or routes. Unsampled DAG and frontend details are represented only where documented.

Main entry points: [`backend/app/services/ingestion.py`](https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/services/ingestion.py) (Ingestion service), [`backend/app/api/routes.py`](https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/api/routes.py) (API routes), [`backend/app/services/rag_pipeline.py`](https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/services/rag_pipeline.py) (RAG search), [`backend/app/services/evaluator.py`](https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/services/evaluator.py) (Answer evaluator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Search interface"]
  node_react["Search app<br/>[App.jsx]"]
  node_searchbar["Question input<br/>[SearchBar.jsx]"]
  node_answer["Answer display<br/>[AnswerCard.jsx]"]
  node_sources["Source list<br/>[SourceList.jsx]"]
end

subgraph group_api["Backend API"]
  node_fastapi["FastAPI app<br/>[main.py]"]
  node_routes["API routes<br/>[routes.py]"]
  node_schemas["Request schemas<br/>[schemas.py]"]
end

subgraph group_ingestion["Paper ingestion"]
  node_arxiv_fetch["arXiv fetcher<br/>[arxiv_fetcher.py]"]
  node_pdf["PDF extraction<br/>[pdf_extractor.py]"]
  node_chunker["Text chunking<br/>[chunker.py]"]
  node_embedder["Embedding service<br/>[embedder.py]"]
  node_ingestion_service["Ingestion service<br/>[ingestion.py]"]
  node_airflow["Scheduled pipeline"]
end

subgraph group_quality["Retrieval and evaluation"]
  node_rag["RAG search<br/>[rag_pipeline.py]"]
  node_evaluator["Answer evaluator<br/>[evaluator.py]"]
  node_golden["Golden questions"]
end

subgraph group_platform["Data and tracking"]
  node_config["App settings<br/>[config.py]"]
  node_database["DB session setup<br/>[database.py]"]
  node_models["Paper and chunks<br/>[db.py]"]
  node_postgres[("PostgreSQL pgvector")]
end

node_user(("Researcher"))
node_gemini{{"Gemini API"}}
node_arxiv{{"arXiv API"}}
node_mlflow[("MLflow tracking")]

node_user -->|"enters question"| node_searchbar
node_searchbar -->|"submits question"| node_react
node_react -->|"POST /search"| node_routes
node_react -->|"renders answer"| node_answer
node_react -->|"renders sources"| node_sources
node_fastapi -->|"registers routes"| node_routes
node_routes -->|"validates requests"| node_schemas
node_routes -->|"calls search"| node_rag
node_routes -->|"calls ingestion"| node_ingestion_service
node_routes -->|"calls evaluation"| node_evaluator
node_airflow -->|"posts ingest and evaluate"| node_fastapi
node_ingestion_service -->|"fetches papers"| node_arxiv_fetch
node_ingestion_service -->|"extracts PDF text"| node_pdf
node_ingestion_service -->|"chunks text"| node_chunker
node_ingestion_service -->|"embeds chunks"| node_embedder
node_ingestion_service -->|"stores papers and chunks"| node_models
node_arxiv_fetch -->|"fetches metadata"| node_arxiv
node_embedder -->|"requests embeddings"| node_gemini
node_rag -->|"embeds query"| node_embedder
node_rag -->|"queries similar chunks"| node_models
node_rag -->|"generates answer"| node_gemini
node_evaluator -->|"evaluates search result"| node_rag
node_evaluator -->|"loads batch questions"| node_golden
node_evaluator -->|"scores answer"| node_gemini
node_ingestion_service -->|"logs ingestion metrics"| node_mlflow
node_rag -->|"logs search run"| node_mlflow
node_evaluator -->|"logs evaluation scores"| node_mlflow
node_database -->|"reads database URL"| node_config
node_database -->|"opens sessions"| node_postgres
node_models -->|"uses declarative base"| node_database
node_routes -->|"depends on DB session"| node_database
node_ingestion_service -->|"reads pipeline settings"| node_config

click node_react "https://github.com/dingzehu/arxiv-rag/blob/main/frontend/src/App.jsx"
click node_searchbar "https://github.com/dingzehu/arxiv-rag/blob/main/frontend/src/components/SearchBar.jsx"
click node_answer "https://github.com/dingzehu/arxiv-rag/blob/main/frontend/src/components/AnswerCard.jsx"
click node_sources "https://github.com/dingzehu/arxiv-rag/blob/main/frontend/src/components/SourceList.jsx"
click node_fastapi "https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/main.py"
click node_routes "https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/api/routes.py"
click node_schemas "https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/models/schemas.py"
click node_arxiv_fetch "https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/services/arxiv_fetcher.py"
click node_pdf "https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/services/pdf_extractor.py"
click node_chunker "https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/services/chunker.py"
click node_embedder "https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/services/embedder.py"
click node_ingestion_service "https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/services/ingestion.py"
click node_airflow "https://github.com/dingzehu/arxiv-rag/blob/main/airflow/dags/arxiv_pipeline_dag.py"
click node_rag "https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/services/rag_pipeline.py"
click node_evaluator "https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/services/evaluator.py"
click node_golden "https://github.com/dingzehu/arxiv-rag/blob/main/evaluation/golden_test_set.json"
click node_config "https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/config.py"
click node_database "https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/database.py"
click node_models "https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/models/db.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_react,node_searchbar,node_answer,node_sources toneBlue
class node_fastapi,node_routes,node_schemas,node_mlflow toneAmber
class node_arxiv_fetch,node_pdf,node_chunker,node_embedder,node_ingestion_service,node_airflow,node_gemini,node_arxiv toneMint
class node_rag,node_evaluator,node_golden toneRose
class node_config,node_database,node_models,node_postgres,node_user toneIndigo
```

## Components

### Search interface

- [Search app](https://github.com/dingzehu/arxiv-rag/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Question input](https://github.com/dingzehu/arxiv-rag/blob/main/frontend/src/components/SearchBar.jsx): `frontend/src/components/SearchBar.jsx`
- [Answer display](https://github.com/dingzehu/arxiv-rag/blob/main/frontend/src/components/AnswerCard.jsx): `frontend/src/components/AnswerCard.jsx`
- [Source list](https://github.com/dingzehu/arxiv-rag/blob/main/frontend/src/components/SourceList.jsx): `frontend/src/components/SourceList.jsx`

### Backend API

- [FastAPI app](https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/main.py): `backend/app/main.py`
- [API routes](https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/api/routes.py): `backend/app/api/routes.py`
- [Request schemas](https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/models/schemas.py): `backend/app/models/schemas.py`

### Paper ingestion

- [arXiv fetcher](https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/services/arxiv_fetcher.py): `backend/app/services/arxiv_fetcher.py`
- [PDF extraction](https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/services/pdf_extractor.py): `backend/app/services/pdf_extractor.py`
- [Text chunking](https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/services/chunker.py): `backend/app/services/chunker.py`
- [Embedding service](https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/services/embedder.py): `backend/app/services/embedder.py`
- [Ingestion service](https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/services/ingestion.py): `backend/app/services/ingestion.py`
- [Scheduled pipeline](https://github.com/dingzehu/arxiv-rag/blob/main/airflow/dags/arxiv_pipeline_dag.py): `airflow/dags/arxiv_pipeline_dag.py`

### Retrieval and evaluation

- [RAG search](https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/services/rag_pipeline.py): `backend/app/services/rag_pipeline.py`
- [Answer evaluator](https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/services/evaluator.py): `backend/app/services/evaluator.py`
- [Golden questions](https://github.com/dingzehu/arxiv-rag/blob/main/evaluation/golden_test_set.json): `evaluation/golden_test_set.json`

### Data and tracking

- [App settings](https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/config.py): `backend/app/config.py`
- [DB session setup](https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/database.py): `backend/app/database.py`
- [Paper and chunks](https://github.com/dingzehu/arxiv-rag/blob/main/backend/app/models/db.py): `backend/app/models/db.py`
- **PostgreSQL pgvector**

### Other components

- **Researcher**
- **Gemini API**
- **arXiv API**
- **MLflow tracking**

## Connections

- Researcher → Question input: enters question (evidence: `README.md`)
- Question input → Search app: submits question (evidence: `frontend/src/App.jsx`)
- Search app → API routes: POST /search (evidence: `frontend/src/App.jsx`)
- Search app → Answer display: renders answer (evidence: `frontend/src/App.jsx`)
- Search app → Source list: renders sources (evidence: `frontend/src/App.jsx`)
- FastAPI app → API routes: registers routes (evidence: `backend/app/main.py`)
- API routes → Request schemas: validates requests (evidence: `backend/app/api/routes.py`)
- API routes → RAG search: calls search (evidence: `backend/app/api/routes.py`)
- API routes → Ingestion service: calls ingestion (evidence: `backend/app/api/routes.py`)
- API routes → Answer evaluator: calls evaluation (evidence: `backend/app/api/routes.py`)
- Scheduled pipeline → FastAPI app: posts ingest and evaluate (evidence: `README.md`)
- Ingestion service → arXiv fetcher: fetches papers (evidence: `backend/app/services/ingestion.py`)
- Ingestion service → PDF extraction: extracts PDF text (evidence: `backend/app/services/ingestion.py`)
- Ingestion service → Text chunking: chunks text (evidence: `backend/app/services/ingestion.py`)
- Ingestion service → Embedding service: embeds chunks (evidence: `backend/app/services/ingestion.py`)
- Ingestion service → Paper and chunks: stores papers and chunks (evidence: `backend/app/services/ingestion.py`)
- arXiv fetcher → arXiv API: fetches metadata (evidence: `README.md`)
- Embedding service → Gemini API: requests embeddings (evidence: `README.md`)
- RAG search → Embedding service: embeds query (evidence: `backend/app/services/rag_pipeline.py`)
- RAG search → Paper and chunks: queries similar chunks (evidence: `backend/app/services/rag_pipeline.py`)
- RAG search → Gemini API: generates answer (evidence: `README.md`)
- Answer evaluator → RAG search: evaluates search result (evidence: `backend/app/services/evaluator.py`)
- Answer evaluator → Golden questions: loads batch questions (evidence: `backend/app/services/evaluator.py`)
- Answer evaluator → Gemini API: scores answer (evidence: `backend/app/services/evaluator.py`)
- Ingestion service → MLflow tracking: logs ingestion metrics (evidence: `backend/app/services/ingestion.py`)
- RAG search → MLflow tracking: logs search run (evidence: `backend/app/services/rag_pipeline.py`)
- Answer evaluator → MLflow tracking: logs evaluation scores (evidence: `backend/app/services/evaluator.py`)
- DB session setup → App settings: reads database URL (evidence: `backend/app/database.py`)
- DB session setup → PostgreSQL pgvector: opens sessions (evidence: `README.md`)
- Paper and chunks → DB session setup: uses declarative base (evidence: `backend/app/models/db.py`)
- API routes → DB session setup: depends on DB session (evidence: `backend/app/api/routes.py`)
- Ingestion service → App settings: reads pipeline settings (evidence: `backend/app/services/ingestion.py`)
