Kirushnapriya/Cardiac_Perfusion_RAG
Cardiac Perfusion RAG Assistant
A retrieval-augmented generation (RAG) chatbot that answers questions about cardiopulmonary bypass and cardiac perfusion, grounded in a small set of reference textbooks. Ask it a question, and it retrieves the most relevant passages from the indexed books, hands them to an LLM as context, and returns an answer with the source pages cited underneath.
Built with Gradio for the UI, ChromaDB for vector storage, sentence-transformers for embeddings, and Groq for inference.
How it works
- Ingest — PDFs in
data/pdfare loaded and split into overlapping chunks (src/data_loader.py). - Embed — each chunk is embedded with
sentence-transformers/all-MiniLM-L6-v2and written to a persistent ChromaDB collection atdata/vector_store(src/embedding.py,src/vector_store.py). - Retrieve — at query time, the question is embedded and the top-k most similar chunks are pulled from ChromaDB (
src/search.py). - Generate — the retrieved chunks are stuffed into a prompt and sent to Groq's
openai/gpt-oss-20bmodel, and the response is returned alongside the source book/page it came from (app.py).
Project layout
app.py # Gradio app: builds the retriever + LLM and serves the chat UI
main.py # One-off script to (re)build the vector store from data/pdf
src/
data_loader.py # Loads PDFs/text files into LangChain Document objects
embedding.py # Chunking + embedding pipeline (sentence-transformers)
vector_store.py # ChromaDB persistence layer
search.py # Similarity search / retrieval logic
data/
pdf/ # Source reference books (not committed — see below)
vector_store/ # Pre-built ChromaDB index, committed via Git LFSSetup
Requires Python 3.13+ and uv (the project is managed with uv/pyproject.toml, though requirements.txt is also kept in sync for environments that expect it).
git clone <this-repo>
cd RAG
uv syncCreate a .env file in the project root with your Groq API key:
GROQ_API_KEY=your-groq-api-key-hereRunning the app
uv run app.pyThis starts the Gradio chat interface on http://0.0.0.0:7860 (or the port set via the PORT env var), using the vector store that already ships in data/vector_store.
Rebuilding the vector store
The prebuilt index in data/vector_store covers the books currently in data/pdf. If you add, remove, or change the source PDFs, rebuild the index with:
uv run main.pyThis re-chunks and re-embeds everything under data/, then persists the new embeddings into ChromaDB. Note that data/* is gitignored except for data/vector_store, so source PDFs need to be supplied locally rather than pulled from the repo.
