How moonglade-07/clinical-trial-document-q-a--rag-pipeline works
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 Streamlit app · embedder.py Hybrid retrieval · qa_chain.py RAG orchestration · pdf_processor.py PDF extraction
Components 15
User interface
- Streamlit app
app.py
Document ingestion
- PDF extraction
src/ingestion/pdf_processor.py - Hierarchical chunking
src/processing/chunker.py
Indexing and retrieval
- Embedding and storage
src/vectorstore/embedder.py - ChromaDB store
src/vectorstore/embedder.py - Parent chunk store
src/vectorstore/embedder.py - Hybrid retrieval
src/vectorstore/embedder.py - Trial-ID filtering
src/vectorstore/embedder.py - Trial-ID reranking
src/vectorstore/embedder.py - Parent mapping
src/vectorstore/embedder.py
Question answering
- RAG orchestration
src/rag/qa_chain.py - Query expansion
src/rag/query_expansion.py - Citations and confidence
src/rag/qa_chain.py
Other components
- Document analyst
- Gemini LLM
Connections 21
- Document analyst → Streamlit app: uploads and asks
README.md - Streamlit app → PDF extraction: extracts PDF
app.py - Streamlit app → Hierarchical chunking: creates chunks
app.py - PDF extraction → Hierarchical chunking: provides page text
src/processing/chunker.py - Streamlit app → Embedding and storage: stores chunks
app.py - Embedding and storage → ChromaDB store: writes embeddings
src/vectorstore/embedder.py - Embedding and storage → Parent chunk store: writes parent text
src/vectorstore/embedder.py - Streamlit app → RAG orchestration: asks question
app.py - RAG orchestration → Query expansion: expands query
src/rag/qa_chain.py - Query expansion → Gemini LLM: rewrites query
src/rag/query_expansion.py - RAG orchestration → Gemini LLM: generates answer
src/rag/qa_chain.py - RAG orchestration → Hybrid retrieval: builds retrieval
src/rag/qa_chain.py - Hybrid retrieval → ChromaDB store: searches dense vectors
src/vectorstore/embedder.py - Hybrid retrieval → Trial-ID filtering: combines retrieval
src/vectorstore/embedder.py - Hybrid retrieval → Trial-ID reranking: reranks results
src/vectorstore/embedder.py - Trial-ID filtering → ChromaDB store: reads trial metadata
src/vectorstore/embedder.py - Trial-ID reranking → Trial-ID filtering: scores candidates
src/vectorstore/embedder.py - Hybrid retrieval → Parent mapping: maps parent chunks
src/vectorstore/embedder.py - Parent mapping → Parent chunk store: reads parent text
src/vectorstore/embedder.py - RAG orchestration → Citations and confidence: parses sources
src/rag/qa_chain.py - Citations and confidence → Streamlit app: returns cited answer
app.py