# abhijitwebdev/medic-guidelines-rag architecture

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

- Interactive diagram: https://gitdiagram.com/abhijitwebdev/medic-guidelines-rag
- Repository: https://github.com/abhijitwebdev/medic-guidelines-rag

## Overview

Medical Guideline Assistant answers general questions from its pinned government-guideline corpus, with citations and refusals enforced by three gates. The main user path runs through the API and assistant orchestration; corpus ingestion and indexing prepare the material it searches. Account/history storage and caching support the application. Relationships reflect the README and available source-index references; some implementation details, including several retrieval and ingestion stages, were not sampled.

Main entry points: [`src/rag_project/assistant.py`](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/assistant.py) (Assistant), [`src/rag_project/retrieval/search.py`](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/retrieval/search.py) (Hybrid Retrieval), [`src/rag_project/llm.py`](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/llm.py) (Model Client), [`src/rag_project/ingest/pipeline.py`](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/ingest/pipeline.py) (Corpus Ingestion)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application"]
  node_api["HTTP API<br/>[api.py]"]
  node_assistant["Assistant<br/>[assistant.py]"]
  node_accounts[("Accounts and History<br/>[users.py]")]
end

subgraph group_corpus["Guideline Corpus"]
  node_ingest["Corpus Ingestion<br/>[pipeline.py]"]
  node_manifest["Pinned Manifest<br/>[manifest.py]"]
  node_parse["PDF Parsing<br/>[parse.py]"]
  node_chunk["Chunking<br/>[chunk.py]"]
  node_indexbuild["Index Building<br/>[build.py]"]
  node_embed["Embedding<br/>[embed.py]"]
  node_vector[("Vector Store<br/>[store.py]")]
end

subgraph group_answer["Answer Pipeline"]
  node_rewrite["Query Rewrite<br/>[rewrite.py]"]
  node_hyde["HyDE<br/>[hyde.py]"]
  node_search["Hybrid Retrieval<br/>[search.py]"]
  node_bm25["BM25 Search<br/>[bm25.py]"]
  node_rerank["Passage Reranking<br/>[rerank.py]"]
  node_inputgate["Intent Gate<br/>[input_gate.py]"]
  node_confidence["Confidence Gate<br/>[confidence.py]"]
  node_corrective["Corrective Retrieval<br/>[corrective.py]"]
  node_generate["Answer Generation<br/>[generate.py]"]
  node_outputgate["Output Gate<br/>[output_gate.py]"]
end

subgraph group_support["Supporting Services"]
  node_llm["Model Client<br/>[llm.py]"]
  node_cache[("Cache<br/>[cache.py]")]
  node_dbengine[("Database Engine<br/>[engine.py]")]
end

node_user(("Questioner"))
node_government["Government Guidelines"]
node_modelservice{{"OpenAI Service"}}

node_user -->|"asks"| node_api
node_api -->|"invokes"| node_assistant
node_api -->|"uses accounts"| node_accounts
node_ingest -->|"verifies and loads"| node_manifest
node_ingest -->|"parses documents"| node_parse
node_ingest -->|"chunks sections"| node_chunk
node_government -.->|"documents listed"| node_manifest
node_indexbuild -.->|"builds vectors"| node_embed
node_indexbuild -.->|"writes index"| node_vector
node_assistant -->|"checks intent"| node_inputgate
node_assistant -->|"retrieves passages"| node_search
node_assistant -->|"reranks passages"| node_rerank
node_assistant -->|"judges confidence"| node_confidence
node_assistant -->|"retries retrieval"| node_corrective
node_assistant -->|"generates answer"| node_generate
node_assistant -->|"validates answer"| node_outputgate
node_rewrite -->|"rewrites query"| node_search
node_hyde -->|"blends query vector"| node_search
node_search -->|"searches lexical"| node_bm25
node_search -->|"searches dense"| node_vector
node_confidence -->|"requests retry"| node_corrective
node_generate -->|"calls model"| node_llm
node_inputgate -->|"classifies intent"| node_llm
node_outputgate -->|"judges support"| node_llm
node_llm -->|"sends prompts"| node_modelservice
node_assistant -->|"caches results"| node_cache
node_accounts -->|"persists accounts"| node_dbengine

