# leosumanth3-source/swarnasky-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/leosumanth3-source/swarnasky-chatbot
- Repository: https://github.com/leosumanth3-source/swarnasky-chatbot

## Overview

This repository builds a website-grounded RAG assistant: it archives Swarnasky pages, cleans and sections their content, chunks and indexes it, then serves answers through a FastAPI chat endpoint. The main API performs embedding, Qdrant retrieval, reranking, context assembly, and Ollama generation; separate command-line scripts demonstrate retrieval and RAG flows. Pipeline links are supported by the scripts’ documented input/output formats. The README is empty, so API capabilities beyond the sampled excerpts are not inferred.

Main entry points: [`main.py`](https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/main.py) (Chat API), [`rag.py`](https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/rag.py) (CLI RAG flow), [`reranker.py`](https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/reranker.py) (Rerank utility), [`embed_to_qdrant.py`](https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/embed_to_qdrant.py) (Vector indexer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Content ingestion"]
  node_crawler["Website crawler<br/>[crawl.py]"]
  node_cleaner["Content cleaner<br/>[clean_data.py]"]
  node_chunker["Section chunker<br/>[chunks.py]"]
  node_indexer["Vector indexer<br/>[embed_to_qdrant.py]"]
end

subgraph group_serve["Answer service"]
  node_api["Chat API<br/>[main.py]"]
  node_query_embed["Query embedding<br/>[main.py]"]
  node_candidate_search["Candidate retrieval<br/>[main.py]"]
  node_rerank["Result reranking<br/>[main.py]"]
  node_answer["Context answer<br/>[main.py]"]
end

subgraph group_tools["Retrieval utilities"]
  node_cli_rag["CLI RAG flow<br/>[rag.py]"]
  node_search_demo["Search utility<br/>[search.py]"]
  node_rerank_demo["Rerank utility<br/>[reranker.py]"]
end

subgraph group_infra["Models and storage"]
  node_embed_model["Embedding model"]
  node_cross_encoder["Cross-encoder"]
  node_qdrant[("Qdrant collection")]
  node_ollama["Ollama model"]
end

node_visitor(("Website visitor"))
node_website["Swarnasky website"]

node_crawler -->|"fetches pages"| node_website
node_crawler -.->|"archives HTML"| node_cleaner
node_cleaner -->|"writes cleaned sections"| node_chunker
node_chunker -->|"writes chunk records"| node_indexer
node_indexer -->|"embeds chunks"| node_embed_model
node_indexer -->|"upserts vectors"| node_qdrant
node_visitor -.->|"asks question"| node_api
node_api -->|"handles request"| node_query_embed
node_query_embed -->|"embeds question"| node_embed_model
node_api -->|"runs retrieval"| node_candidate_search
node_candidate_search -->|"queries vectors"| node_qdrant
node_api -->|"ranks candidates"| node_rerank
node_rerank -->|"scores documents"| node_cross_encoder
node_api -->|"builds response"| node_answer
node_answer -->|"generates answer"| node_ollama
node_visitor -->|"asks question"| node_cli_rag
node_cli_rag -->|"embeds question"| node_embed_model
node_cli_rag -->|"retrieves candidates"| node_qdrant
node_cli_rag -->|"reranks candidates"| node_cross_encoder
node_cli_rag -->|"generates answer"| node_ollama
node_search_demo -->|"embeds query"| node_embed_model
node_search_demo -->|"searches vectors"| node_qdrant
node_rerank_demo -->|"embeds query"| node_embed_model
node_rerank_demo -->|"retrieves candidates"| node_qdrant
node_rerank_demo -->|"reranks candidates"| node_cross_encoder

click node_crawler "https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/crawl.py"
click node_cleaner "https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/clean_data.py"
click node_chunker "https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/chunks.py"
click node_indexer "https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/embed_to_qdrant.py"
click node_api "https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/main.py"
click node_query_embed "https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/main.py"
click node_candidate_search "https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/main.py"
click node_rerank "https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/main.py"
click node_answer "https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/main.py"
click node_cli_rag "https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/rag.py"
click node_search_demo "https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/search.py"
click node_rerank_demo "https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/reranker.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_crawler,node_cleaner,node_chunker,node_indexer toneBlue
class node_api,node_query_embed,node_candidate_search,node_rerank,node_answer toneAmber
class node_cli_rag,node_search_demo,node_rerank_demo toneMint
class node_embed_model,node_cross_encoder,node_qdrant,node_ollama toneRose
class node_visitor,node_website toneIndigo
```

## Components

### Content ingestion

- [Website crawler](https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/crawl.py): `crawl.py`
- [Content cleaner](https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/clean_data.py): `clean_data.py`
- [Section chunker](https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/chunks.py): `chunks.py`
- [Vector indexer](https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/embed_to_qdrant.py): `embed_to_qdrant.py`

### Answer service

- [Chat API](https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/main.py): `main.py`
- [Query embedding](https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/main.py): `main.py`
- [Candidate retrieval](https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/main.py): `main.py`
- [Result reranking](https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/main.py): `main.py`
- [Context answer](https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/main.py): `main.py`

### Retrieval utilities

- [CLI RAG flow](https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/rag.py): `rag.py`
- [Search utility](https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/search.py): `search.py`
- [Rerank utility](https://github.com/leosumanth3-source/swarnasky-chatbot/blob/main/reranker.py): `reranker.py`

### Models and storage

- **Embedding model**
- **Cross-encoder**
- **Qdrant collection**
- **Ollama model**

### Other components

- **Website visitor**
- **Swarnasky website**

## Connections

- Website crawler → Swarnasky website: fetches pages (evidence: `crawl.py`)
- Website crawler → Content cleaner: archives HTML
- Content cleaner → Section chunker: writes cleaned sections (evidence: `chunks.py`)
- Section chunker → Vector indexer: writes chunk records (evidence: `embed_to_qdrant.py`)
- Vector indexer → Embedding model: embeds chunks (evidence: `embed_to_qdrant.py`)
- Vector indexer → Qdrant collection: upserts vectors (evidence: `embed_to_qdrant.py`)
- Website visitor → Chat API: asks question
- Chat API → Query embedding: handles request (evidence: `main.py`)
- Query embedding → Embedding model: embeds question (evidence: `main.py`)
- Chat API → Candidate retrieval: runs retrieval (evidence: `main.py`)
- Candidate retrieval → Qdrant collection: queries vectors (evidence: `main.py`)
- Chat API → Result reranking: ranks candidates (evidence: `main.py`)
- Result reranking → Cross-encoder: scores documents (evidence: `main.py`)
- Chat API → Context answer: builds response (evidence: `main.py`)
- Context answer → Ollama model: generates answer (evidence: `main.py`)
- Website visitor → CLI RAG flow: asks question (evidence: `rag.py`)
- CLI RAG flow → Embedding model: embeds question (evidence: `rag.py`)
- CLI RAG flow → Qdrant collection: retrieves candidates (evidence: `rag.py`)
- CLI RAG flow → Cross-encoder: reranks candidates (evidence: `rag.py`)
- CLI RAG flow → Ollama model: generates answer (evidence: `rag.py`)
- Search utility → Embedding model: embeds query (evidence: `search.py`)
- Search utility → Qdrant collection: searches vectors (evidence: `search.py`)
- Rerank utility → Embedding model: embeds query (evidence: `reranker.py`)
- Rerank utility → Qdrant collection: retrieves candidates (evidence: `reranker.py`)
- Rerank utility → Cross-encoder: reranks candidates (evidence: `reranker.py`)
