A full-stack medical assistant that answers user questions with retrieval-augmented generation (RAG), chat history, and a clean React interface. The app is split into three layers:
- A React frontend for the chat UI
- An Express + MongoDB backend for chat/session storage
- A FastAPI + LangChain service that retrieves medical context from Pinecone and generates answers with Groq
RAG Medical Chatbot is built to help users ask medical questions in a conversational way. When a question is sent, the backend stores the message in MongoDB, forwards the prompt to the AI service, and then saves the assistant reply back into the same chat thread.
The AI service uses:
- Pinecone for semantic retrieval over the indexed medical knowledge base
- LangChain for retrieval and prompt orchestration
- Groq as the chat model provider
If the answer is not supported by the retrieved context, the model is instructed to say so instead of guessing.
flowchart LR
U[User] --> F[React Frontend]
F --> B[Express Backend]
B --> M[(MongoDB)]
B --> A[FastAPI AI Service]
A --> P[Pinecone Vector Store]
A --> G[Groq LLM]
A --> B
B --> F
- The user opens the chat UI and starts a new conversation.
- The frontend sends the question to the Express backend.
- The backend stores the user message in MongoDB.
- The backend calls the FastAPI AI service.
- The AI service retrieves relevant medical chunks from Pinecone.
- Groq generates a grounded answer using the retrieved context.
- The backend stores the assistant response and updates the chat title on the first message.
- The frontend refreshes the conversation list and renders the reply.
- Medical question answering with RAG
- Persistent chat history per conversation
- Automatic chat title generation
- Sidebar with previous chats
- Clean, responsive chat interface
- Separate AI service for retrieval and generation logic
- Frontend: React, Vite, Axios
- Backend: Node.js, Express, MongoDB, Mongoose, Axios, CORS
- AI Service: FastAPI, LangChain, Pinecone, Groq, Python
RAG-medibot/
├── frontend/ # React UI
├── backend/ # Express API + MongoDB models
├── ai-service/ # FastAPI RAG service and indexing scripts
├── docs/ # Project docs
└── scripts/ # Utility scripts
Make sure you have the following installed:
- Node.js 18 or newer
- Python 3.10 or newer
- MongoDB running locally or in the cloud
- A Pinecone account and index
- A Groq API key
git clone <your-repo-url> cd RAG-medibot
cd backend
npm installCreate a .env file inside backend/:
MONGO_URL=your_mongodb_connection_string
cd ../ai-service
python -m venv .venvActivate the virtual environment:
- Windows PowerShell:
.venv\Scripts\Activate.ps1 - Command Prompt:
.venv\Scripts\activate.bat - macOS/Linux:
source .venv/bin/activate
Install Python dependencies:
pip install -r requirements.txt
Create a .env file inside ai-service/:
PINECONE_API_KEY=your_pinecone_api_key GROQ_API_KEY=your_groq_api_key
If you need to build the Pinecone knowledge base from the local data folder, run the indexing script first:
python store_index.py
cd ../frontend
npm installOpen three terminals and start each service separately.
cd backend
node server.jsThe backend runs on http://localhost:8080.
cd ai-service
uvicorn app:app --reload --port 8000The FastAPI service runs on http://127.0.0.1:8000.
cd frontend
npm run devThe frontend runs on http://localhost:5173.
POST /api/ai/createNewChatcreates a new chat threadGET /api/ai/getChatsreturns all saved chatsGET /api/ai/getOldChats/:idreturns the messages for one chatPOST /api/ai/ask-aisends a question to the AI service and stores the answerPOST /api/ai-service/datais the FastAPI RAG endpoint used by the backend
Click the thumbnail above to open the demo video.
- The medical assistant is meant for informational use and should not be treated as a substitute for professional medical advice.
- The AI answer quality depends on the indexed knowledge base, the Pinecone index, and the configured Groq model.
- If chat history is missing, check that MongoDB is running and that the backend is connected successfully.
Sahid Ahmed