# wenchuan-zhang/patho-agenticrag architecture

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

- Interactive diagram: https://gitdiagram.com/wenchuan-zhang/patho-agenticrag
- Repository: https://github.com/wenchuan-zhang/patho-agenticrag

## Overview

Patho-AgenticRAG combines pathology-page ingestion and multimodal retrieval with an agentic VLM workflow; a separate genetic-programming subsystem evolves similarity-fusion functions against retrieval evaluations. The README documents model serving and agent capabilities, while source excerpts show the search API, Milvus-backed search, reranking, and evolution internals. Demo orchestration and ingestion details are not sampled, so those links reflect README-documented workflow only.

Main entry points: [`demo/patho_agenticrag.py`](https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/demo/patho_agenticrag.py) (Agent workflow), [`multimodal_fusion/gp_evolution.py`](https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/multimodal_fusion/gp_evolution.py) (GP evolution), [`search_engine/milvus_search_engine.py`](https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/search_engine/milvus_search_engine.py) (Hybrid search), [`multimodal_fusion/code_evaluation.py`](https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/multimodal_fusion/code_evaluation.py) (Similarity evaluation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_agent["Agentic diagnosis"]
  node_agent_demo["Agent workflow"]
  node_vrag["VRAG agent<br/>[vrag_agent.py]"]
  node_wrapper["Model wrapper<br/>[wrapper.py]"]
  node_router["Agentic Router"]
  node_patho_model["Patho-R1"]
  node_vrag_model["VRAG VLM"]
end

subgraph group_retrieval["Multimodal retrieval"]
  node_textbook_pdfs["Pathology PDFs"]
  node_ingestion["Page ingestion"]
  node_milvus[("Milvus vectors<br/>[milvus.py]")]
  node_search_api["Search API"]
  node_search_engine["Hybrid search"]
  node_reranker["Offline reranking<br/>[offline_rerank.py]"]
end

subgraph group_evolution["Fusion evolution"]
  node_gp["GP evolution<br/>[gp_evolution.py]"]
  node_primitives["Fusion primitives<br/>[basic_functions.py]"]
  node_archives["Evolution archive<br/>[archive.py]"]
  node_surrogate["Surrogate model<br/>[surrogate_model.py]"]
end

subgraph group_eval["Evaluation and logging"]
  node_fitness_eval["Similarity evaluation<br/>[code_evaluation.py]"]
  node_ranking_metric["NDCG metric<br/>[ndcg.py]"]
  node_run_logs["Run logging<br/>[log_plot_tool.py]"]
end

node_clinician(("Questioner"))

node_clinician -->|"asks"| node_agent_demo
node_agent_demo -->|"routes tasks"| node_router
node_agent_demo -->|"invokes"| node_vrag
node_agent_demo -->|"requests evidence"| node_search_api
node_vrag -.->|"uses"| node_wrapper
node_wrapper -->|"queries"| node_vrag_model
node_agent_demo -->|"queries"| node_patho_model
node_textbook_pdfs -->|"supplies pages"| node_ingestion
node_ingestion -->|"indexes pages"| node_milvus
node_search_api -->|"dispatches search"| node_search_engine
node_search_engine -->|"queries vectors"| node_milvus
node_search_engine -->|"reranks candidates"| node_reranker
node_gp -->|"builds expressions"| node_primitives
node_gp -->|"evaluates candidates"| node_fitness_eval
node_gp -->|"updates archive"| node_archives
node_archives -->|"predicts fitness"| node_surrogate
node_fitness_eval -->|"reranks cached results"| node_reranker
node_fitness_eval -->|"computes ranking"| node_ranking_metric
node_gp -->|"logs generations"| node_run_logs

click node_agent_demo "https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/demo/patho_agenticrag.py"
click node_vrag "https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/demo/vrag_agent.py"
click node_wrapper "https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/demo/wrapper.py"
click node_textbook_pdfs "https://github.com/wenchuan-zhang/patho-agenticrag/tree/main/pdf_datasets"
click node_ingestion "https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/search_engine/milvus_ingestion.py"
click node_milvus "https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/search_engine/milvus.py"
click node_search_api "https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/search_engine/milvus_search_engine_api.py"
click node_search_engine "https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/search_engine/milvus_search_engine.py"
click node_reranker "https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/search_engine/offline_rerank.py"
click node_gp "https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/multimodal_fusion/gp_evolution.py"
click node_primitives "https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/multimodal_fusion/basic_functions.py"
click node_archives "https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/multimodal_fusion/archive.py"
click node_surrogate "https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/multimodal_fusion/surrogate_model.py"
click node_fitness_eval "https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/multimodal_fusion/code_evaluation.py"
click node_ranking_metric "https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/multimodal_fusion/ndcg.py"
click node_run_logs "https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/multimodal_fusion/analysis/log_plot_tool.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_agent_demo,node_vrag,node_wrapper,node_router,node_patho_model,node_vrag_model toneBlue
class node_textbook_pdfs,node_ingestion,node_milvus,node_search_api,node_search_engine,node_reranker toneAmber
class node_gp,node_primitives,node_archives,node_surrogate toneMint
class node_fitness_eval,node_ranking_metric,node_run_logs toneRose
class node_clinician toneIndigo
```

## Components

### Agentic diagnosis

- [Agent workflow](https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/demo/patho_agenticrag.py): `demo/patho_agenticrag.py`
- [VRAG agent](https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/demo/vrag_agent.py): `demo/vrag_agent.py`
- [Model wrapper](https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/demo/wrapper.py): `demo/wrapper.py`
- **Agentic Router**
- **Patho-R1**
- **VRAG VLM**

### Multimodal retrieval

- [Pathology PDFs](https://github.com/wenchuan-zhang/patho-agenticrag/tree/main/pdf_datasets): `pdf_datasets`
- [Page ingestion](https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/search_engine/milvus_ingestion.py): `search_engine/milvus_ingestion.py`
- [Milvus vectors](https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/search_engine/milvus.py): `search_engine/milvus.py`
- [Search API](https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/search_engine/milvus_search_engine_api.py): `search_engine/milvus_search_engine_api.py`
- [Hybrid search](https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/search_engine/milvus_search_engine.py): `search_engine/milvus_search_engine.py`
- [Offline reranking](https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/search_engine/offline_rerank.py): `search_engine/offline_rerank.py`

### Fusion evolution

- [GP evolution](https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/multimodal_fusion/gp_evolution.py): `multimodal_fusion/gp_evolution.py`
- [Fusion primitives](https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/multimodal_fusion/basic_functions.py): `multimodal_fusion/basic_functions.py`
- [Evolution archive](https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/multimodal_fusion/archive.py): `multimodal_fusion/archive.py`
- [Surrogate model](https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/multimodal_fusion/surrogate_model.py): `multimodal_fusion/surrogate_model.py`

### Evaluation and logging

- [Similarity evaluation](https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/multimodal_fusion/code_evaluation.py): `multimodal_fusion/code_evaluation.py`
- [NDCG metric](https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/multimodal_fusion/ndcg.py): `multimodal_fusion/ndcg.py`
- [Run logging](https://github.com/wenchuan-zhang/patho-agenticrag/blob/main/multimodal_fusion/analysis/log_plot_tool.py): `multimodal_fusion/analysis/log_plot_tool.py`

### Other components

- **Questioner**

## Connections

- Questioner → Agent workflow: asks (evidence: `README.md`)
- Agent workflow → Agentic Router: routes tasks (evidence: `README.md`)
- Agent workflow → VRAG agent: invokes (evidence: `README.md`)
- Agent workflow → Search API: requests evidence (evidence: `README.md`)
- VRAG agent → Model wrapper: uses
- Model wrapper → VRAG VLM: queries (evidence: `README.md`)
- Agent workflow → Patho-R1: queries (evidence: `README.md`)
- Pathology PDFs → Page ingestion: supplies pages (evidence: `README.md`)
- Page ingestion → Milvus vectors: indexes pages (evidence: `README.md`)
- Search API → Hybrid search: dispatches search (evidence: `search_engine/milvus_search_engine_api.py`)
- Hybrid search → Milvus vectors: queries vectors (evidence: `search_engine/milvus_search_engine.py`)
- Hybrid search → Offline reranking: reranks candidates (evidence: `search_engine/milvus_search_engine.py`)
- GP evolution → Fusion primitives: builds expressions (evidence: `multimodal_fusion/gp_evolution.py`)
- GP evolution → Similarity evaluation: evaluates candidates (evidence: `multimodal_fusion/gp_evolution.py`)
- GP evolution → Evolution archive: updates archive (evidence: `multimodal_fusion/gp_evolution.py`)
- Evolution archive → Surrogate model: predicts fitness (evidence: `multimodal_fusion/archive.py`)
- Similarity evaluation → Offline reranking: reranks cached results (evidence: `multimodal_fusion/code_evaluation.py`)
- Similarity evaluation → NDCG metric: computes ranking (evidence: `multimodal_fusion/code_evaluation.py`)
- GP evolution → Run logging: logs generations (evidence: `multimodal_fusion/gp_evolution.py`)
