MERN-based FAQ chatbot that follows the RAG architecture for local question answering. Escalation is intentionally left out for now.
The app runs fully on local services:
- React + Vite provides the chatbot UI.
- Express exposes the FAQ and chat APIs.
- MongoDB stores FAQ documents and saved embeddings.
- A local Python embedding worker builds BGE embeddings with Transformers.
- The retriever ranks stored FAQ vectors against the query vector.
- Ollama runs the local chat model that generates the final answer from retrieved context.
- A user asks a question in the React chat page.
- Express sends the query to the embedding worker.
- The retriever compares the query embedding with FAQ embeddings stored in MongoDB.
- The top matching FAQ contexts are sent to Ollama.
- Ollama answers using only the retrieved FAQ context.
- The API returns the answer, confidence score, and source FAQ records.
- Node.js and npm
- MongoDB running locally
- Python 3.10+
- Ollama running locally
- An Ollama chat model, for example:
ollama pull gemma3:4bCreate local environment files:
cp server/.env.example server/.env
cp client/.env.example client/.envInstall JavaScript dependencies:
npm run install:allInstall Python dependencies:
python3 -m pip install -r server/requirements.txtSeed the FAQ database:
npm run seedRun the full project:
npm run devClient:
http://localhost:5173
Server:
http://localhost:5001
Default server configuration is in server/.env.example:
PORT=5001
MONGODB_URI=mongodb://127.0.0.1:27017/faq_vled_rag
CLIENT_ORIGIN=http://localhost:5173
MIN_CONFIDENCE=0.53
TOP_K=4
OLLAMA_BASE_URL=http://127.0.0.1:11434
OLLAMA_MODEL=gemma3:4b
FLAG_EMBEDDING_MODEL=BAAI/bge-small-en-v1.5
PYTHON_BIN=python3
EMBEDDING_TIMEOUT_MS=30000Run only the server:
npm run dev --prefix serverRun only the client:
npm run dev --prefix clientBuild the client:
npm run build --prefix clientRebuild embeddings after editing FAQ text directly in MongoDB:
npm run reindex --prefix serverImport Samagama FAQ data:
npm run import:samagama --prefix serverHealth check:
GET /healthChat:
POST /api/chat
Content-Type: application/json
{
"message": "How long is the internship?"
}Example response:
{
"answer": "Two months from your chosen start date...",
"answerFound": true,
"confidence": 0.7,
"sources": [
{
"id": "...",
"question": "How long is the internship?",
"category": "Timing and dates",
"score": 0.7008
}
]
}- FAQ embeddings are stored in MongoDB; they are not recomputed for every user query.
- User queries are embedded at request time so they can be compared with stored FAQ vectors.
- Ollama and MongoDB must be running before using the chatbot API.
- If the client shows that the chatbot API is unreachable, check Express, MongoDB, and Ollama first.