# anmol-mittal30/medically-ai-medical-assistant architecture

> Architecture diagram of the GitHub repository anmol-mittal30/medically-ai-medical-assistant, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/anmol-mittal30/medically-ai-medical-assistant
- Repository: https://github.com/anmol-mittal30/medically-ai-medical-assistant

## Overview

Medically AI is an educational medical-document QA app. Authorized PDFs are extracted, chunked, embedded, and indexed offline; a user question is embedded and matched against that index, then retrieved context is sent to Gemini and the answer and source passages are shown in the Streamlit session. The graph preserves the documented ingestion and online paths, including page metadata and configurable retrieval. Source excerpts show ingestion and generation details; some retrieval/UI wiring is documented only in the README, so those edges cite it.

Main entry points: [`medibot.py`](https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/medibot.py) (Streamlit workspace), [`create_memory_for_llm.py`](https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/create_memory_for_llm.py) (PDF ingestion), [`config.py`](https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/config.py) (App settings)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Offline indexing"]
  node_indexer["PDF ingestion"]
  node_extract["Page extraction"]
  node_chunk["Text chunking"]
  node_embed["MiniLM embeddings"]
  node_faiss[("FAISS index")]
end

subgraph group_qa["Question answering"]
  node_ui["Streamlit workspace<br/>[medibot.py]"]
  node_query_embed["Query embedding<br/>[medibot.py]"]
  node_retrieve["Top-K retrieval<br/>[medibot.py]"]
  node_prompt["Context and prompt<br/>[medibot.py]"]
  node_answer["Answer generation<br/>[medibot.py]"]
  node_references["Source excerpts<br/>[medibot.py]"]
end

subgraph group_settings["Configuration"]
  node_config["App settings<br/>[config.py]"]
end

node_pdfs["Medical PDFs"]
node_user(("User"))
node_gemini["Gemini API"]

node_pdfs -->|"provides PDFs"| node_indexer
node_indexer -->|"loads pages"| node_extract
node_indexer -->|"splits pages"| node_chunk
node_indexer -->|"embeds chunks"| node_embed
node_indexer -->|"saves index"| node_faiss
node_user -->|"asks question"| node_ui
node_ui -->|"encodes question"| node_query_embed
node_query_embed -->|"searches vectors"| node_faiss
node_faiss -->|"returns matches"| node_retrieve
node_ui -->|"requests Top-K"| node_retrieve
node_retrieve -->|"supplies context"| node_prompt
node_ui -->|"supplies question"| node_prompt
node_prompt -->|"generates response"| node_answer
node_answer -->|"sends prompt"| node_gemini
node_gemini -->|"returns response"| node_answer
node_answer -->|"returns answer"| node_ui
node_retrieve -->|"provides passages"| node_references
node_references -->|"displays sources"| node_ui
node_indexer -->|"reads settings"| node_config
node_ui -->|"reads settings"| node_config

click node_indexer "https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/create_memory_for_llm.py"
click node_extract "https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/create_memory_for_llm.py"
click node_chunk "https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/create_memory_for_llm.py"
click node_embed "https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/create_memory_for_llm.py"
click node_faiss "https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/create_memory_for_llm.py"
click node_ui "https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/medibot.py"
click node_query_embed "https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/medibot.py"
click node_retrieve "https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/medibot.py"
click node_prompt "https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/medibot.py"
click node_answer "https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/medibot.py"
click node_references "https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/medibot.py"
click node_config "https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/config.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_indexer,node_extract,node_chunk,node_embed,node_faiss,node_user toneBlue
class node_ui,node_query_embed,node_retrieve,node_prompt,node_answer,node_references toneAmber
class node_config,node_gemini toneMint
class node_pdfs toneIndigo
```

## Components

### Offline indexing

- [PDF ingestion](https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/create_memory_for_llm.py): `create_memory_for_llm.py`
- [Page extraction](https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/create_memory_for_llm.py): `create_memory_for_llm.py`
- [Text chunking](https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/create_memory_for_llm.py): `create_memory_for_llm.py`
- [MiniLM embeddings](https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/create_memory_for_llm.py): `create_memory_for_llm.py`
- [FAISS index](https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/create_memory_for_llm.py): `create_memory_for_llm.py`

### Question answering

- [Streamlit workspace](https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/medibot.py): `medibot.py`
- [Query embedding](https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/medibot.py): `medibot.py`
- [Top-K retrieval](https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/medibot.py): `medibot.py`
- [Context and prompt](https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/medibot.py): `medibot.py`
- [Answer generation](https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/medibot.py): `medibot.py`
- [Source excerpts](https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/medibot.py): `medibot.py`

### Configuration

- [App settings](https://github.com/anmol-mittal30/medically-ai-medical-assistant/blob/main/config.py): `config.py`

### Other components

- **Medical PDFs**
- **User**
- **Gemini API**

## Connections

- Medical PDFs → PDF ingestion: provides PDFs (evidence: `README.md`)
- PDF ingestion → Page extraction: loads pages (evidence: `create_memory_for_llm.py`)
- PDF ingestion → Text chunking: splits pages (evidence: `create_memory_for_llm.py`)
- PDF ingestion → MiniLM embeddings: embeds chunks (evidence: `create_memory_for_llm.py`)
- PDF ingestion → FAISS index: saves index (evidence: `create_memory_for_llm.py`)
- User → Streamlit workspace: asks question (evidence: `README.md`)
- Streamlit workspace → Query embedding: encodes question (evidence: `README.md`)
- Query embedding → FAISS index: searches vectors (evidence: `README.md`)
- FAISS index → Top-K retrieval: returns matches (evidence: `README.md`)
- Streamlit workspace → Top-K retrieval: requests Top-K (evidence: `README.md`)
- Top-K retrieval → Context and prompt: supplies context (evidence: `README.md`)
- Streamlit workspace → Context and prompt: supplies question (evidence: `README.md`)
- Context and prompt → Answer generation: generates response (evidence: `medibot.py`)
- Answer generation → Gemini API: sends prompt (evidence: `medibot.py`)
- Gemini API → Answer generation: returns response (evidence: `README.md`)
- Answer generation → Streamlit workspace: returns answer (evidence: `README.md`)
- Top-K retrieval → Source excerpts: provides passages (evidence: `README.md`)
- Source excerpts → Streamlit workspace: displays sources (evidence: `README.md`)
- PDF ingestion → App settings: reads settings (evidence: `create_memory_for_llm.py`)
- Streamlit workspace → App settings: reads settings (evidence: `medibot.py`)
