# moonglade-07/clinical-trial-document-q-a--rag-pipeline architecture

> Architecture diagram of the GitHub repository moonglade-07/clinical-trial-document-q-a--rag-pipeline, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline
- Repository: https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline

## Overview

Clinical Document Q&A is a Streamlit app for uploading medical PDFs, indexing their contents, and answering natural-language questions with page citations. Its main workflow extracts and cleans page text, creates hierarchical chunks, embeds and stores them, then expands questions, retrieves relevant context, and generates a grounded answer. Retrieval includes hybrid search, trial-ID filtering and boosting, and parent-chunk mapping. The excerpts show app orchestration and core module behavior; README statements support the product workflow, while some retrieval details are visible only within the vector-store module.

Main entry points: [`app.py`](https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/app.py) (Streamlit app), [`src/vectorstore/embedder.py`](https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/vectorstore/embedder.py) (Hybrid retrieval), [`src/rag/qa_chain.py`](https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/rag/qa_chain.py) (RAG orchestration), [`src/ingestion/pdf_processor.py`](https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/ingestion/pdf_processor.py) (PDF extraction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_app["Streamlit app<br/>[app.py]"]
end

subgraph group_ingestion["Document ingestion"]
  node_pdf["PDF extraction<br/>[pdf_processor.py]"]
  node_chunks["Hierarchical chunking<br/>[chunker.py]"]
end

subgraph group_indexing["Indexing and retrieval"]
  node_embedder["Embedding and storage<br/>[embedder.py]"]
  node_chroma[("ChromaDB store<br/>[embedder.py]")]
  node_parents[("Parent chunk store<br/>[embedder.py]")]
  node_retriever["Hybrid retrieval<br/>[embedder.py]"]
  node_trialfilter["Trial-ID filtering<br/>[embedder.py]"]
  node_reranker["Trial-ID reranking<br/>[embedder.py]"]
  node_parentmap["Parent mapping<br/>[embedder.py]"]
end

subgraph group_answering["Question answering"]
  node_qa["RAG orchestration<br/>[qa_chain.py]"]
  node_expansion["Query expansion<br/>[query_expansion.py]"]
  node_citations["Citations and confidence<br/>[qa_chain.py]"]
end

node_user(("Document analyst"))
node_gemini{{"Gemini LLM"}}

node_user -->|"uploads and asks"| node_app
node_app -->|"extracts PDF"| node_pdf
node_app -->|"creates chunks"| node_chunks
node_pdf -->|"provides page text"| node_chunks
node_app -->|"stores chunks"| node_embedder
node_embedder -->|"writes embeddings"| node_chroma
node_embedder -->|"writes parent text"| node_parents
node_app -->|"asks question"| node_qa
node_qa -->|"expands query"| node_expansion
node_expansion -->|"rewrites query"| node_gemini
node_qa -->|"generates answer"| node_gemini
node_qa -->|"builds retrieval"| node_retriever
node_retriever -->|"searches dense vectors"| node_chroma
node_retriever -->|"combines retrieval"| node_trialfilter
node_retriever -->|"reranks results"| node_reranker
node_trialfilter -->|"reads trial metadata"| node_chroma
node_reranker -->|"scores candidates"| node_trialfilter
node_retriever -->|"maps parent chunks"| node_parentmap
node_parentmap -->|"reads parent text"| node_parents
node_qa -->|"parses sources"| node_citations
node_citations -->|"returns cited answer"| node_app

click node_app "https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/app.py"
click node_pdf "https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/ingestion/pdf_processor.py"
click node_chunks "https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/processing/chunker.py"
click node_embedder "https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/vectorstore/embedder.py"
click node_chroma "https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/vectorstore/embedder.py"
click node_parents "https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/vectorstore/embedder.py"
click node_retriever "https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/vectorstore/embedder.py"
click node_trialfilter "https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/vectorstore/embedder.py"
click node_reranker "https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/vectorstore/embedder.py"
click node_parentmap "https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/vectorstore/embedder.py"
click node_qa "https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/rag/qa_chain.py"
click node_expansion "https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/rag/query_expansion.py"
click node_citations "https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/rag/qa_chain.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_app toneBlue
class node_pdf,node_chunks toneAmber
class node_embedder,node_chroma,node_parents,node_retriever,node_trialfilter,node_reranker,node_parentmap toneMint
class node_qa,node_expansion,node_citations toneRose
class node_user,node_gemini toneIndigo
```

## Components

### User interface

- [Streamlit app](https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/app.py): `app.py`

### Document ingestion

- [PDF extraction](https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/ingestion/pdf_processor.py): `src/ingestion/pdf_processor.py`
- [Hierarchical chunking](https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/processing/chunker.py): `src/processing/chunker.py`

### Indexing and retrieval

- [Embedding and storage](https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/vectorstore/embedder.py): `src/vectorstore/embedder.py`
- [ChromaDB store](https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/vectorstore/embedder.py): `src/vectorstore/embedder.py`
- [Parent chunk store](https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/vectorstore/embedder.py): `src/vectorstore/embedder.py`
- [Hybrid retrieval](https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/vectorstore/embedder.py): `src/vectorstore/embedder.py`
- [Trial-ID filtering](https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/vectorstore/embedder.py): `src/vectorstore/embedder.py`
- [Trial-ID reranking](https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/vectorstore/embedder.py): `src/vectorstore/embedder.py`
- [Parent mapping](https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/vectorstore/embedder.py): `src/vectorstore/embedder.py`

### Question answering

- [RAG orchestration](https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/rag/qa_chain.py): `src/rag/qa_chain.py`
- [Query expansion](https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/rag/query_expansion.py): `src/rag/query_expansion.py`
- [Citations and confidence](https://github.com/moonglade-07/clinical-trial-document-q-a--rag-pipeline/blob/main/src/rag/qa_chain.py): `src/rag/qa_chain.py`

### Other components

- **Document analyst**
- **Gemini LLM**

## Connections

- Document analyst → Streamlit app: uploads and asks (evidence: `README.md`)
- Streamlit app → PDF extraction: extracts PDF (evidence: `app.py`)
- Streamlit app → Hierarchical chunking: creates chunks (evidence: `app.py`)
- PDF extraction → Hierarchical chunking: provides page text (evidence: `src/processing/chunker.py`)
- Streamlit app → Embedding and storage: stores chunks (evidence: `app.py`)
- Embedding and storage → ChromaDB store: writes embeddings (evidence: `src/vectorstore/embedder.py`)
- Embedding and storage → Parent chunk store: writes parent text (evidence: `src/vectorstore/embedder.py`)
- Streamlit app → RAG orchestration: asks question (evidence: `app.py`)
- RAG orchestration → Query expansion: expands query (evidence: `src/rag/qa_chain.py`)
- Query expansion → Gemini LLM: rewrites query (evidence: `src/rag/query_expansion.py`)
- RAG orchestration → Gemini LLM: generates answer (evidence: `src/rag/qa_chain.py`)
- RAG orchestration → Hybrid retrieval: builds retrieval (evidence: `src/rag/qa_chain.py`)
- Hybrid retrieval → ChromaDB store: searches dense vectors (evidence: `src/vectorstore/embedder.py`)
- Hybrid retrieval → Trial-ID filtering: combines retrieval (evidence: `src/vectorstore/embedder.py`)
- Hybrid retrieval → Trial-ID reranking: reranks results (evidence: `src/vectorstore/embedder.py`)
- Trial-ID filtering → ChromaDB store: reads trial metadata (evidence: `src/vectorstore/embedder.py`)
- Trial-ID reranking → Trial-ID filtering: scores candidates (evidence: `src/vectorstore/embedder.py`)
- Hybrid retrieval → Parent mapping: maps parent chunks (evidence: `src/vectorstore/embedder.py`)
- Parent mapping → Parent chunk store: reads parent text (evidence: `src/vectorstore/embedder.py`)
- RAG orchestration → Citations and confidence: parses sources (evidence: `src/rag/qa_chain.py`)
- Citations and confidence → Streamlit app: returns cited answer (evidence: `app.py`)
