This project is a Retrieval-Augmented Generation (RAG) pipeline that allows users to query medical PDFs and get context-aware, accurate answers using a local LLM. It uses LangChain, SentenceTransformers, Chroma vector store, and the BioMistral-7B model.
- 📄 Upload and parse PDF documents
- 🔍 Perform semantic search over embedded medical content
- 🤖 Generate medically-aligned answers using Llama-based LLM
- 🧠 Uses PubMedBERT for biomedical embeddings
Install required libraries (recommended to run in Google Colab):
pip install langchain sentence-transformers chromadb llama-cpp-python langchain_community pypdf/content/drive/MyDrive/Colab Notebooks/→ Your PDF files/content/drive/MyDrive/BioMistral-7B.Q2_K.gguf→ Your LLM file
-
Mount Google Drive:
from google.colab import drive drive.mount("/content/drive")
-
Load PDFs and Split Text:
from langchain_community.document_loaders import PyPDFDirectoryLoader ... docs = loader.load()
-
Generate Embeddings using PubMedBERT:
from langchain_community.embeddings import SentenceTransformerEmbeddings embedding = SentenceTransformerEmbeddings(model_name="NeuML/pubmedbert-base-embeddings")
-
Build Vector Store with Chroma:
vectorstore = Chroma.from_documents(chunks, embedding)
-
Load the Language Model:
from langchain_community.llms import LlamaCpp llm = LlamaCpp(model_path=".../BioMistral-7B.Q2_K.gguf", ...)
-
Start Chat Interface:
while True: user_input = input("Input query: ") ...
Input query: Who is at risk of heart disease?
Answer: [contextual answer based on the uploaded PDFs]
You can download the BioMistral 7B GGUF model (compatible with llama-cpp-python) here:
Recommended model file:
BioMistral-7B.Q2_K.gguf
Place the model in your Google Drive:
/content/drive/MyDrive/BioMistral-7B.Q2_K.gguf
- Don't forget to add your Hugging Face token if using private models or APIs:
os.environ["HUGGINGFACEHUB_API_TOKEN"] = "your_token_here"
- Never upload private tokens to public repositories.
This project combines:
- Biomedical language understanding (via PubMedBERT)
- Efficient document-based QA (via LangChain RAG pipeline)
- Local inference with LLMs (Llama.cpp)