This project provides a Retrieval-Augmented Generation (RAG) model designed to query medical journals for solving medical-related queries. By combining document retrieval with advanced language models, the system generates accurate, contextually relevant answers referencing the supplied medical literature.
-
Medical Journal Ingestion
- Automatically extracts content from PDF-format medical journals stored in the
datadirectory. - Splits text into manageable chunks for optimized retrieval and indexing.
- Automatically extracts content from PDF-format medical journals stored in the
-
RAG Framework
- Integrates document retrieval with generative AI to answer medical queries.
- Ensures factual, context-aware responses by grounding answers in referenced journals.
-
Chroma Vector Database
- Efficiently stores document embeddings for similarity searches.
- Supports incremental updates to include new journals or reset the database entirely.
-
Web and API Interface
- Flask-based API for querying the system programmatically.
- Web interface for users to interact with the system intuitively.
- Medical Practitioners: Quickly reference key insights from journals to support decision-making.
- Researchers: Retrieve specific information related to a query for their studies.
- Students: Access concise answers to medical questions, backed by journal citations.
-
Clone the Repository:
git clone https://github.com/your-username/medical-rag-system.git cd medical-rag-system -
Set Up a Virtual Environment:
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Dependencies:
pip install -r requirements.txt
-
Install Ollama:
Ollama is required to manage the embedding and language models. Install it using:curl -fsSL https://ollama.com/install.sh | sh -
Pull Required Models:
Fetch themistralandnomic-embed-textmodels using Ollama:ollama pull mistral ollama pull nomic-embed-text
-
Verify Model Availability:
Ensure the models are successfully installed:ollama list
medical-rag-system/
├── data/ # Directory for input medical journal PDFs.
├── chroma/ # Directory for the Chroma database.
├── templates/
│ └── chat.html # Web interface for queries.
├── POPULATE_DATA.py # Script to load and index medical journals.
├── GET_EMBEDDING_FUNCTION.py # Utility for embedding functions tailored for medical journals.
├── QUERY_DATA.py # Script for querying the indexed database.
├── QUERY_API.py # Flask-based API for query handling.
├── requirements.txt # Python dependencies.
└── README.md # Documentation.
Place your medical journals (PDF format) in the data directory.
python POPULATE_DATA.py To clear and rebuild the database:
python POPULATE_DATA.py --reset Run the following command to query the database with a medical question:
python QUERY_DATA.py "What are the latest treatments for type 2 diabetes?" Start the Flask application for the web interface:
python QUERY_API.py Visit http://127.0.0.1:5000 in your browser to interact with the system.
-
Document Processing
- Journals in PDF format are parsed into text chunks.
- Each chunk is assigned metadata, including source, page number, and chunk ID, for easy identification.
-
Embedding and Storage
- Text chunks are embedded using the
OllamaEmbeddingsmodel. - The embeddings are stored in a persistent Chroma vector database, enabling similarity-based retrieval.
- Text chunks are embedded using the
-
Query Handling
- Queries are matched against the database to retrieve the most relevant text chunks.
- A response is generated using the retrieved context and the
mistrallanguage model.
-
Web Interface
- The web-based chat interface simplifies user interaction for medical queries.
- LangChain: For efficient document handling, text splitting, and embedding integration.
- Ollama: Embedding generator and RAG response handler.
- Chroma: Vector database for fast similarity-based lookups.
- Flask: For API hosting and web interface.
- Additional Data Formats: Support formats beyond PDFs, like
.docxor.txt, by updating the document loader inGET_EMBEDDING_FUNCTION.py. - Improved Language Models: Integrate domain-specific models for better medical query responses.
- Enhanced UI: Upgrade
templates/chat.htmlfor a more user-friendly experience.
Contributions are welcome! Submit feature requests, report issues, or create pull requests to help improve this project.
This project is licensed under the MIT License. See the LICENSE file for details.