# abdulrahman2005-prog/medical_rag architecture

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

- Interactive diagram: https://gitdiagram.com/abdulrahman2005-prog/medical_rag
- Repository: https://github.com/abdulrahman2005-prog/medical_rag

## Overview

ClinixAI is a clinical evidence-retrieval assistant over an indexed WHO guideline. Its primary workflow accepts a question in Streamlit, embeds it, retrieves top-ranked passages, applies a similarity threshold, then displays evidence or refuses unsupported questions. A separate FastAPI route also serves questions and can generate cited answers through the LLM integration. The repository includes document-preparation modules, but their end-to-end wiring is not shown in the excerpts; those links are marked unverified. The Streamlit excerpt is partial, so the README supports some workflow relationships.

Main entry points: [`api.py`](https://github.com/abdulrahman2005-prog/medical_rag/blob/main/api.py) (Question API), [`streamlit_app.py`](https://github.com/abdulrahman2005-prog/medical_rag/blob/main/streamlit_app.py) (Top-K Search), [`embedding.py`](https://github.com/abdulrahman2005-prog/medical_rag/blob/main/embedding.py) (Chunk Embeddings), [`data/faiss.index`](https://github.com/abdulrahman2005-prog/medical_rag/blob/main/data/faiss.index) (FAISS Index)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Question Interfaces"]
  node_streamlit["Clinical Interface<br/>[streamlit_app.py]"]
  node_fastapi["Question API<br/>[api.py]"]
  node_evidence_result["Evidence or Refusal<br/>[streamlit_app.py]"]
end

subgraph group_retrieval["Evidence Retrieval"]
  node_query_embedding["Query Embedding<br/>[streamlit_app.py]"]
  node_semantic_search["Top-K Search<br/>[streamlit_app.py]"]
  node_grounding["Grounding Check<br/>[streamlit_app.py]"]
  node_faiss_index[("FAISS Index<br/>[faiss.index]")]
  node_chunk_metadata[("Chunk Metadata<br/>[metadata.json]")]
end

subgraph group_knowledge["Knowledge Preparation"]
  node_page_parsing["Page Parsing<br/>[parsing.py]"]
  node_text_cleaning["Text Cleaning<br/>[cleaning.py]"]
  node_chunking["Evidence Chunking<br/>[chunking.py]"]
  node_document_embeddings["Chunk Embeddings<br/>[embedding.py]"]
end

subgraph group_answering["Answering Services"]
  node_answer_generation["Grounded Answering<br/>[llm.py]"]
end

node_clinician(("Clinician"))
node_api_client(("API Client"))
node_groq["Groq Service"]

node_clinician -->|"asks"| node_streamlit
node_streamlit -->|"embeds question"| node_query_embedding
node_query_embedding -->|"passes vector"| node_semantic_search
node_semantic_search -->|"searches index"| node_faiss_index
node_semantic_search -->|"reads passages"| node_chunk_metadata
node_semantic_search -->|"ranks evidence"| node_grounding
node_grounding -->|"decides PASS or REFUSE"| node_evidence_result
node_streamlit -->|"displays evidence"| node_evidence_result
node_api_client -.->|"submits question"| node_fastapi
node_fastapi -->|"searches index"| node_faiss_index
node_fastapi -->|"reads passages"| node_chunk_metadata
node_fastapi -->|"requests answer"| node_answer_generation
node_answer_generation -->|"calls model"| node_groq
node_page_parsing -.->|"prepares text"| node_text_cleaning
node_text_cleaning -.->|"supplies cleaned text"| node_chunking
node_chunking -.->|"supplies chunks"| node_document_embeddings
node_document_embeddings -.->|"builds vectors"| node_faiss_index
node_document_embeddings -.->|"stores chunk details"| node_chunk_metadata

click node_streamlit "https://github.com/abdulrahman2005-prog/medical_rag/blob/main/streamlit_app.py"
click node_fastapi "https://github.com/abdulrahman2005-prog/medical_rag/blob/main/api.py"
click node_query_embedding "https://github.com/abdulrahman2005-prog/medical_rag/blob/main/streamlit_app.py"
click node_semantic_search "https://github.com/abdulrahman2005-prog/medical_rag/blob/main/streamlit_app.py"
click node_grounding "https://github.com/abdulrahman2005-prog/medical_rag/blob/main/streamlit_app.py"
click node_evidence_result "https://github.com/abdulrahman2005-prog/medical_rag/blob/main/streamlit_app.py"
click node_faiss_index "https://github.com/abdulrahman2005-prog/medical_rag/blob/main/data/faiss.index"
click node_chunk_metadata "https://github.com/abdulrahman2005-prog/medical_rag/blob/main/data/metadata.json"
click node_page_parsing "https://github.com/abdulrahman2005-prog/medical_rag/blob/main/parsing.py"
click node_text_cleaning "https://github.com/abdulrahman2005-prog/medical_rag/blob/main/cleaning.py"
click node_chunking "https://github.com/abdulrahman2005-prog/medical_rag/blob/main/chunking.py"
click node_document_embeddings "https://github.com/abdulrahman2005-prog/medical_rag/blob/main/embedding.py"
click node_answer_generation "https://github.com/abdulrahman2005-prog/medical_rag/blob/main/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_streamlit,node_fastapi,node_evidence_result,node_api_client toneBlue
class node_query_embedding,node_semantic_search,node_grounding,node_faiss_index,node_chunk_metadata toneAmber
class node_page_parsing,node_text_cleaning,node_chunking,node_document_embeddings toneMint
class node_answer_generation toneRose
class node_clinician,node_groq toneIndigo
```

## Components

### Question Interfaces

- [Clinical Interface](https://github.com/abdulrahman2005-prog/medical_rag/blob/main/streamlit_app.py): `streamlit_app.py`
- [Question API](https://github.com/abdulrahman2005-prog/medical_rag/blob/main/api.py): `api.py`
- [Evidence or Refusal](https://github.com/abdulrahman2005-prog/medical_rag/blob/main/streamlit_app.py): `streamlit_app.py`

### Evidence Retrieval

- [Query Embedding](https://github.com/abdulrahman2005-prog/medical_rag/blob/main/streamlit_app.py): `streamlit_app.py`
- [Top-K Search](https://github.com/abdulrahman2005-prog/medical_rag/blob/main/streamlit_app.py): `streamlit_app.py`
- [Grounding Check](https://github.com/abdulrahman2005-prog/medical_rag/blob/main/streamlit_app.py): `streamlit_app.py`
- [FAISS Index](https://github.com/abdulrahman2005-prog/medical_rag/blob/main/data/faiss.index): `data/faiss.index`
- [Chunk Metadata](https://github.com/abdulrahman2005-prog/medical_rag/blob/main/data/metadata.json): `data/metadata.json`

### Knowledge Preparation

- [Page Parsing](https://github.com/abdulrahman2005-prog/medical_rag/blob/main/parsing.py): `parsing.py`
- [Text Cleaning](https://github.com/abdulrahman2005-prog/medical_rag/blob/main/cleaning.py): `cleaning.py`
- [Evidence Chunking](https://github.com/abdulrahman2005-prog/medical_rag/blob/main/chunking.py): `chunking.py`
- [Chunk Embeddings](https://github.com/abdulrahman2005-prog/medical_rag/blob/main/embedding.py): `embedding.py`

### Answering Services

- [Grounded Answering](https://github.com/abdulrahman2005-prog/medical_rag/blob/main/llm.py): `llm.py`

### Other components

- **Clinician**
- **API Client**
- **Groq Service**

## Connections

- Clinician → Clinical Interface: asks (evidence: `README.md`)
- Clinical Interface → Query Embedding: embeds question (evidence: `streamlit_app.py`)
- Query Embedding → Top-K Search: passes vector (evidence: `streamlit_app.py`)
- Top-K Search → FAISS Index: searches index (evidence: `streamlit_app.py`)
- Top-K Search → Chunk Metadata: reads passages (evidence: `README.md`)
- Top-K Search → Grounding Check: ranks evidence (evidence: `README.md`)
- Grounding Check → Evidence or Refusal: decides PASS or REFUSE (evidence: `README.md`)
- Clinical Interface → Evidence or Refusal: displays evidence (evidence: `README.md`)
- API Client → Question API: submits question
- Question API → FAISS Index: searches index (evidence: `api.py`)
- Question API → Chunk Metadata: reads passages (evidence: `api.py`)
- Question API → Grounded Answering: requests answer (evidence: `api.py`)
- Grounded Answering → Groq Service: calls model (evidence: `llm.py`)
- Page Parsing → Text Cleaning: prepares text
- Text Cleaning → Evidence Chunking: supplies cleaned text
- Evidence Chunking → Chunk Embeddings: supplies chunks
- Chunk Embeddings → FAISS Index: builds vectors
- Chunk Embeddings → Chunk Metadata: stores chunk details
