# nivith1029/chatbot architecture

> Architecture diagram of the GitHub repository nivith1029/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/nivith1029/chatbot
- Repository: https://github.com/nivith1029/chatbot

## Overview

This repository provides a local PDF RAG assistant through the documented `rag_service.py` API, with PDF ingestion, semantic retrieval, and cited answers backed by Ollama and FAISS. The sampled `main.py` also implements a chat-with-history API and a richer RAG variant; its chat branch is shown separately. Edges reflect README statements and visible calls; unsampled implementation details are not inferred.

Main entry points: [`rag_service.py`](https://github.com/nivith1029/chatbot/blob/main/rag_service.py) (RAG endpoints), [`main.py`](https://github.com/nivith1029/chatbot/blob/main/main.py) (Chat and history endpoints)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_rag["PDF RAG"]
  node_rag_api["RAG endpoints<br/>[rag_service.py]"]
  node_pdf_process["PDF extraction and chunking<br/>[rag_service.py]"]
  node_retrieval["Search and answer assembly<br/>[rag_service.py]"]
end

subgraph group_chat["Chat API"]
  node_chat_api["Chat and history endpoints<br/>[main.py]"]
end

subgraph group_storage["Local storage"]
  node_faiss[("FAISS index<br/>[rag_service.py]")]
  node_rag_metadata[("Chunk metadata<br/>[rag_service.py]")]
  node_chat_db[("Conversation database<br/>[main.py]")]
end

subgraph group_models["Model services"]
  node_embed["Embedding requests<br/>[rag_service.py]"]
  node_chat_model_call["Chat model requests<br/>[main.py]"]
end

node_client(("API client"))
node_ollama{{"Ollama"}}

node_client -->|"uploads or queries"| node_rag_api
node_rag_api -->|"extracts and chunks"| node_pdf_process
node_rag_api -->|"requests embeddings"| node_embed
node_embed -->|"sends text"| node_ollama
node_rag_api -->|"reads and writes index"| node_faiss
node_rag_api -->|"loads and saves metadata"| node_rag_metadata
node_rag_api -->|"searches and assembles context"| node_retrieval
node_retrieval -->|"requests answer"| node_ollama
node_client -->|"starts and chats"| node_chat_api
node_chat_api -->|"reads and saves messages"| node_chat_db
node_chat_api -->|"requests reply"| node_chat_model_call
node_chat_model_call -->|"sends messages"| node_ollama

click node_rag_api "https://github.com/nivith1029/chatbot/blob/main/rag_service.py"
click node_pdf_process "https://github.com/nivith1029/chatbot/blob/main/rag_service.py"
click node_retrieval "https://github.com/nivith1029/chatbot/blob/main/rag_service.py"
click node_embed "https://github.com/nivith1029/chatbot/blob/main/rag_service.py"
click node_chat_api "https://github.com/nivith1029/chatbot/blob/main/main.py"
click node_chat_model_call "https://github.com/nivith1029/chatbot/blob/main/main.py"
click node_faiss "https://github.com/nivith1029/chatbot/blob/main/rag_service.py"
click node_rag_metadata "https://github.com/nivith1029/chatbot/blob/main/rag_service.py"
click node_chat_db "https://github.com/nivith1029/chatbot/blob/main/main.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_rag_api,node_pdf_process,node_retrieval,node_client toneBlue
class node_chat_api toneAmber
class node_faiss,node_rag_metadata,node_chat_db toneMint
class node_embed,node_chat_model_call toneRose
class node_ollama toneIndigo
```

## Components

### PDF RAG

- [RAG endpoints](https://github.com/nivith1029/chatbot/blob/main/rag_service.py): `rag_service.py`
- [PDF extraction and chunking](https://github.com/nivith1029/chatbot/blob/main/rag_service.py): `rag_service.py`
- [Search and answer assembly](https://github.com/nivith1029/chatbot/blob/main/rag_service.py): `rag_service.py`

### Chat API

- [Chat and history endpoints](https://github.com/nivith1029/chatbot/blob/main/main.py): `main.py`

### Local storage

- [FAISS index](https://github.com/nivith1029/chatbot/blob/main/rag_service.py): `rag_service.py`
- [Chunk metadata](https://github.com/nivith1029/chatbot/blob/main/rag_service.py): `rag_service.py`
- [Conversation database](https://github.com/nivith1029/chatbot/blob/main/main.py): `main.py`

### Model services

- [Embedding requests](https://github.com/nivith1029/chatbot/blob/main/rag_service.py): `rag_service.py`
- [Chat model requests](https://github.com/nivith1029/chatbot/blob/main/main.py): `main.py`

### Other components

- **API client**
- **Ollama**

## Connections

- API client → RAG endpoints: uploads or queries (evidence: `README.md`)
- RAG endpoints → PDF extraction and chunking: extracts and chunks (evidence: `rag_service.py`)
- RAG endpoints → Embedding requests: requests embeddings (evidence: `rag_service.py`)
- Embedding requests → Ollama: sends text (evidence: `rag_service.py`)
- RAG endpoints → FAISS index: reads and writes index (evidence: `rag_service.py`)
- RAG endpoints → Chunk metadata: loads and saves metadata (evidence: `rag_service.py`)
- RAG endpoints → Search and answer assembly: searches and assembles context (evidence: `rag_service.py`)
- Search and answer assembly → Ollama: requests answer (evidence: `rag_service.py`)
- API client → Chat and history endpoints: starts and chats (evidence: `main.py`)
- Chat and history endpoints → Conversation database: reads and saves messages (evidence: `main.py`)
- Chat and history endpoints → Chat model requests: requests reply (evidence: `main.py`)
- Chat model requests → Ollama: sends messages (evidence: `main.py`)
