# sarathy-10/ai_industial_chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/sarathy-10/ai_industial_chatbot
- Repository: https://github.com/sarathy-10/ai_industial_chatbot

## Overview

This is a document-grounded industrial chatbot with two principal stages: offline PDF indexing and online question answering. Users ask through the Streamlit interface (or the documented CLI); the RAG layer retrieves relevant chunks, generates a grounded answer, and returns source metadata for display. The README documents these capabilities; the sampled source shows the indexing implementation and portions of the UI and RAG flow. Some internal details are unsampled, so the graph avoids asserting their call relationships.

Main entry points: [`rag.py`](https://github.com/sarathy-10/ai_industial_chatbot/blob/main/rag.py) (RAG Coordinator), [`build_index.py`](https://github.com/sarathy-10/ai_industial_chatbot/blob/main/build_index.py) (Embedding & Index Build), [`app.py`](https://github.com/sarathy-10/ai_industial_chatbot/blob/main/app.py) (Streamlit Chat UI), [`index.faiss`](https://github.com/sarathy-10/ai_industial_chatbot/blob/main/index.faiss) (FAISS Index)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_indexing["Knowledge Indexing"]
  node_indexer["Indexing Orchestrator<br/>[build_index.py]"]
  node_pdf_extract["PDF Extraction<br/>[build_index.py]"]
  node_chunking["Cleaning &amp; Chunking<br/>[build_index.py]"]
  node_embedding_build["Embedding &amp; Index Build<br/>[build_index.py]"]
  node_embed_model{{"Sentence Transformer"}}
end

subgraph group_qa["Question Answering"]
  node_rag["RAG Coordinator<br/>[rag.py]"]
  node_query_embed["Question Embedding<br/>[rag.py]"]
  node_retrieval["Top-K Retrieval<br/>[rag.py]"]
  node_prompt["Grounded Prompt<br/>[rag.py]"]
  node_llm{{"Qwen Language Model"}}
  node_answer_sources["Answer &amp; Sources<br/>[rag.py]"]
end

subgraph group_interface["Chat Interfaces"]
  node_streamlit["Streamlit Chat UI<br/>[app.py]"]
  node_cli["CLI Chat<br/>[rag.py]"]
end

subgraph group_artifacts["Search Artifacts"]
  node_faiss[("FAISS Index<br/>[index.faiss]")]
  node_metadata[("Chunk Metadata<br/>[metadata.json]")]
end

node_pdfs["Industrial PDFs"]
node_user(("Questioner"))

node_pdfs -->|"provides PDFs"| node_pdf_extract
node_indexer -->|"loads pages"| node_pdf_extract
node_pdf_extract -->|"passes page text"| node_chunking
node_indexer -->|"builds index"| node_embedding_build
node_embedding_build -->|"encodes chunks"| node_embed_model
node_embedding_build -->|"writes vectors"| node_faiss
node_embedding_build -->|"writes records"| node_metadata
node_user -->|"asks question"| node_streamlit
node_streamlit -->|"calls ask"| node_rag
node_user -->|"enters question"| node_cli
node_cli -->|"runs chatbot"| node_rag
node_rag -->|"retrieves question"| node_query_embed
node_query_embed -->|"encodes question"| node_embed_model
node_rag -->|"retrieves chunks"| node_retrieval
node_retrieval -->|"searches index"| node_faiss
node_retrieval -->|"reads records"| node_metadata
node_rag -->|"builds context"| node_prompt
node_prompt -->|"generates answer"| node_llm
node_rag -->|"returns answer and sources"| node_answer_sources
node_answer_sources -->|"displays answer and sources"| node_streamlit

click node_indexer "https://github.com/sarathy-10/ai_industial_chatbot/blob/main/build_index.py"
click node_pdf_extract "https://github.com/sarathy-10/ai_industial_chatbot/blob/main/build_index.py"
click node_chunking "https://github.com/sarathy-10/ai_industial_chatbot/blob/main/build_index.py"
click node_embedding_build "https://github.com/sarathy-10/ai_industial_chatbot/blob/main/build_index.py"
click node_faiss "https://github.com/sarathy-10/ai_industial_chatbot/blob/main/index.faiss"
click node_metadata "https://github.com/sarathy-10/ai_industial_chatbot/blob/main/metadata.json"
click node_streamlit "https://github.com/sarathy-10/ai_industial_chatbot/blob/main/app.py"
click node_cli "https://github.com/sarathy-10/ai_industial_chatbot/blob/main/rag.py"
click node_rag "https://github.com/sarathy-10/ai_industial_chatbot/blob/main/rag.py"
click node_query_embed "https://github.com/sarathy-10/ai_industial_chatbot/blob/main/rag.py"
click node_retrieval "https://github.com/sarathy-10/ai_industial_chatbot/blob/main/rag.py"
click node_prompt "https://github.com/sarathy-10/ai_industial_chatbot/blob/main/rag.py"
click node_answer_sources "https://github.com/sarathy-10/ai_industial_chatbot/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_indexer,node_pdf_extract,node_chunking,node_embedding_build,node_embed_model toneBlue
class node_rag,node_query_embed,node_retrieval,node_prompt,node_llm,node_answer_sources toneAmber
class node_streamlit,node_cli toneMint
class node_faiss,node_metadata toneRose
class node_pdfs,node_user toneIndigo
```

## Components

### Knowledge Indexing

- [Indexing Orchestrator](https://github.com/sarathy-10/ai_industial_chatbot/blob/main/build_index.py): `build_index.py`
- [PDF Extraction](https://github.com/sarathy-10/ai_industial_chatbot/blob/main/build_index.py): `build_index.py`
- [Cleaning & Chunking](https://github.com/sarathy-10/ai_industial_chatbot/blob/main/build_index.py): `build_index.py`
- [Embedding & Index Build](https://github.com/sarathy-10/ai_industial_chatbot/blob/main/build_index.py): `build_index.py`
- **Sentence Transformer**

### Question Answering

- [RAG Coordinator](https://github.com/sarathy-10/ai_industial_chatbot/blob/main/rag.py): `rag.py`
- [Question Embedding](https://github.com/sarathy-10/ai_industial_chatbot/blob/main/rag.py): `rag.py`
- [Top-K Retrieval](https://github.com/sarathy-10/ai_industial_chatbot/blob/main/rag.py): `rag.py`
- [Grounded Prompt](https://github.com/sarathy-10/ai_industial_chatbot/blob/main/rag.py): `rag.py`
- **Qwen Language Model**
- [Answer & Sources](https://github.com/sarathy-10/ai_industial_chatbot/blob/main/rag.py): `rag.py`

### Chat Interfaces

- [Streamlit Chat UI](https://github.com/sarathy-10/ai_industial_chatbot/blob/main/app.py): `app.py`
- [CLI Chat](https://github.com/sarathy-10/ai_industial_chatbot/blob/main/rag.py): `rag.py`

### Search Artifacts

- [FAISS Index](https://github.com/sarathy-10/ai_industial_chatbot/blob/main/index.faiss): `index.faiss`
- [Chunk Metadata](https://github.com/sarathy-10/ai_industial_chatbot/blob/main/metadata.json): `metadata.json`

### Other components

- **Industrial PDFs**
- **Questioner**

## Connections

- Industrial PDFs → PDF Extraction: provides PDFs (evidence: `README.md`)
- Indexing Orchestrator → PDF Extraction: loads pages (evidence: `build_index.py`)
- PDF Extraction → Cleaning & Chunking: passes page text (evidence: `build_index.py`)
- Indexing Orchestrator → Embedding & Index Build: builds index (evidence: `build_index.py`)
- Embedding & Index Build → Sentence Transformer: encodes chunks (evidence: `build_index.py`)
- Embedding & Index Build → FAISS Index: writes vectors (evidence: `build_index.py`)
- Embedding & Index Build → Chunk Metadata: writes records (evidence: `build_index.py`)
- Questioner → Streamlit Chat UI: asks question (evidence: `README.md`)
- Streamlit Chat UI → RAG Coordinator: calls ask (evidence: `app.py`)
- Questioner → CLI Chat: enters question (evidence: `README.md`)
- CLI Chat → RAG Coordinator: runs chatbot (evidence: `README.md`)
- RAG Coordinator → Question Embedding: retrieves question (evidence: `rag.py`)
- Question Embedding → Sentence Transformer: encodes question (evidence: `rag.py`)
- RAG Coordinator → Top-K Retrieval: retrieves chunks (evidence: `rag.py`)
- Top-K Retrieval → FAISS Index: searches index (evidence: `rag.py`)
- Top-K Retrieval → Chunk Metadata: reads records (evidence: `rag.py`)
- RAG Coordinator → Grounded Prompt: builds context (evidence: `rag.py`)
- Grounded Prompt → Qwen Language Model: generates answer (evidence: `rag.py`)
- RAG Coordinator → Answer & Sources: returns answer and sources (evidence: `rag.py`)
- Answer & Sources → Streamlit Chat UI: displays answer and sources (evidence: `README.md`)
