Rasheedj/mtech-chatbot
0
README.md
MTech.ai Chatbot
A conversational AI assistant for MTech.ai that answers questions about the company's projects and services using vector search and LLM technology.
Features
- Answers questions about company projects and services
- Utilizes vector search for relevant information retrieval
- Powered by Hugging Face models for embeddings and text generation
- FastAPI backend for efficient request handling
- Automatic document processing and indexing
Architecture
The application follows a modular architecture:
app.py: Main FastAPI applicationconfig.py: Configuration settingsllm.py: LLM integration for response generationloader.py: Document loading and chunkingvector_db.py: Vector database managementutils.py: Utility functions
Technical Stack
- FastAPI: Web framework
- Sentence Transformers: Embedding generation
- TinyLlama/Hugging Face: Text generation
- FAISS: Vector similarity search
- PyTorch: Deep learning framework
Setup Instructions
1. Install Dependencies
pip install -r requirements.txt2. Prepare Project Documents
Add markdown files with project information to the data/projects/ directory.
3. Run the Application
python -m appThe server will start on http://localhost:8000 by default.
API Endpoints
POST /query: Process a user query and return a responsePOST /rebuild_index: Rebuild the vector index from scratchGET /health: Check the health of the application
Deployment to Hugging Face Spaces
Prerequisites
- Hugging Face account
- Git LFS installed
Deployment Steps
- Create a new Hugging Face Space:
- Go to Hugging Face Spaces
- Click "Create a new Space"
- Select "FastAPI" as the SDK
- Name your space and set it to public or private
- Clone the space repository:
git clone https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME- Copy your application files to the cloned repository:
cp -r app.py config.py llm.py loader.py vector_db.py utils.py requirements.txt README.md /path/to/cloned/repo/- Create the data directory and add project files:
mkdir -p /path/to/cloned/repo/data/projects
cp -r data/projects/* /path/to/cloned/repo/data/projects/- Commit and push your changes:
cd /path/to/cloned/repo
git add .
git commit -m "Initial application deployment"
git pushThe Hugging Face platform will automatically build and deploy your application when you push to the repository.
Notes on Initialization
When deployed to Hugging Face Spaces, the application will automatically:
- Load and process all project documents
- Build a vector index for efficient retrieval
- Initialize the LLM for response generation
This happens during the first startup and may take a few minutes. Subsequent restarts will load the saved index for faster initialization.
Customization
- Adjust model settings in
config.pyto use different embedding or LLM models - Modify chunking parameters to optimize retrieval performance
- Add new project documents to expand the knowledge base
Troubleshooting
If the application fails to retrieve relevant information:
- Check if the vector index was properly built
- Verify that project documents contain the necessary information
- Adjust the similarity threshold in
config.py - Rebuild the index using the
/rebuild_indexendpoint
License
MIT
