# syedraihanm/rag-pdf-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/syedraihanm/rag-pdf-chatbot
- Repository: https://github.com/syedraihanm/rag-pdf-chatbot

## Overview

This repository is a PDF-focused RAG chatbot with a Streamlit interface and a FastAPI backend. The main workflow uploads a PDF, parses and chunks it, creates a local FAISS index, then rewrites conversational questions, retrieves relevant chunks, and streams a Groq-generated answer with page citations. A separate evaluation script retrieves context and uses Groq as an LLM judge. The graph reflects the shown calls and documented capabilities; unsampled implementation details are not expanded.

Main entry points: [`src/vector_store.py`](https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/src/vector_store.py) (Embedding and indexing), [`evaluate.py`](https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/evaluate.py) (LLM-judge evaluation), [`src/retrieval.py`](https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/src/retrieval.py) (Chunk retrieval), [`api/main.py`](https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/api/main.py) (FastAPI endpoints)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["User interface"]
  node_ui["Streamlit dashboard<br/>[app.py]"]
end

subgraph group_service["Chat service"]
  node_api["FastAPI endpoints<br/>[main.py]"]
  node_chat["Chat orchestration<br/>[chat.py]"]
  node_rewriter["Query rewriting<br/>[chat.py]"]
  node_retrieval["Chunk retrieval<br/>[retrieval.py]"]
end

subgraph group_indexing["Document indexing"]
  node_ingest["PDF parsing and splitting<br/>[ingest.py]"]
  node_vector["Embedding and indexing<br/>[vector_store.py]"]
  node_faiss[("FAISS index<br/>[vector_store.py]")]
  node_chunks[("Stored chunks<br/>[vector_store.py]")]
  node_config["Storage configuration<br/>[config.py]"]
end

subgraph group_evaluation["Evaluation"]
  node_evaluation["LLM-judge evaluation<br/>[evaluate.py]"]
  node_dataset["Evaluation questions"]
  node_results["Evaluation results<br/>[ragas_results.csv]"]
end

node_user(("Document user"))
node_groq{{"Groq LLM"}}

node_user -->|"asks and uploads"| node_ui
node_ui -->|"calls endpoints"| node_api
node_api -->|"indexes upload"| node_vector
node_vector -->|"loads and splits"| node_ingest
node_ingest -->|"gets PDF path"| node_config
node_vector -->|"gets store paths"| node_config
node_vector -->|"writes index"| node_faiss
node_vector -->|"saves chunks"| node_chunks
node_api -->|"requests stream"| node_chat
node_chat -->|"rewrites follow-up"| node_rewriter
node_chat -->|"retrieves context"| node_retrieval
node_retrieval -->|"searches vectors"| node_faiss
node_retrieval -->|"loads chunk data"| node_chunks
node_retrieval -->|"gets store paths"| node_config
node_chat -->|"rewrites and generates"| node_groq
node_api -->|"streams tokens and citations"| node_ui
node_user -.->|"benchmarks answers"| node_evaluation
node_evaluation -->|"reads questions"| node_dataset
node_evaluation -->|"retrieves context"| node_retrieval
node_evaluation -->|"scores responses"| node_groq
node_evaluation -->|"writes scores"| node_results

click node_ui "https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/app.py"
click node_api "https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/api/main.py"
click node_chat "https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/src/chat.py"
click node_rewriter "https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/src/chat.py"
click node_retrieval "https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/src/retrieval.py"
click node_ingest "https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/src/ingest.py"
click node_vector "https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/src/vector_store.py"
click node_faiss "https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/src/vector_store.py"
click node_chunks "https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/src/vector_store.py"
click node_config "https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/src/config.py"
click node_evaluation "https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/evaluate.py"
click node_dataset "https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/data_structures_rag_evaluation.csv"
click node_results "https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/ragas_results.csv"

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_ui,node_user toneBlue
class node_api,node_chat,node_rewriter,node_retrieval toneAmber
class node_ingest,node_vector,node_faiss,node_chunks,node_config toneMint
class node_evaluation,node_dataset,node_results toneRose
class node_groq toneIndigo
```

## Components

### User interface

- [Streamlit dashboard](https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/app.py): `app.py`

### Chat service

- [FastAPI endpoints](https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/api/main.py): `api/main.py`
- [Chat orchestration](https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/src/chat.py): `src/chat.py`
- [Query rewriting](https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/src/chat.py): `src/chat.py`
- [Chunk retrieval](https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/src/retrieval.py): `src/retrieval.py`

### Document indexing

- [PDF parsing and splitting](https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/src/ingest.py): `src/ingest.py`
- [Embedding and indexing](https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/src/vector_store.py): `src/vector_store.py`
- [FAISS index](https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/src/vector_store.py): `src/vector_store.py`
- [Stored chunks](https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/src/vector_store.py): `src/vector_store.py`
- [Storage configuration](https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/src/config.py): `src/config.py`

### Evaluation

- [LLM-judge evaluation](https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/evaluate.py): `evaluate.py`
- [Evaluation questions](https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/data_structures_rag_evaluation.csv): `data_structures_rag_evaluation.csv`
- [Evaluation results](https://github.com/syedraihanm/rag-pdf-chatbot/blob/main/ragas_results.csv): `ragas_results.csv`

### Other components

- **Document user**
- **Groq LLM**

## Connections

- Document user → Streamlit dashboard: asks and uploads (evidence: `README.md`)
- Streamlit dashboard → FastAPI endpoints: calls endpoints (evidence: `app.py`)
- FastAPI endpoints → Embedding and indexing: indexes upload (evidence: `api/main.py`)
- Embedding and indexing → PDF parsing and splitting: loads and splits (evidence: `src/vector_store.py`)
- PDF parsing and splitting → Storage configuration: gets PDF path (evidence: `src/ingest.py`)
- Embedding and indexing → Storage configuration: gets store paths (evidence: `src/vector_store.py`)
- Embedding and indexing → FAISS index: writes index (evidence: `src/vector_store.py`)
- Embedding and indexing → Stored chunks: saves chunks (evidence: `src/vector_store.py`)
- FastAPI endpoints → Chat orchestration: requests stream (evidence: `api/main.py`)
- Chat orchestration → Query rewriting: rewrites follow-up (evidence: `src/chat.py`)
- Chat orchestration → Chunk retrieval: retrieves context (evidence: `src/chat.py`)
- Chunk retrieval → FAISS index: searches vectors (evidence: `src/retrieval.py`)
- Chunk retrieval → Stored chunks: loads chunk data (evidence: `src/retrieval.py`)
- Chunk retrieval → Storage configuration: gets store paths (evidence: `src/retrieval.py`)
- Chat orchestration → Groq LLM: rewrites and generates (evidence: `src/chat.py`)
- FastAPI endpoints → Streamlit dashboard: streams tokens and citations (evidence: `app.py`)
- Document user → LLM-judge evaluation: benchmarks answers (evidence: `README.md`)
- LLM-judge evaluation → Evaluation questions: reads questions (evidence: `evaluate.py`)
- LLM-judge evaluation → Chunk retrieval: retrieves context (evidence: `evaluate.py`)
- LLM-judge evaluation → Groq LLM: scores responses (evidence: `evaluate.py`)
- LLM-judge evaluation → Evaluation results: writes scores (evidence: `evaluate.py`)
