Biomedical RAG Chat Pipeline: End-to-End Flow
Describes a 10-step RAG pipeline for biomedical Q&A using Qdrant, PostgreSQL/pgvector, and Groq Llama 3.3-70b.
What this file does
Describes a 10-step RAG pipeline for biomedical Q&A using Qdrant, PostgreSQL/pgvector, and Groq Llama 3.3-70b.
When to use it
- Building a multi-turn chat system with document retrieval
- Implementing session-based memory for biomedical Q&A
- Combining vector stores for both documents and chat history
- Setting up a modular RAG pipeline with Google Drive ingestion
Assumes this stack
Biomedical RAG Chat Pipeline: End-to-End Flow
Overview
This pipeline enables Retrieval-Augmented Generation (RAG) for biomedical question answering, combining document retrieval (Qdrant) and chat memory (PostgreSQL/pgvector) with a state-of-the-art LLM (Groq Llama 3.3-70b). The system supports multi-turn chat, session-based memory, and scalable document ingestion.
Step-by-Step Flow
-
Google Drive Download
- PDFs are downloaded from a specified Google Drive folder.
- File:
src/data_access/google_drive_access.py
-
PDF Parsing
- PDFs are parsed into raw text.
- File:
src/data_access/pdf_parser.py
-
Document Chunking
- Raw text is split into manageable chunks for embedding.
- File:
src/data_access/document_chunker.py
-
Embedding Generation & Storage
- Each chunk is embedded using PubMedBERT.
- Embeddings are stored in Qdrant (vector DB) under a session/collection name.
- File:
src/data_access/embeddings_manager.py
-
Session Management
- All operations are session-based for isolation and multi-user support.
- File:
src/deep_recall/session_manager.py
-
Chat Memory Storage
- User and assistant messages are embedded and stored in PostgreSQL with pgvector.
- File:
src/deep_recall/memory/memory_store.py
-
Dual Retrieval (RAG)
- On each user query:
- Document Retrieval: Top-K relevant chunks are retrieved from Qdrant.
- Chat Retrieval: Top-K relevant chat messages are retrieved from PostgreSQL.
- Files:
- Document:
src/data_access/embeddings_manager.py - Chat:
src/deep_recall/memory/memory_store.py
- Document:
- On each user query:
-
Prompt Assembly
- Retrieved document and chat context are combined into a single prompt.
- File:
src/llm/groq_llama.py(assemble_prompt)
-
LLM Response Generation
- The prompt is sent to Groq's Llama 3.3-70b model via API.
- The assistant's response is returned and stored in chat memory.
- File:
src/llm/groq_llama.py
-
Chat Loop
- The user can continue asking questions; each turn updates chat memory and context.
- File:
src/llm/test_pipeline_groq.py
Flow Diagram
flowchart TD
A[Download PDFs from Google Drive] --> B[Parse PDFs to Text]
B --> C[Chunk Documents]
C --> D[Generate Embeddings]
D --> E[Store in Qdrant (Document Memory)]
subgraph Chat Session
F[User Query]
F --> G[Store User Message in Chat Memory (Postgres/pgvector)]
G --> H[Retrieve Top-K Docs from Qdrant]
G --> I[Retrieve Top-K Chat Messages]
H & I --> J[Assemble RAG Prompt]
J --> K[Groq Llama 3.3-70b API]
K --> L[Assistant Response]
L --> M[Store Assistant Message in Chat Memory]
L --> F
end
How Document and Chat Memory Work Together
- Document Memory (Qdrant):
- Stores vector embeddings of all document chunks.
- Enables fast, semantic retrieval of factual biomedical knowledge.
- Chat Memory (PostgreSQL/pgvector):
- Stores embeddings of all user and assistant messages per session.
- Enables retrieval of relevant chat history for context continuity.
- Combined Retrieval:
- Both memories are queried for each user input.
- The LLM receives both factual and conversational context for optimal answers.
Chat Loop Summary
- Each user message and assistant response is stored in chat memory.
- Retrieval always includes the latest chat history and relevant documents.
- The loop continues until the user types
exitorbreak. - Only the user's question and the assistant's answer are printed for clarity.
Main Files/Modules by Step
| Step | File/Module |
|---|---|
| Google Drive Download | google_drive_access.py |
| PDF Parsing | pdf_parser.py |
| Document Chunking | document_chunker.py |
| Embedding & Qdrant Storage | embeddings_manager.py |
| Session Management | session_manager.py |
| Chat Memory (Postgres) | memory_store.py |
| Document Retrieval | embeddings_manager.py |
| Chat Retrieval | memory_store.py |
| Prompt Assembly & LLM | groq_llama.py |
| Chat Loop | test_pipeline_groq.py |
Summary
This pipeline enables robust, session-based biomedical RAG chat with dual memory retrieval and state-of-the-art LLM responses. It is modular, scalable, and ready for research or production use.
What's inside
1 overview, 10 numbered steps, 1 Mermaid flowchart, 1 comparison table, 1 file list
Change this for your project
- Replace
Saikrishnapaila/avenio_aiwith your own repository name - Replace
Google Drivefolder reference with your own source - Replace
PubMedBERTwith your chosen embedding model - Replace
Groq Llama 3.3-70bwith your LLM endpoint
Where it goes
Reference documentation for a retrieval pipeline. Keep with the ingestion or retrieval code it describes.
Worth borrowing
- Dual retrieval from separate document and chat memory stores
- Session-based isolation for multi-user support
- Mermaid flowchart to visualise pipeline steps
Related Documents
SUMMARY
Proposes three on-prem AI architectures, modular, hybrid, and fully local RAG, with hardware specs and vendor lists.
Retrieval & Prompts
Explains how CharMemory's extraction prompt and Vector Storage settings determine memory retrieval quality in SillyTavern.
App Review Support Guide — Switch2Go
Explains an AAC app's accessibility permissions, hardware needs, and reviewer walkthrough to pass App Store review.
RFC-BLite: High-Performance Embedded Document Database for .NET
Specifies an embedded document database for.NET with zero-allocation I/O, C-BSON format, and ACID transactions.