# gauravk221b/pdf-rag-assistant architecture

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

- Interactive diagram: https://gitdiagram.com/gauravk221b/pdf-rag-assistant
- Repository: https://github.com/gauravk221b/pdf-rag-assistant

## Overview

PDF RAG Assistant lets a user upload a text-based PDF, ask a question, and see an answer with the retrieved passages, page references, similarity scores, and provider. The main flow runs through the Streamlit UI into PDF processing and indexing, then query retrieval and LLM generation before results are displayed. Gemini is attempted first, with Groq as fallback. The README documents the retrieval and attribution capabilities; the graph’s implementation links are based on the shown app.py and rag.py excerpts.

Main entry points: [`rag.py`](https://github.com/gauravk221b/pdf-rag-assistant/blob/main/rag.py) (Pipeline builder), [`app.py`](https://github.com/gauravk221b/pdf-rag-assistant/blob/main/app.py) (Streamlit interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

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

subgraph group_retrieval["PDF Retrieval"]
  node_pipeline["Pipeline builder<br/>[rag.py]"]
  node_pdf["PDF extraction<br/>[rag.py]"]
  node_chunking["Text chunking<br/>[rag.py]"]
  node_embedding["Embedding generation<br/>[rag.py]"]
  node_index[("FAISS index<br/>[rag.py]")]
  node_search["Semantic search<br/>[rag.py]"]
end

subgraph group_generation["Answer Generation"]
  node_answer["Answer orchestration<br/>[rag.py]"]
  node_llm["LLM fallback dispatcher<br/>[rag.py]"]
  node_gemini{{"Gemini API"}}
  node_groq{{"Groq API"}}
end

node_user(("PDF user"))

node_user -->|"uploads / asks"| node_ui
node_ui -->|"processes PDF"| node_pipeline
node_pipeline -->|"extracts pages"| node_pdf
node_pdf -->|"chunks text"| node_chunking
node_pipeline -->|"creates embeddings"| node_embedding
node_pipeline -->|"builds index"| node_index
node_ui -->|"submits question"| node_answer
node_answer -->|"retrieves top 3"| node_search
node_search -->|"searches"| node_index
node_search -->|"encodes query"| node_embedding
node_answer -->|"sends prompt"| node_llm
node_llm -->|"tries first"| node_gemini
node_llm -->|"falls back"| node_groq
node_answer -->|"returns answer and sources"| node_ui

click node_ui "https://github.com/gauravk221b/pdf-rag-assistant/blob/main/app.py"
click node_pipeline "https://github.com/gauravk221b/pdf-rag-assistant/blob/main/rag.py"
click node_pdf "https://github.com/gauravk221b/pdf-rag-assistant/blob/main/rag.py"
click node_chunking "https://github.com/gauravk221b/pdf-rag-assistant/blob/main/rag.py"
click node_embedding "https://github.com/gauravk221b/pdf-rag-assistant/blob/main/rag.py"
click node_index "https://github.com/gauravk221b/pdf-rag-assistant/blob/main/rag.py"
click node_search "https://github.com/gauravk221b/pdf-rag-assistant/blob/main/rag.py"
click node_answer "https://github.com/gauravk221b/pdf-rag-assistant/blob/main/rag.py"
click node_llm "https://github.com/gauravk221b/pdf-rag-assistant/blob/main/rag.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_ui,node_user toneBlue
class node_pipeline,node_pdf,node_chunking,node_embedding,node_index,node_search toneAmber
class node_answer,node_llm,node_gemini,node_groq toneMint
```

## Components

### User Interface

- [Streamlit interface](https://github.com/gauravk221b/pdf-rag-assistant/blob/main/app.py): `app.py`

### PDF Retrieval

- [Pipeline builder](https://github.com/gauravk221b/pdf-rag-assistant/blob/main/rag.py): `rag.py`
- [PDF extraction](https://github.com/gauravk221b/pdf-rag-assistant/blob/main/rag.py): `rag.py`
- [Text chunking](https://github.com/gauravk221b/pdf-rag-assistant/blob/main/rag.py): `rag.py`
- [Embedding generation](https://github.com/gauravk221b/pdf-rag-assistant/blob/main/rag.py): `rag.py`
- [FAISS index](https://github.com/gauravk221b/pdf-rag-assistant/blob/main/rag.py): `rag.py`
- [Semantic search](https://github.com/gauravk221b/pdf-rag-assistant/blob/main/rag.py): `rag.py`

### Answer Generation

- [Answer orchestration](https://github.com/gauravk221b/pdf-rag-assistant/blob/main/rag.py): `rag.py`
- [LLM fallback dispatcher](https://github.com/gauravk221b/pdf-rag-assistant/blob/main/rag.py): `rag.py`
- **Gemini API**
- **Groq API**

### Other components

- **PDF user**

## Connections

- PDF user → Streamlit interface: uploads / asks (evidence: `README.md`)
- Streamlit interface → Pipeline builder: processes PDF (evidence: `app.py`)
- Pipeline builder → PDF extraction: extracts pages (evidence: `rag.py`)
- PDF extraction → Text chunking: chunks text (evidence: `rag.py`)
- Pipeline builder → Embedding generation: creates embeddings (evidence: `rag.py`)
- Pipeline builder → FAISS index: builds index (evidence: `rag.py`)
- Streamlit interface → Answer orchestration: submits question (evidence: `app.py`)
- Answer orchestration → Semantic search: retrieves top 3 (evidence: `rag.py`)
- Semantic search → FAISS index: searches (evidence: `rag.py`)
- Semantic search → Embedding generation: encodes query (evidence: `rag.py`)
- Answer orchestration → LLM fallback dispatcher: sends prompt (evidence: `rag.py`)
- LLM fallback dispatcher → Gemini API: tries first (evidence: `rag.py`)
- LLM fallback dispatcher → Groq API: falls back (evidence: `rag.py`)
- Answer orchestration → Streamlit interface: returns answer and sources (evidence: `app.py`)
