# sumeetsingh501/ai-app architecture

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

- Interactive diagram: https://gitdiagram.com/sumeetsingh501/ai-app
- Repository: https://github.com/sumeetsingh501/ai-app

## Overview

The product is an internal, document-grounded Q&A assistant. Employees ask in the Streamlit chat; the app retrieves and reranks relevant passages, combines them with conversation history, and returns an LLM-generated answer with source citations. Document ingestion builds semantic and keyword indexes separately from chat-time retrieval. The graph includes the documented ingestion and hybrid-search stages; source-level connections are cited where excerpts show them, while optional provider choices are shown separately.

Main entry points: [`rag/retriever.py`](https://github.com/sumeetsingh501/ai-app/blob/main/rag/retriever.py) (Retrieval coordinator), [`app.py`](https://github.com/sumeetsingh501/ai-app/blob/main/app.py) (Chat UI), [`rag/ingest.py`](https://github.com/sumeetsingh501/ai-app/blob/main/rag/ingest.py) (Index builder), [`rag/llm.py`](https://github.com/sumeetsingh501/ai-app/blob/main/rag/llm.py) (Grounded answer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Document ingestion"]
  node_source_docs["Source documents"]
  node_loader["Document loader<br/>[ingest.py]"]
  node_chunker["Text chunker<br/>[ingest.py]"]
  node_index_builder["Index builder<br/>[ingest.py]"]
  node_vector_index[("Vector index<br/>[ingest.py]")]
  node_keyword_corpus[("BM25 corpus<br/>[ingest.py]")]
end

subgraph group_retrieval["Hybrid retrieval"]
  node_retriever["Retrieval coordinator<br/>[retriever.py]"]
  node_semantic_search["Semantic search<br/>[retriever.py]"]
  node_keyword_search["Keyword search<br/>[retriever.py]"]
  node_fusion["Rank fusion<br/>[retriever.py]"]
  node_reranker["Cross-encoder reranker<br/>[retriever.py]"]
end

subgraph group_answering["Answer generation"]
  node_memory["Conversation memory<br/>[memory.py]"]
  node_prompt_llm["Grounded answer<br/>[llm.py]"]
end

subgraph group_providers["Model providers"]
  node_embeddings["Embedding provider<br/>[embeddings.py]"]
  node_openai["OpenAI API"]
  node_anthropic["Anthropic API"]
end

node_employee(("Employee"))
node_chat["Chat UI<br/>[app.py]"]

node_employee -->|"asks question"| node_chat
node_chat -->|"requests passages"| node_retriever
node_chat -->|"reads and updates"| node_memory
node_chat -->|"sends question and context"| node_prompt_llm
node_source_docs -->|"loads documents"| node_loader
node_loader -->|"chunks text"| node_chunker
node_chunker -->|"builds indexes"| node_index_builder
node_index_builder -->|"embeds chunks"| node_embeddings
node_index_builder -->|"writes vectors"| node_vector_index
node_index_builder -->|"writes corpus"| node_keyword_corpus
node_retriever -->|"runs search"| node_semantic_search
node_retriever -->|"runs search"| node_keyword_search
node_retriever -->|"fuses rankings"| node_fusion
node_retriever -->|"reranks candidates"| node_reranker
node_semantic_search -->|"embeds query"| node_embeddings
node_semantic_search -->|"searches vectors"| node_vector_index
node_keyword_search -->|"scores corpus"| node_keyword_corpus
node_prompt_llm -.->|"calls when selected"| node_openai
node_prompt_llm -.->|"calls when selected"| node_anthropic
node_embeddings -.->|"calls when selected"| node_openai
node_employee -->|"reads cited answer"| node_chat

click node_chat "https://github.com/sumeetsingh501/ai-app/blob/main/app.py"
click node_source_docs "https://github.com/sumeetsingh501/ai-app/blob/main/data/sample_docs/employee_leave_policy.md"
click node_loader "https://github.com/sumeetsingh501/ai-app/blob/main/rag/ingest.py"
click node_chunker "https://github.com/sumeetsingh501/ai-app/blob/main/rag/ingest.py"
click node_index_builder "https://github.com/sumeetsingh501/ai-app/blob/main/rag/ingest.py"
click node_embeddings "https://github.com/sumeetsingh501/ai-app/blob/main/rag/embeddings.py"
click node_vector_index "https://github.com/sumeetsingh501/ai-app/blob/main/rag/ingest.py"
click node_keyword_corpus "https://github.com/sumeetsingh501/ai-app/blob/main/rag/ingest.py"
click node_retriever "https://github.com/sumeetsingh501/ai-app/blob/main/rag/retriever.py"
click node_semantic_search "https://github.com/sumeetsingh501/ai-app/blob/main/rag/retriever.py"
click node_keyword_search "https://github.com/sumeetsingh501/ai-app/blob/main/rag/retriever.py"
click node_fusion "https://github.com/sumeetsingh501/ai-app/blob/main/rag/retriever.py"
click node_reranker "https://github.com/sumeetsingh501/ai-app/blob/main/rag/retriever.py"
click node_memory "https://github.com/sumeetsingh501/ai-app/blob/main/rag/memory.py"
click node_prompt_llm "https://github.com/sumeetsingh501/ai-app/blob/main/rag/llm.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_source_docs,node_loader,node_chunker,node_index_builder,node_vector_index,node_keyword_corpus,node_chat toneBlue
class node_retriever,node_semantic_search,node_keyword_search,node_fusion,node_reranker toneAmber
class node_memory,node_prompt_llm toneMint
class node_embeddings,node_openai,node_anthropic toneRose
class node_employee toneIndigo
```

## Components

### Document ingestion

- [Source documents](https://github.com/sumeetsingh501/ai-app/blob/main/data/sample_docs/employee_leave_policy.md): `data/sample_docs/employee_leave_policy.md`
- [Document loader](https://github.com/sumeetsingh501/ai-app/blob/main/rag/ingest.py): `rag/ingest.py`
- [Text chunker](https://github.com/sumeetsingh501/ai-app/blob/main/rag/ingest.py): `rag/ingest.py`
- [Index builder](https://github.com/sumeetsingh501/ai-app/blob/main/rag/ingest.py): `rag/ingest.py`
- [Vector index](https://github.com/sumeetsingh501/ai-app/blob/main/rag/ingest.py): `rag/ingest.py`
- [BM25 corpus](https://github.com/sumeetsingh501/ai-app/blob/main/rag/ingest.py): `rag/ingest.py`

### Hybrid retrieval

- [Retrieval coordinator](https://github.com/sumeetsingh501/ai-app/blob/main/rag/retriever.py): `rag/retriever.py`
- [Semantic search](https://github.com/sumeetsingh501/ai-app/blob/main/rag/retriever.py): `rag/retriever.py`
- [Keyword search](https://github.com/sumeetsingh501/ai-app/blob/main/rag/retriever.py): `rag/retriever.py`
- [Rank fusion](https://github.com/sumeetsingh501/ai-app/blob/main/rag/retriever.py): `rag/retriever.py`
- [Cross-encoder reranker](https://github.com/sumeetsingh501/ai-app/blob/main/rag/retriever.py): `rag/retriever.py`

### Answer generation

- [Conversation memory](https://github.com/sumeetsingh501/ai-app/blob/main/rag/memory.py): `rag/memory.py`
- [Grounded answer](https://github.com/sumeetsingh501/ai-app/blob/main/rag/llm.py): `rag/llm.py`

### Model providers

- [Embedding provider](https://github.com/sumeetsingh501/ai-app/blob/main/rag/embeddings.py): `rag/embeddings.py`
- **OpenAI API**
- **Anthropic API**

### Other components

- **Employee**
- [Chat UI](https://github.com/sumeetsingh501/ai-app/blob/main/app.py): `app.py`

## Connections

- Employee → Chat UI: asks question (evidence: `app.py`)
- Chat UI → Retrieval coordinator: requests passages (evidence: `app.py`)
- Chat UI → Conversation memory: reads and updates (evidence: `app.py`)
- Chat UI → Grounded answer: sends question and context (evidence: `app.py`)
- Source documents → Document loader: loads documents (evidence: `rag/ingest.py`)
- Document loader → Text chunker: chunks text (evidence: `rag/ingest.py`)
- Text chunker → Index builder: builds indexes (evidence: `rag/ingest.py`)
- Index builder → Embedding provider: embeds chunks (evidence: `rag/ingest.py`)
- Index builder → Vector index: writes vectors (evidence: `rag/ingest.py`)
- Index builder → BM25 corpus: writes corpus (evidence: `rag/ingest.py`)
- Retrieval coordinator → Semantic search: runs search (evidence: `rag/retriever.py`)
- Retrieval coordinator → Keyword search: runs search (evidence: `rag/retriever.py`)
- Retrieval coordinator → Rank fusion: fuses rankings (evidence: `rag/retriever.py`)
- Retrieval coordinator → Cross-encoder reranker: reranks candidates (evidence: `rag/retriever.py`)
- Semantic search → Embedding provider: embeds query (evidence: `rag/retriever.py`)
- Semantic search → Vector index: searches vectors (evidence: `rag/retriever.py`)
- Keyword search → BM25 corpus: scores corpus (evidence: `rag/retriever.py`)
- Grounded answer → OpenAI API: calls when selected (evidence: `rag/llm.py`)
- Grounded answer → Anthropic API: calls when selected (evidence: `rag/llm.py`)
- Embedding provider → OpenAI API: calls when selected (evidence: `rag/embeddings.py`)
- Employee → Chat UI: reads cited answer (evidence: `README.md`)
