# preethi-sethumadhavan/enterprise_rag_system architecture

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

- Interactive diagram: https://gitdiagram.com/preethi-sethumadhavan/enterprise_rag_system
- Repository: https://github.com/preethi-sethumadhavan/enterprise_rag_system

## Overview

This repository implements an HR policy RAG assistant with two main flows: building a searchable index from policy files and answering employee questions through a Flask API and chat UI. The README documents the UI/API and grounded-answer capabilities; source excerpts show indexing, query handling, retrieval, confidence checks, and OpenAI calls. The index builder and policy files are included as product runtime, not delivery tooling. The UI-to-API relationship is documented, but the template implementation was not sampled.

Main entry points: [`app.py`](https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/app.py) (Hybrid retrieval), [`build_index.py`](https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/build_index.py) (Text chunker), [`config.py`](https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/config.py) (Configuration), [`templates/chat.html`](https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/templates/chat.html) (Chat interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Policy indexing"]
  node_policy_corpus["Policy documents"]
  node_document_loader["PDF/TXT loader<br/>[build_index.py]"]
  node_text_chunker["Text chunker<br/>[build_index.py]"]
  node_index_embedder["Index embeddings<br/>[build_index.py]"]
  node_vector_index[("FAISS index<br/>[build_index.py]")]
  node_chunk_store[("Chunk store<br/>[build_index.py]")]
end

subgraph group_service["Answer service"]
  node_config["Configuration<br/>[config.py]"]
  node_flask_api["Flask API<br/>[app.py]"]
  node_query_rewriter["Query rewriting<br/>[app.py]"]
  node_conversation_memory[("Conversation memory<br/>[app.py]")]
  node_query_embedder["Query embeddings<br/>[app.py]"]
  node_hybrid_retriever["Hybrid retrieval<br/>[app.py]"]
  node_confidence_guard["Confidence guard<br/>[app.py]"]
  node_answer_generator["Grounded answer<br/>[app.py]"]
  node_response["Answer response<br/>[app.py]"]
end

subgraph group_integrations["External services"]
  node_openai{{"OpenAI API"}}
end

subgraph group_interface["User interface"]
  node_chat_ui["Chat interface<br/>[chat.html]"]
end

node_employee(("Employee"))

node_policy_corpus -->|"reads files"| node_document_loader
node_document_loader -->|"passes text"| node_text_chunker
node_text_chunker -->|"embeds chunks"| node_index_embedder
node_index_embedder -->|"requests embeddings"| node_openai
node_index_embedder -->|"adds vectors"| node_vector_index
node_text_chunker -->|"saves chunks"| node_chunk_store
node_config -->|"configures paths"| node_document_loader
node_config -->|"configures API"| node_flask_api
node_employee -->|"asks question"| node_chat_ui
node_chat_ui -->|"submits question"| node_flask_api
node_flask_api -->|"rewrites query"| node_query_rewriter
node_query_rewriter -->|"reads history"| node_conversation_memory
node_query_rewriter -->|"requests rewrite"| node_openai
node_query_rewriter -->|"passes query"| node_hybrid_retriever
node_hybrid_retriever -->|"embeds query"| node_query_embedder
node_query_embedder -->|"requests embeddings"| node_openai
node_hybrid_retriever -->|"searches vectors"| node_vector_index
node_hybrid_retriever -->|"matches chunks"| node_chunk_store
node_hybrid_retriever -->|"checks results"| node_confidence_guard
node_confidence_guard -->|"permits context"| node_answer_generator
node_answer_generator -->|"requests answer"| node_openai
node_answer_generator -->|"stores exchange"| node_conversation_memory
node_answer_generator -->|"returns answer"| node_response
node_response -->|"formats JSON"| node_flask_api
node_flask_api -->|"sends answer"| node_employee

click node_policy_corpus "https://github.com/preethi-sethumadhavan/enterprise_rag_system/tree/main/data"
click node_document_loader "https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/build_index.py"
click node_text_chunker "https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/build_index.py"
click node_index_embedder "https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/build_index.py"
click node_vector_index "https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/build_index.py"
click node_chunk_store "https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/build_index.py"
click node_config "https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/config.py"
click node_flask_api "https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/app.py"
click node_chat_ui "https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/templates/chat.html"
click node_query_rewriter "https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/app.py"
click node_conversation_memory "https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/app.py"
click node_query_embedder "https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/app.py"
click node_hybrid_retriever "https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/app.py"
click node_confidence_guard "https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/app.py"
click node_answer_generator "https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/app.py"
click node_response "https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/app.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_policy_corpus,node_document_loader,node_text_chunker,node_index_embedder,node_vector_index,node_chunk_store toneBlue
class node_config,node_flask_api,node_query_rewriter,node_conversation_memory,node_query_embedder,node_hybrid_retriever,node_confidence_guard,node_answer_generator,node_response toneAmber
class node_openai toneMint
class node_chat_ui toneRose
class node_employee toneIndigo
```

## Components

### Policy indexing

- [Policy documents](https://github.com/preethi-sethumadhavan/enterprise_rag_system/tree/main/data): `data`
- [PDF/TXT loader](https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/build_index.py): `build_index.py`
- [Text chunker](https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/build_index.py): `build_index.py`
- [Index embeddings](https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/build_index.py): `build_index.py`
- [FAISS index](https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/build_index.py): `build_index.py`
- [Chunk store](https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/build_index.py): `build_index.py`

### Answer service

- [Configuration](https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/config.py): `config.py`
- [Flask API](https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/app.py): `app.py`
- [Query rewriting](https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/app.py): `app.py`
- [Conversation memory](https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/app.py): `app.py`
- [Query embeddings](https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/app.py): `app.py`
- [Hybrid retrieval](https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/app.py): `app.py`
- [Confidence guard](https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/app.py): `app.py`
- [Grounded answer](https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/app.py): `app.py`
- [Answer response](https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/app.py): `app.py`

### External services

- **OpenAI API**

### User interface

- [Chat interface](https://github.com/preethi-sethumadhavan/enterprise_rag_system/blob/main/templates/chat.html): `templates/chat.html`

### Other components

- **Employee**

## Connections

- Policy documents → PDF/TXT loader: reads files (evidence: `build_index.py`)
- PDF/TXT loader → Text chunker: passes text (evidence: `build_index.py`)
- Text chunker → Index embeddings: embeds chunks (evidence: `build_index.py`)
- Index embeddings → OpenAI API: requests embeddings (evidence: `build_index.py`)
- Index embeddings → FAISS index: adds vectors (evidence: `build_index.py`)
- Text chunker → Chunk store: saves chunks (evidence: `build_index.py`)
- Configuration → PDF/TXT loader: configures paths (evidence: `build_index.py`)
- Configuration → Flask API: configures API (evidence: `app.py`)
- Employee → Chat interface: asks question (evidence: `README.md`)
- Chat interface → Flask API: submits question (evidence: `README.md`)
- Flask API → Query rewriting: rewrites query (evidence: `app.py`)
- Query rewriting → Conversation memory: reads history (evidence: `app.py`)
- Query rewriting → OpenAI API: requests rewrite (evidence: `app.py`)
- Query rewriting → Hybrid retrieval: passes query (evidence: `app.py`)
- Hybrid retrieval → Query embeddings: embeds query (evidence: `app.py`)
- Query embeddings → OpenAI API: requests embeddings (evidence: `app.py`)
- Hybrid retrieval → FAISS index: searches vectors (evidence: `app.py`)
- Hybrid retrieval → Chunk store: matches chunks (evidence: `app.py`)
- Hybrid retrieval → Confidence guard: checks results (evidence: `app.py`)
- Confidence guard → Grounded answer: permits context (evidence: `app.py`)
- Grounded answer → OpenAI API: requests answer (evidence: `app.py`)
- Grounded answer → Conversation memory: stores exchange (evidence: `app.py`)
- Grounded answer → Answer response: returns answer (evidence: `app.py`)
- Answer response → Flask API: formats JSON (evidence: `app.py`)
- Flask API → Employee: sends answer (evidence: `README.md`)