click node_api "https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/api.py"
click node_assistant "https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/assistant.py"
click node_accounts "https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/db/users.py"
click node_ingest "https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/ingest/pipeline.py"
click node_manifest "https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/corpus/manifest.py"
click node_parse "https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/ingest/parse.py"
click node_chunk "https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/ingest/chunk.py"
click node_indexbuild "https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/indexing/build.py"
click node_embed "https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/indexing/embed.py"
click node_vector "https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/indexing/store.py"
click node_rewrite "https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/retrieval/rewrite.py"
click node_hyde "https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/retrieval/hyde.py"
click node_search "https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/retrieval/search.py"
click node_bm25 "https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/indexing/bm25.py"
click node_rerank "https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/retrieval/rerank.py"
click node_inputgate "https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/guardrails/input_gate.py"
click node_confidence "https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/guardrails/confidence.py"
click node_corrective "https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/retrieval/corrective.py"
click node_generate "https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/generation/generate.py"
click node_outputgate "https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/guardrails/output_gate.py"
click node_llm "https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/llm.py"
click node_cache "https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/cache.py"
click node_dbengine "https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/db/engine.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_api,node_assistant,node_accounts toneBlue
class node_ingest,node_manifest,node_parse,node_chunk,node_indexbuild,node_embed,node_vector toneAmber
class node_rewrite,node_hyde,node_search,node_bm25,node_rerank,node_inputgate,node_confidence,node_corrective,node_generate,node_outputgate toneMint
class node_llm,node_cache,node_dbengine toneRose
class node_user,node_government,node_modelservice toneIndigo
```

## Components

### Application

- [HTTP API](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/api.py): `src/rag_project/api.py`
- [Assistant](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/assistant.py): `src/rag_project/assistant.py`
- [Accounts and History](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/db/users.py): `src/rag_project/db/users.py`

### Guideline Corpus

- [Corpus Ingestion](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/ingest/pipeline.py): `src/rag_project/ingest/pipeline.py`
- [Pinned Manifest](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/corpus/manifest.py): `src/rag_project/corpus/manifest.py`
- [PDF Parsing](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/ingest/parse.py): `src/rag_project/ingest/parse.py`
- [Chunking](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/ingest/chunk.py): `src/rag_project/ingest/chunk.py`
- [Index Building](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/indexing/build.py): `src/rag_project/indexing/build.py`
- [Embedding](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/indexing/embed.py): `src/rag_project/indexing/embed.py`
- [Vector Store](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/indexing/store.py): `src/rag_project/indexing/store.py`

### Answer Pipeline

- [Query Rewrite](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/retrieval/rewrite.py): `src/rag_project/retrieval/rewrite.py`
- [HyDE](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/retrieval/hyde.py): `src/rag_project/retrieval/hyde.py`
- [Hybrid Retrieval](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/retrieval/search.py): `src/rag_project/retrieval/search.py`
- [BM25 Search](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/indexing/bm25.py): `src/rag_project/indexing/bm25.py`
- [Passage Reranking](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/retrieval/rerank.py): `src/rag_project/retrieval/rerank.py`
- [Intent Gate](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/guardrails/input_gate.py): `src/rag_project/guardrails/input_gate.py`
- [Confidence Gate](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/guardrails/confidence.py): `src/rag_project/guardrails/confidence.py`
- [Corrective Retrieval](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/retrieval/corrective.py): `src/rag_project/retrieval/corrective.py`
- [Answer Generation](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/generation/generate.py): `src/rag_project/generation/generate.py`
- [Output Gate](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/guardrails/output_gate.py): `src/rag_project/guardrails/output_gate.py`

### Supporting Services

- [Model Client](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/llm.py): `src/rag_project/llm.py`
- [Cache](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/cache.py): `src/rag_project/cache.py`
- [Database Engine](https://github.com/abhijitwebdev/medic-guidelines-rag/blob/main/src/rag_project/db/engine.py): `src/rag_project/db/engine.py`

### Other components

- **Questioner**
- **Government Guidelines**
- **OpenAI Service**

## Connections

- Questioner → HTTP API: asks (evidence: `src/rag_project/api.py`)
- HTTP API → Assistant: invokes (evidence: `src/rag_project/api.py`)
- HTTP API → Accounts and History: uses accounts (evidence: `src/rag_project/api.py`)
- Corpus Ingestion → Pinned Manifest: verifies and loads (evidence: `src/rag_project/ingest/pipeline.py`)
- Corpus Ingestion → PDF Parsing: parses documents (evidence: `src/rag_project/ingest/pipeline.py`)
- Corpus Ingestion → Chunking: chunks sections (evidence: `src/rag_project/ingest/pipeline.py`)
- Government Guidelines → Pinned Manifest: documents listed (evidence: `README.md`)
- Index Building → Embedding: builds vectors
- Index Building → Vector Store: writes index
- Assistant → Intent Gate: checks intent (evidence: `src/rag_project/assistant.py`)
- Assistant → Hybrid Retrieval: retrieves passages (evidence: `README.md`)
- Assistant → Passage Reranking: reranks passages (evidence: `src/rag_project/assistant.py`)
- Assistant → Confidence Gate: judges confidence (evidence: `src/rag_project/assistant.py`)
- Assistant → Corrective Retrieval: retries retrieval (evidence: `README.md`)
- Assistant → Answer Generation: generates answer (evidence: `src/rag_project/assistant.py`)
- Assistant → Output Gate: validates answer (evidence: `src/rag_project/assistant.py`)
- Query Rewrite → Hybrid Retrieval: rewrites query (evidence: `README.md`)
- HyDE → Hybrid Retrieval: blends query vector (evidence: `README.md`)
- Hybrid Retrieval → BM25 Search: searches lexical (evidence: `src/rag_project/retrieval/search.py`)
- Hybrid Retrieval → Vector Store: searches dense (evidence: `src/rag_project/retrieval/search.py`)
- Confidence Gate → Corrective Retrieval: requests retry (evidence: `README.md`)
- Answer Generation → Model Client: calls model (evidence: `src/rag_project/generation/generate.py`)
- Intent Gate → Model Client: classifies intent (evidence: `src/rag_project/guardrails/input_gate.py`)
- Output Gate → Model Client: judges support (evidence: `src/rag_project/guardrails/output_gate.py`)
- Model Client → OpenAI Service: sends prompts (evidence: `src/rag_project/llm.py`)
- Assistant → Cache: caches results (evidence: `src/rag_project/assistant.py`)
- Accounts and History → Database Engine: persists accounts (evidence: `src/rag_project/db/users.py`)
