# yash-anpat/ai-document-assistant architecture

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

- Interactive diagram: https://gitdiagram.com/yash-anpat/ai-document-assistant
- Repository: https://github.com/yash-anpat/ai-document-assistant

## Overview

This is a Streamlit PDF question-answering app. Users upload a PDF, which the RAG engine extracts, chunks, embeds, and indexes; questions are answered from retrieved passages using Groq-hosted GPT-OSS, with page references shown in the chat. Components are divided by interface, document indexing, and question answering. The README documents the major capabilities; the sampled source shows their implementation and call relationships.

Main entry points: [`rag_pipeline.py`](https://github.com/yash-anpat/ai-document-assistant/blob/main/rag_pipeline.py) (RAG engine), [`app.py`](https://github.com/yash-anpat/ai-document-assistant/blob/main/app.py) (Streamlit chat)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Chat interface"]
  node_chat["Streamlit chat<br/>[app.py]"]
  node_session["Chat session<br/>[app.py]"]
  node_source_view["Source display<br/>[app.py]"]
end

subgraph group_indexing["Document indexing"]
  node_engine["RAG engine<br/>[rag_pipeline.py]"]
  node_pdf_extract["PDF extraction<br/>[rag_pipeline.py]"]
  node_chunking["Text chunking<br/>[rag_pipeline.py]"]
  node_embedding["Semantic embeddings<br/>[rag_pipeline.py]"]
  node_embedding_model["Sentence Transformers"]
  node_chunk_store["Chunk metadata<br/>[rag_pipeline.py]"]
  node_vector_index[("FAISS index<br/>[rag_pipeline.py]")]
end

subgraph group_answering["Question answering"]
  node_retrieval["Similarity retrieval<br/>[rag_pipeline.py]"]
  node_prompt["Grounded prompt<br/>[rag_pipeline.py]"]
  node_groq["Groq inference"]
  node_answer["Answer and sources<br/>[rag_pipeline.py]"]
end

node_user(("User"))

node_user -->|"uploads or asks"| node_chat
node_chat -->|"updates"| node_session
node_chat -->|"builds index"| node_engine
node_engine -->|"extracts pages"| node_pdf_extract
node_engine -->|"splits text"| node_chunking
node_engine -->|"encodes chunks"| node_embedding
node_embedding -->|"encodes text"| node_embedding_model
node_engine -->|"stores chunks"| node_chunk_store
node_engine -->|"adds embeddings"| node_vector_index
node_chat -->|"generates answer"| node_engine
node_engine -->|"retrieves context"| node_retrieval
node_retrieval -->|"encodes query"| node_embedding
node_retrieval -->|"searches vectors"| node_vector_index
node_retrieval -->|"reads chunks"| node_chunk_store
node_engine -->|"builds prompt"| node_prompt
node_prompt -->|"sends context"| node_groq
node_engine -->|"returns response"| node_answer
node_answer -->|"displays answer"| node_chat
node_answer -->|"provides citations"| node_source_view
node_source_view -->|"renders history"| node_session

click node_chat "https://github.com/yash-anpat/ai-document-assistant/blob/main/app.py"
click node_session "https://github.com/yash-anpat/ai-document-assistant/blob/main/app.py"
click node_source_view "https://github.com/yash-anpat/ai-document-assistant/blob/main/app.py"
click node_engine "https://github.com/yash-anpat/ai-document-assistant/blob/main/rag_pipeline.py"
click node_pdf_extract "https://github.com/yash-anpat/ai-document-assistant/blob/main/rag_pipeline.py"
click node_chunking "https://github.com/yash-anpat/ai-document-assistant/blob/main/rag_pipeline.py"
click node_embedding "https://github.com/yash-anpat/ai-document-assistant/blob/main/rag_pipeline.py"
click node_chunk_store "https://github.com/yash-anpat/ai-document-assistant/blob/main/rag_pipeline.py"
click node_vector_index "https://github.com/yash-anpat/ai-document-assistant/blob/main/rag_pipeline.py"
click node_retrieval "https://github.com/yash-anpat/ai-document-assistant/blob/main/rag_pipeline.py"
click node_prompt "https://github.com/yash-anpat/ai-document-assistant/blob/main/rag_pipeline.py"
click node_answer "https://github.com/yash-anpat/ai-document-assistant/blob/main/rag_pipeline.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_chat,node_session,node_source_view,node_user toneBlue
class node_engine,node_pdf_extract,node_chunking,node_embedding,node_embedding_model,node_chunk_store,node_vector_index toneAmber
class node_retrieval,node_prompt,node_groq,node_answer toneMint
```

## Components

### Chat interface

- [Streamlit chat](https://github.com/yash-anpat/ai-document-assistant/blob/main/app.py): `app.py`
- [Chat session](https://github.com/yash-anpat/ai-document-assistant/blob/main/app.py): `app.py`
- [Source display](https://github.com/yash-anpat/ai-document-assistant/blob/main/app.py): `app.py`

### Document indexing

- [RAG engine](https://github.com/yash-anpat/ai-document-assistant/blob/main/rag_pipeline.py): `rag_pipeline.py`
- [PDF extraction](https://github.com/yash-anpat/ai-document-assistant/blob/main/rag_pipeline.py): `rag_pipeline.py`
- [Text chunking](https://github.com/yash-anpat/ai-document-assistant/blob/main/rag_pipeline.py): `rag_pipeline.py`
- [Semantic embeddings](https://github.com/yash-anpat/ai-document-assistant/blob/main/rag_pipeline.py): `rag_pipeline.py`
- **Sentence Transformers**
- [Chunk metadata](https://github.com/yash-anpat/ai-document-assistant/blob/main/rag_pipeline.py): `rag_pipeline.py`
- [FAISS index](https://github.com/yash-anpat/ai-document-assistant/blob/main/rag_pipeline.py): `rag_pipeline.py`

### Question answering

- [Similarity retrieval](https://github.com/yash-anpat/ai-document-assistant/blob/main/rag_pipeline.py): `rag_pipeline.py`
- [Grounded prompt](https://github.com/yash-anpat/ai-document-assistant/blob/main/rag_pipeline.py): `rag_pipeline.py`
- **Groq inference**
- [Answer and sources](https://github.com/yash-anpat/ai-document-assistant/blob/main/rag_pipeline.py): `rag_pipeline.py`

### Other components

- **User**

## Connections

- User → Streamlit chat: uploads or asks (evidence: `app.py`)
- Streamlit chat → Chat session: updates (evidence: `app.py`)
- Streamlit chat → RAG engine: builds index (evidence: `app.py`)
- RAG engine → PDF extraction: extracts pages (evidence: `rag_pipeline.py`)
- RAG engine → Text chunking: splits text (evidence: `rag_pipeline.py`)
- RAG engine → Semantic embeddings: encodes chunks (evidence: `rag_pipeline.py`)
- Semantic embeddings → Sentence Transformers: encodes text (evidence: `rag_pipeline.py`)
- RAG engine → Chunk metadata: stores chunks (evidence: `rag_pipeline.py`)
- RAG engine → FAISS index: adds embeddings (evidence: `rag_pipeline.py`)
- Streamlit chat → RAG engine: generates answer (evidence: `app.py`)
- RAG engine → Similarity retrieval: retrieves context (evidence: `rag_pipeline.py`)
- Similarity retrieval → Semantic embeddings: encodes query (evidence: `rag_pipeline.py`)
- Similarity retrieval → FAISS index: searches vectors (evidence: `rag_pipeline.py`)
- Similarity retrieval → Chunk metadata: reads chunks (evidence: `rag_pipeline.py`)
- RAG engine → Grounded prompt: builds prompt (evidence: `rag_pipeline.py`)
- Grounded prompt → Groq inference: sends context (evidence: `rag_pipeline.py`)
- RAG engine → Answer and sources: returns response (evidence: `rag_pipeline.py`)
- Answer and sources → Streamlit chat: displays answer (evidence: `app.py`)
- Answer and sources → Source display: provides citations (evidence: `app.py`)
- Source display → Chat session: renders history (evidence: `app.py`)
