# sudheera96/kidneycare-rag architecture

> Architecture diagram of the GitHub repository sudheera96/kidneycare-rag, 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/sudheera96/kidneycare-rag
- Repository: https://github.com/sudheera96/kidneycare-rag

## Overview

KidneyCare RAG turns a user's CKD question into a relevance-checked answer with retrieved source citations. At startup, the Gradio app initializes the RAG pipeline, which loads local documents, chunks them, and builds an in-memory semantic index. For questions, the pipeline classifies and expands the query, retrieves passages, checks whether the evidence is sufficient, generates and validates an answer, and formats sources for display. The README documents these capabilities; unsampled pipeline sections and evaluation wiring are represented only where the supplied source index or README supports them.

Main entry points: [`src/rag_pipeline.py`](https://github.com/sudheera96/kidneycare-rag/blob/main/src/rag_pipeline.py) (RAG Pipeline), [`src/app.py`](https://github.com/sudheera96/kidneycare-rag/blob/main/src/app.py) (App Initialization), [`src/vector_store.py`](https://github.com/sudheera96/kidneycare-rag/blob/main/src/vector_store.py) (Passage Retrieval), [`src/document_loader.py`](https://github.com/sudheera96/kidneycare-rag/blob/main/src/document_loader.py) (Document Loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User Interface"]
  node_gradio["Gradio Interface<br/>[app.py]"]
  node_app_handler["App Initialization<br/>[app.py]"]
end

subgraph group_knowledge["Knowledge Preparation"]
  node_source_docs["Local CKD Documents"]
  node_loader["Document Loader<br/>[document_loader.py]"]
  node_chunker["Text Chunker<br/>[chunker.py]"]
  node_vector_store[("Semantic Index<br/>[vector_store.py]")]
end

subgraph group_answering["Grounded Answering"]
  node_rag["RAG Pipeline<br/>[rag_pipeline.py]"]
  node_topic["Topic Classification<br/>[rag_pipeline.py]"]
  node_query_expansion["Query Expansion<br/>[rag_pipeline.py]"]
  node_retrieval["Passage Retrieval<br/>[vector_store.py]"]
  node_grounding["Relevance Gate<br/>[rag_pipeline.py]"]
  node_generation["Answer Generation<br/>[rag_pipeline.py]"]
  node_source_format["Answer And Sources<br/>[rag_pipeline.py]"]
end

subgraph group_evaluation["Evaluation"]
  node_evaluation_runner["Question Evaluation<br/>[evaluate.py]"]
end

node_user(("Questioner"))

node_user -->|"asks"| node_gradio
node_gradio -->|"submits"| node_app_handler
node_app_handler -->|"initializes"| node_rag
node_app_handler -->|"forwards question"| node_rag
node_rag -->|"classifies"| node_topic
node_rag -->|"expands"| node_query_expansion
node_source_docs -->|"provides files"| node_loader
node_rag -->|"loads documents"| node_loader
node_rag -->|"chunks documents"| node_chunker
node_rag -->|"builds index"| node_vector_store
node_rag -->|"searches"| node_retrieval
node_retrieval -->|"searches index"| node_vector_store
node_rag -->|"checks relevance"| node_grounding
node_rag -->|"generates answer"| node_generation
node_rag -->|"formats response"| node_source_format
node_source_format -->|"returns answer and sources"| node_gradio
node_evaluation_runner -->|"evaluates questions"| node_rag

click node_gradio "https://github.com/sudheera96/kidneycare-rag/blob/main/src/app.py"
click node_app_handler "https://github.com/sudheera96/kidneycare-rag/blob/main/src/app.py"
click node_rag "https://github.com/sudheera96/kidneycare-rag/blob/main/src/rag_pipeline.py"
click node_topic "https://github.com/sudheera96/kidneycare-rag/blob/main/src/rag_pipeline.py"
click node_query_expansion "https://github.com/sudheera96/kidneycare-rag/blob/main/src/rag_pipeline.py"
click node_source_docs "https://github.com/sudheera96/kidneycare-rag/tree/main/data"
click node_loader "https://github.com/sudheera96/kidneycare-rag/blob/main/src/document_loader.py"
click node_chunker "https://github.com/sudheera96/kidneycare-rag/blob/main/src/chunker.py"
click node_vector_store "https://github.com/sudheera96/kidneycare-rag/blob/main/src/vector_store.py"
click node_retrieval "https://github.com/sudheera96/kidneycare-rag/blob/main/src/vector_store.py"
click node_grounding "https://github.com/sudheera96/kidneycare-rag/blob/main/src/rag_pipeline.py"
click node_generation "https://github.com/sudheera96/kidneycare-rag/blob/main/src/rag_pipeline.py"
click node_source_format "https://github.com/sudheera96/kidneycare-rag/blob/main/src/rag_pipeline.py"
click node_evaluation_runner "https://github.com/sudheera96/kidneycare-rag/blob/main/evaluation/evaluate.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_gradio,node_app_handler toneBlue
class node_source_docs,node_loader,node_chunker,node_vector_store toneAmber
class node_rag,node_topic,node_query_expansion,node_retrieval,node_grounding,node_generation,node_source_format toneMint
class node_evaluation_runner toneRose
class node_user toneIndigo
```

## Components

### User Interface

- [Gradio Interface](https://github.com/sudheera96/kidneycare-rag/blob/main/src/app.py): `src/app.py`
- [App Initialization](https://github.com/sudheera96/kidneycare-rag/blob/main/src/app.py): `src/app.py`

### Knowledge Preparation

- [Local CKD Documents](https://github.com/sudheera96/kidneycare-rag/tree/main/data): `data`
- [Document Loader](https://github.com/sudheera96/kidneycare-rag/blob/main/src/document_loader.py): `src/document_loader.py`
- [Text Chunker](https://github.com/sudheera96/kidneycare-rag/blob/main/src/chunker.py): `src/chunker.py`
- [Semantic Index](https://github.com/sudheera96/kidneycare-rag/blob/main/src/vector_store.py): `src/vector_store.py`

### Grounded Answering

- [RAG Pipeline](https://github.com/sudheera96/kidneycare-rag/blob/main/src/rag_pipeline.py): `src/rag_pipeline.py`
- [Topic Classification](https://github.com/sudheera96/kidneycare-rag/blob/main/src/rag_pipeline.py): `src/rag_pipeline.py`
- [Query Expansion](https://github.com/sudheera96/kidneycare-rag/blob/main/src/rag_pipeline.py): `src/rag_pipeline.py`
- [Passage Retrieval](https://github.com/sudheera96/kidneycare-rag/blob/main/src/vector_store.py): `src/vector_store.py`
- [Relevance Gate](https://github.com/sudheera96/kidneycare-rag/blob/main/src/rag_pipeline.py): `src/rag_pipeline.py`
- [Answer Generation](https://github.com/sudheera96/kidneycare-rag/blob/main/src/rag_pipeline.py): `src/rag_pipeline.py`
- [Answer And Sources](https://github.com/sudheera96/kidneycare-rag/blob/main/src/rag_pipeline.py): `src/rag_pipeline.py`

### Evaluation

- [Question Evaluation](https://github.com/sudheera96/kidneycare-rag/blob/main/evaluation/evaluate.py): `evaluation/evaluate.py`

### Other components

- **Questioner**

## Connections

- Questioner → Gradio Interface: asks (evidence: `README.md`)
- Gradio Interface → App Initialization: submits (evidence: `src/app.py`)
- App Initialization → RAG Pipeline: initializes (evidence: `src/app.py`)
- App Initialization → RAG Pipeline: forwards question (evidence: `src/app.py`)
- RAG Pipeline → Topic Classification: classifies (evidence: `src/rag_pipeline.py`)
- RAG Pipeline → Query Expansion: expands (evidence: `src/rag_pipeline.py`)
- Local CKD Documents → Document Loader: provides files (evidence: `README.md`)
- RAG Pipeline → Document Loader: loads documents (evidence: `src/rag_pipeline.py`)
- RAG Pipeline → Text Chunker: chunks documents (evidence: `src/rag_pipeline.py`)
- RAG Pipeline → Semantic Index: builds index (evidence: `src/rag_pipeline.py`)
- RAG Pipeline → Passage Retrieval: searches (evidence: `src/rag_pipeline.py`)
- Passage Retrieval → Semantic Index: searches index (evidence: `src/vector_store.py`)
- RAG Pipeline → Relevance Gate: checks relevance (evidence: `src/rag_pipeline.py`)
- RAG Pipeline → Answer Generation: generates answer (evidence: `src/rag_pipeline.py`)
- RAG Pipeline → Answer And Sources: formats response (evidence: `src/rag_pipeline.py`)
- Answer And Sources → Gradio Interface: returns answer and sources (evidence: `src/app.py`)
- Question Evaluation → RAG Pipeline: evaluates questions (evidence: `evaluation/evaluate.py`)
