| title | QAMED CHATBOT |
|---|---|
| emoji | 🏥 |
| colorFrom | blue |
| colorTo | indigo |
| sdk | streamlit |
| app_file | app.py |
| pinned | false |
| license | mit |
An advanced Retrieval-Augmented Generation system specifically designed for medical question answering using hybrid vector databases, cross-encoder reranking, and medical-specialized language models.
QAMed is a comprehensive Medical RAG system that processes dense medical textbooks and provides accurate, contextual answers to complex medical questions. It uses a decoupled Parent-Child Retrieval Strategy, ensuring that while the search happens on precise, semantic micro-chunks, the language model is fed the full, cohesive parent paragraphs (up to 2048 tokens) to generate its answers.
By leveraging Docling for deep PDF structural parsing, Qdrant + BM25 for hybrid retrieval, and Groq for lightning-fast token streaming, QAMed ensures that medical professionals and students can quickly access precise information from authoritative texts without hallucinations.
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Medical PDF │ │ Query Input │ │ Final Answer │
│ Textbook │ │ (Complex Medical │ │ Synthesis │
│ │ │ Question) │ │ │
└────────┬────────┘ └─────────┬────────┘ └─────────▲───────┘
│ │ │
▼ ▼ │
┌─────────────────┐ ┌──────────────────┐ │
│ Document │ │ Query │ │
│ Processing │ │ Decomposition │ │
│ • Docling Parse │ │ • Groq LLM │ │
│ • 200-t Chunks │ │ • Sub-questions │ │
│ • LLM Micro-Tags│ │ • Caching (Redis)│ │
└────────┬────────┘ └─────────┬────────┘ │
│ │ │
▼ ▼ │
┌─────────────────┐ ┌──────────────────┐ ┌─────────┴───────┐
│ Storage │◄───┤ Hybrid Retrieval │ │ Answer │
│ • Qdrant (Dense)│ │ & Reranking │ │ Generation │
│ • SQLite (Text) │ │ • Dense + BM25 │ │ • Groq LLMs │
│ • S-PubMedBert │ │ • RRF Fusion │ │ • v3 Prompt │
│ • BM25 Index │ │ • BGE Reranker │ │ • Streaming │
└─────────────────┘ └──────────────────┘ └─────────────────┘
-
🏥 Advanced Ingestion Pipeline
- Docling PDF Parsing: Natively parses complex medical tables, clinical diagrams, and two-column layouts.
- Contextual Micro-Headers: Every chunk is passed through an LLM during ingestion to generate hierarchical breadcrumbs and anatomical summaries, ensuring disambiguation.
- Parent-Child Strategy: Chunks are small (200 tokens) for precise vector matching, but map to larger parent sections stored in a local SQLite database for context-rich generation.
-
🧠 Intelligent Query Processing
- LLM-Based Decomposition: Breaks down multi-part complex medical questions into independent sub-queries.
- Query Caching: Skips expensive retrieval for exact-match or semantically similar repeated questions.
- SIMPLE vs. COMPLEX Routing: Bypasses LLM generation for simple definitional queries, extracting raw textbook sentences directly.
-
🎯 Sophisticated Hybrid Retrieval
- Dense Search (Qdrant): Powered by
S-PubMedBertembeddings for deep semantic understanding. - Sparse Search (BM25): Built dynamically in-memory at startup to catch exact drug names and anatomical terminology.
- Reciprocal Rank Fusion (RRF): Fuses Dense and Sparse results (Top K=75).
- Cross-Encoder Reranking: Filters the noisy Top 75 pool down to the absolute best 6 chunks using
BAAI/bge-reranker-base.
- Dense Search (Qdrant): Powered by
-
🤖 High-Quality Answer Generation
- Groq LLMs: Llama 3.1 70B powers the synthesis with ultra-fast token streaming.
- Medical-Specific Prompting (v3): Explicitly instructed to synthesize cohesive, textbook-quality flowing responses and filter out MCQs or non-textbook artifacts.
- Python 3.9 or higher
- API Keys for Qdrant Cloud and Groq
python -m venv qamed-env
source qamed-env/bin/activate # On Windows: qamed-env\Scripts\activatepip install -r requirements.txtCreate a .env file in the root directory:
QDRANT_URL=your_qdrant_cloud_url
QDRANT_API_KEY=your_qdrant_api_key
GROQ_API_KEY=your_groq_api_key
GROQ_MODEL=llama-3.1-70b-versatile
PROMPT_VERSION=v3Use the CLI to process a PDF textbook. The --force flag ensures any old chunks for that specific book are cleanly deleted from Qdrant and SQLite before inserting the new ones.
python data/ingest.py --pdf "/path/to/your/medical_textbook.pdf" --forceNote: Docling layout parsing is CPU-intensive. A large medical textbook may take 30-60 minutes to extract before uploading begins.
Start the application interface:
streamlit run app.pyUpon startup, the app will connect to Qdrant, download your chunks, and dynamically build the BM25 sparse index in memory.
- Create a new Streamlit Space.
- Push this repository to your Space.
- Configure your Secrets in the Space settings (
QDRANT_URL,QDRANT_API_KEY,GROQ_API_KEY). - Ensure your local
data/doc_store.dbis committed to Git (do not add it to.gitignore!) so the HF Space can access the parent sections.
| Component | Author | License |
|---|---|---|
| Llama 3.1 (Groq API) | Meta | Llama 3.1 License |
| S-PubMedBert-MS-MARCO | Pritam Deka | MIT |
| Docling | IBM | MIT |
| BGE Reranker | BAAI | MIT |
The above models are downloaded at runtime via Hugging Face Hub or accessed via API.