# tanuj26rajput/rag-project architecture

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

- Interactive diagram: https://gitdiagram.com/tanuj26rajput/rag-project
- Repository: https://github.com/tanuj26rajput/rag-project

## Overview

This is a single-file Streamlit app for PDF question answering. The user uploads a PDF, the app extracts and indexes its text, then uses retrieval-augmented generation to answer questions and display chat history. The README also documents embeddings, FAISS retrieval, PDF parsing, and multi-turn chat; these are reflected alongside the sampled implementation. All source relationships shown are visible in model.py; the hosted Hugging Face model is an external dependency.

Main entry points: [`model.py`](https://github.com/tanuj26rajput/rag-project/blob/main/model.py) (RAG chain)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Chat interface"]
  node_streamlit["Streamlit UI<br/>[model.py]"]
  node_chat_history["Chat history<br/>[model.py]"]
end

subgraph group_documents["Document processing"]
  node_pdf_extract["PDF extraction<br/>[model.py]"]
  node_chunking["Text chunking<br/>[model.py]"]
  node_embeddings["Embeddings<br/>[model.py]"]
  node_faiss[("FAISS index<br/>[model.py]")]
  node_retriever["Similarity retriever<br/>[model.py]"]
end

subgraph group_answers["Answer generation"]
  node_chain["RAG chain<br/>[model.py]"]
  node_prompt["Context prompt<br/>[model.py]"]
  node_llm["Hugging Face LLM"]
  node_parser["Answer parser<br/>[model.py]"]
end

node_user(("User"))

node_user -->|"uploads and asks"| node_streamlit
node_streamlit -->|"calls load_docs"| node_pdf_extract
node_streamlit -->|"builds and invokes"| node_chain
node_streamlit -->|"stores and displays"| node_chat_history
node_chain -->|"splits documents"| node_chunking
node_chain -->|"creates embeddings"| node_embeddings
node_chain -->|"indexes chunks"| node_faiss
node_faiss -->|"creates retriever"| node_retriever
node_chain -->|"retrieves context"| node_retriever
node_chain -->|"formats context and question"| node_prompt
node_chain -->|"generates answer"| node_llm
node_chain -->|"parses output"| node_parser

click node_streamlit "https://github.com/tanuj26rajput/rag-project/blob/main/model.py"
click node_chat_history "https://github.com/tanuj26rajput/rag-project/blob/main/model.py"
click node_pdf_extract "https://github.com/tanuj26rajput/rag-project/blob/main/model.py"
click node_chunking "https://github.com/tanuj26rajput/rag-project/blob/main/model.py"
click node_embeddings "https://github.com/tanuj26rajput/rag-project/blob/main/model.py"
click node_faiss "https://github.com/tanuj26rajput/rag-project/blob/main/model.py"
click node_retriever "https://github.com/tanuj26rajput/rag-project/blob/main/model.py"
click node_chain "https://github.com/tanuj26rajput/rag-project/blob/main/model.py"
click node_prompt "https://github.com/tanuj26rajput/rag-project/blob/main/model.py"
click node_parser "https://github.com/tanuj26rajput/rag-project/blob/main/model.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_streamlit,node_chat_history,node_user toneBlue
class node_pdf_extract,node_chunking,node_embeddings,node_faiss,node_retriever toneAmber
class node_chain,node_prompt,node_llm,node_parser toneMint
```

## Components

### Chat interface

- [Streamlit UI](https://github.com/tanuj26rajput/rag-project/blob/main/model.py): `model.py`
- [Chat history](https://github.com/tanuj26rajput/rag-project/blob/main/model.py): `model.py`

### Document processing

- [PDF extraction](https://github.com/tanuj26rajput/rag-project/blob/main/model.py): `model.py`
- [Text chunking](https://github.com/tanuj26rajput/rag-project/blob/main/model.py): `model.py`
- [Embeddings](https://github.com/tanuj26rajput/rag-project/blob/main/model.py): `model.py`
- [FAISS index](https://github.com/tanuj26rajput/rag-project/blob/main/model.py): `model.py`
- [Similarity retriever](https://github.com/tanuj26rajput/rag-project/blob/main/model.py): `model.py`

### Answer generation

- [RAG chain](https://github.com/tanuj26rajput/rag-project/blob/main/model.py): `model.py`
- [Context prompt](https://github.com/tanuj26rajput/rag-project/blob/main/model.py): `model.py`
- **Hugging Face LLM**
- [Answer parser](https://github.com/tanuj26rajput/rag-project/blob/main/model.py): `model.py`

### Other components

- **User**

## Connections

- User → Streamlit UI: uploads and asks (evidence: `model.py`)
- Streamlit UI → PDF extraction: calls load_docs (evidence: `model.py`)
- Streamlit UI → RAG chain: builds and invokes (evidence: `model.py`)
- Streamlit UI → Chat history: stores and displays (evidence: `model.py`)
- RAG chain → Text chunking: splits documents (evidence: `model.py`)
- RAG chain → Embeddings: creates embeddings (evidence: `model.py`)
- RAG chain → FAISS index: indexes chunks (evidence: `model.py`)
- FAISS index → Similarity retriever: creates retriever (evidence: `model.py`)
- RAG chain → Similarity retriever: retrieves context (evidence: `model.py`)
- RAG chain → Context prompt: formats context and question (evidence: `model.py`)
- RAG chain → Hugging Face LLM: generates answer (evidence: `model.py`)
- RAG chain → Answer parser: parses output (evidence: `model.py`)
