This project is a web-based chatbot built using Flask, MongoDB, and TF-IDF based similarity matching.
The chatbot answers user queries by finding the most similar question in the database.
Queries that cannot be answered are logged for future improvements.
- Flask-based web API for chatbot interaction
- Stores questions and answers in MongoDB
- Uses TF-IDF vectorization and cosine similarity for query matching
- Handles unanswered queries automatically
- CORS enabled for front-end integration
app.py— Main Flask applicationmongodb.py— Script to insert QA pairs into MongoDBrequirements.txt— Python dependenciesREADME.md— Project documentation
- Python 3.8+
- MongoDB Atlas account or local MongoDB instance
- pip package manager
Open your terminal and run:
git clone https://github.com/experimentalsolution/chatbot-experimental-solution.git
cd my-project
pip install -r requirements.txt- Create a database named chatbot_db.
- Create collections:
- qa_pairs → standard QA pairs
- qa_pairs_experimental_solution → experimental QA pairs
- qa_pairs_not_answered → unanswered queries
- Update the MongoDB URI in app.py and mongodb.py:
- MONGO_URI = "your_mongodb_connection_string"
python mongodb.pyStart the Flask server:
python app.pyDefault server: http://127.0.0.1:5000/ POST request to /chatbot with JSON payload:
{ "query": "Hello" }
Response example:
{ "response": "Morning, Afternoon, Evening to whatever time zone you are! How can I help you?" }
- Fetches all questions and responses from MongoDB.
- Converts questions into vectors using TF-IDF.
- Compares the user query to stored questions with cosine similarity.
- Returns the matched response if similarity > 50%.
- Logs queries that cannot be answered to qa_pairs_not_answered.
- Add machine learning models for better query understanding
- Implement intent classification
- Build a frontend UI for live interaction
- Enable real-time learning from unanswered queries
- Flask
- Flask-CORS
- pymongo
- scikit-learn
pip install flask flask-cors pymongo scikit-learnLive demo is created here on a angular front end .It is deployed . Please check it out and share your feedback .
MIT License