# naveenkumarbs/rag_chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/naveenkumarbs/rag_chatbot
- Repository: https://github.com/naveenkumarbs/rag_chatbot

## Overview

RAG Chatbot lets users upload PDF/text documents, index their contents, ask grounded questions, inspect cited chunks, and continue persisted conversations. The principal flow is upload → extract/chunk/embed → vector indexing; chat → history-aware query rewriting → retrieval/reranking → grounded prompt → local generation → persistence of messages and sources. Separate branches expose search, document management, health, and Prometheus metrics. The graph follows the sampled orchestration and SOURCE INDEX references; unsampled API and storage behavior is included only where the README or index documents it.

Main entry points: [`app/main.py`](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/main.py) (FastAPI application), [`app/rag/generation/rag_service.py`](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/rag/generation/rag_service.py) (RAG service), [`app/rag/retrieval/retrieval_service.py`](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/rag/retrieval/retrieval_service.py) (Retrieval service), [`app/api/chat.py`](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/api/chat.py) (Chat API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and experience"]
  node_application["FastAPI application<br/>[main.py]"]
  node_document_api["Document API<br/>[documents.py]"]
  node_chat_api["Chat API<br/>[chat.py]"]
  node_search_api["Search API<br/>[search.py]"]
  node_conversation_api["Conversation API<br/>[conversations.py]"]
end

subgraph group_ingest["Document ingestion"]
  node_ingestion["Ingestion service"]
  node_document_loader["Document loader<br/>[document_loader.py]"]
  node_chunker["Text chunker<br/>[text_chunker.py]"]
end

subgraph group_retrieve["Evidence retrieval"]
  node_embedding["Ollama embeddings<br/>[ollama_provider.py]"]
  node_vector_store[("Chroma vector store<br/>[chroma_store.py]")]
  node_retrieval["Retrieval service"]
  node_reranker["Cross-encoder reranker"]
  node_retrieval_cache["Retrieval cache<br/>[retrieval_cache.py]"]
end

subgraph group_generate["Answer generation"]
  node_rag_service["RAG service<br/>[rag_service.py]"]
  node_query_rewriter["Query rewriter<br/>[query_writer.py]"]
  node_context_builder["Context builder<br/>[context_builder.py]"]
  node_prompt_builder["Prompt builder<br/>[prompt_builder.py]"]
  node_llm["Ollama chat model<br/>[ollama_provider.py]"]
end

subgraph group_state["Persistence and operations"]
  node_redis[("Redis")]
  node_document_repository["Document repository"]
  node_conversation_repository["Conversation repository"]
  node_message_repository["Message repository"]
  node_source_repository["Message source repository"]
  node_sqlite[("SQLite database<br/>[database.py]")]
  node_health["Health checks<br/>[health_service.py]"]
  node_metrics["Prometheus metrics<br/>[metrics.py]"]
end

node_user(("User"))

node_user -->|"uses"| node_application
node_application -->|"routes"| node_document_api
node_application -->|"routes"| node_chat_api
node_application -->|"routes"| node_search_api
node_application -->|"routes"| node_conversation_api
node_document_api -->|"ingests files"| node_ingestion
node_document_api -->|"records documents"| node_document_repository
node_ingestion -->|"extracts text"| node_document_loader
node_ingestion -->|"chunks text"| node_chunker
node_ingestion -->|"embeds chunks"| node_embedding
node_ingestion -->|"indexes chunks"| node_vector_store
node_search_api -->|"searches"| node_retrieval
node_chat_api -->|"asks questions"| node_rag_service
node_rag_service -->|"rewrites query"| node_query_rewriter
node_rag_service -->|"retrieves evidence"| node_retrieval
node_retrieval -->|"checks cache"| node_retrieval_cache
node_retrieval_cache -->|"reads/writes"| node_redis
node_retrieval -->|"embeds query"| node_embedding
node_retrieval -->|"searches vectors"| node_vector_store
node_retrieval -->|"reranks results"| node_reranker
node_rag_service -->|"builds context"| node_context_builder
node_rag_service -->|"builds prompt"| node_prompt_builder
node_rag_service -->|"generates answer"| node_llm
node_chat_api -->|"loads conversations"| node_conversation_repository
node_chat_api -->|"stores messages"| node_message_repository
node_chat_api -->|"stores sources"| node_source_repository
node_conversation_api -->|"reads conversations"| node_conversation_repository
node_conversation_api -->|"reads messages"| node_message_repository
node_conversation_api -->|"reads sources"| node_source_repository
node_conversation_repository -->|"reads/writes"| node_sqlite
node_message_repository -->|"reads/writes"| node_sqlite
node_source_repository -->|"reads/writes"| node_sqlite
node_document_repository -->|"reads/writes"| node_sqlite
node_application -->|"checks services"| node_health
node_application -->|"exposes metrics"| node_metrics

click node_application "https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/main.py"
click node_document_api "https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/api/documents.py"
click node_chat_api "https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/api/chat.py"
click node_search_api "https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/api/search.py"
click node_conversation_api "https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/api/conversations.py"
click node_ingestion "https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/rag/ingestion/ingestion_service.py"
click node_document_loader "https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/rag/ingestion/document_loader.py"
click node_chunker "https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/rag/chunking/text_chunker.py"
click node_embedding "https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/rag/embeddings/ollama_provider.py"
click node_vector_store "https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/rag/retrieval/chroma_store.py"
click node_retrieval "https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/rag/retrieval/retrieval_service.py"
click node_reranker "https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/rag/reranking/cross_encoder_reranker.py"
click node_retrieval_cache "https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/core/retrieval_cache.py"
click node_rag_service "https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/rag/generation/rag_service.py"
click node_query_rewriter "https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/rag/query/query_writer.py"
click node_context_builder "https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/rag/generation/context_builder.py"
click node_prompt_builder "https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/rag/generation/prompt_builder.py"
click node_llm "https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/rag/providers/ollama_provider.py"
click node_document_repository "https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/repositories/document_repository.py"
click node_conversation_repository "https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/repositories/conversation_repository.py"
click node_message_repository "https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/repositories/message_repository.py"
click node_source_repository "https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/repositories/message_source_repository.py"
click node_sqlite "https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/repositories/database.py"
click node_health "https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/services/health_service.py"
click node_metrics "https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/core/metrics.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_application,node_document_api,node_chat_api,node_search_api,node_conversation_api,node_user toneBlue
class node_ingestion,node_document_loader,node_chunker toneAmber
class node_embedding,node_vector_store,node_retrieval,node_reranker,node_retrieval_cache toneMint
class node_rag_service,node_query_rewriter,node_context_builder,node_prompt_builder,node_llm toneRose
class node_redis,node_document_repository,node_conversation_repository,node_message_repository,node_source_repository,node_sqlite,node_health,node_metrics toneIndigo
```

## Components

### API and experience

- [FastAPI application](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/main.py): `app/main.py`
- [Document API](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/api/documents.py): `app/api/documents.py`
- [Chat API](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/api/chat.py): `app/api/chat.py`
- [Search API](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/api/search.py): `app/api/search.py`
- [Conversation API](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/api/conversations.py): `app/api/conversations.py`

### Document ingestion

- [Ingestion service](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/rag/ingestion/ingestion_service.py): `app/rag/ingestion/ingestion_service.py`
- [Document loader](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/rag/ingestion/document_loader.py): `app/rag/ingestion/document_loader.py`
- [Text chunker](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/rag/chunking/text_chunker.py): `app/rag/chunking/text_chunker.py`

### Evidence retrieval

- [Ollama embeddings](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/rag/embeddings/ollama_provider.py): `app/rag/embeddings/ollama_provider.py`
- [Chroma vector store](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/rag/retrieval/chroma_store.py): `app/rag/retrieval/chroma_store.py`
- [Retrieval service](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/rag/retrieval/retrieval_service.py): `app/rag/retrieval/retrieval_service.py`
- [Cross-encoder reranker](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/rag/reranking/cross_encoder_reranker.py): `app/rag/reranking/cross_encoder_reranker.py`
- [Retrieval cache](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/core/retrieval_cache.py): `app/core/retrieval_cache.py`

### Answer generation

- [RAG service](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/rag/generation/rag_service.py): `app/rag/generation/rag_service.py`
- [Query rewriter](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/rag/query/query_writer.py): `app/rag/query/query_writer.py`
- [Context builder](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/rag/generation/context_builder.py): `app/rag/generation/context_builder.py`
- [Prompt builder](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/rag/generation/prompt_builder.py): `app/rag/generation/prompt_builder.py`
- [Ollama chat model](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/rag/providers/ollama_provider.py): `app/rag/providers/ollama_provider.py`

### Persistence and operations

- **Redis**
- [Document repository](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/repositories/document_repository.py): `app/repositories/document_repository.py`
- [Conversation repository](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/repositories/conversation_repository.py): `app/repositories/conversation_repository.py`
- [Message repository](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/repositories/message_repository.py): `app/repositories/message_repository.py`
- [Message source repository](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/repositories/message_source_repository.py): `app/repositories/message_source_repository.py`
- [SQLite database](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/repositories/database.py): `app/repositories/database.py`
- [Health checks](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/services/health_service.py): `app/services/health_service.py`
- [Prometheus metrics](https://github.com/naveenkumarbs/rag_chatbot/blob/main/app/core/metrics.py): `app/core/metrics.py`

### Other components

- **User**

## Connections

- User → FastAPI application: uses
- FastAPI application → Document API: routes (evidence: `app/main.py`)
- FastAPI application → Chat API: routes (evidence: `app/main.py`)
- FastAPI application → Search API: routes (evidence: `app/main.py`)
- FastAPI application → Conversation API: routes (evidence: `app/main.py`)
- Document API → Ingestion service: ingests files (evidence: `app/api/documents.py`)
- Document API → Document repository: records documents (evidence: `app/api/documents.py`)
- Ingestion service → Document loader: extracts text (evidence: `app/rag/ingestion/ingestion_service.py`)
- Ingestion service → Text chunker: chunks text (evidence: `app/rag/ingestion/ingestion_service.py`)
- Ingestion service → Ollama embeddings: embeds chunks (evidence: `app/rag/ingestion/ingestion_service.py`)
- Ingestion service → Chroma vector store: indexes chunks (evidence: `app/rag/ingestion/ingestion_service.py`)
- Search API → Retrieval service: searches (evidence: `app/api/search.py`)
- Chat API → RAG service: asks questions (evidence: `app/api/chat.py`)
- RAG service → Query rewriter: rewrites query (evidence: `app/rag/generation/rag_service.py`)
- RAG service → Retrieval service: retrieves evidence (evidence: `app/rag/generation/rag_service.py`)
- Retrieval service → Retrieval cache: checks cache (evidence: `app/rag/retrieval/retrieval_service.py`)
- Retrieval cache → Redis: reads/writes (evidence: `app/core/retrieval_cache.py`)
- Retrieval service → Ollama embeddings: embeds query (evidence: `app/rag/retrieval/retrieval_service.py`)
- Retrieval service → Chroma vector store: searches vectors (evidence: `app/rag/retrieval/retrieval_service.py`)
- Retrieval service → Cross-encoder reranker: reranks results (evidence: `app/rag/retrieval/retrieval_service.py`)
- RAG service → Context builder: builds context (evidence: `app/rag/generation/rag_service.py`)
- RAG service → Prompt builder: builds prompt (evidence: `app/rag/generation/rag_service.py`)
- RAG service → Ollama chat model: generates answer (evidence: `app/rag/generation/rag_service.py`)
- Chat API → Conversation repository: loads conversations (evidence: `app/api/chat.py`)
- Chat API → Message repository: stores messages (evidence: `app/api/chat.py`)
- Chat API → Message source repository: stores sources (evidence: `app/api/chat.py`)
- Conversation API → Conversation repository: reads conversations (evidence: `app/api/conversations.py`)
- Conversation API → Message repository: reads messages (evidence: `app/api/conversations.py`)
- Conversation API → Message source repository: reads sources (evidence: `app/api/conversations.py`)
- Conversation repository → SQLite database: reads/writes (evidence: `app/repositories/conversation_repository.py`)
- Message repository → SQLite database: reads/writes (evidence: `app/repositories/message_repository.py`)
- Message source repository → SQLite database: reads/writes (evidence: `app/repositories/message_source_repository.py`)
- Document repository → SQLite database: reads/writes (evidence: `app/repositories/document_repository.py`)
- FastAPI application → Health checks: checks services (evidence: `app/main.py`)
- FastAPI application → Prometheus metrics: exposes metrics (evidence: `app/main.py`)
