A Retrieval-Augmented Generation (RAG) chatbot system with user authentication, PDF management, and vector database integration using FastAPI, LangChain, and ChromaDB.
- User Management: Admin and regular user authentication
- PDF Management: Upload, ingest, and delete PDFs per user
- Vector Database: ChromaDB integration with metadata preservation
- Chat Interface: Interactive chat client with authentication
- Azure Deployment: Docker-based deployment on Azure VM
- Python 3.8+
- OpenAI API key
- SQLite (included)
- ChromaDB (included)
-
Clone and install
git clone https://github.com/kittysoftpaw0510/RAG_chatbot cd RAG_chatbot pip install -r requirements.txt -
Environment setup
mkdir data # Copy your PDF files into 'data' directory -
Create .env file
OPENAI_API_KEY=sk-proj-xxx ADMIN_USERNAME=admin ADMIN_PASSWORD=your_admin_password -
Start the server
uvicorn main:app --host 0.0.0.0 --port 8000
-
Use the chat client
python Client/chat_client.py
- Admin Users: Authenticated using environment variables
- Regular Users: Stored in SQLite database
- Session Management: Credentials required for each operation
-
Admin Functions:
- View all users
- Reset user passwords
- Manage all PDFs
- Clear vector database
-
Regular User Functions:
- Upload PDFs
- Ingest PDFs manually
- Chat with their documents
- Delete their own PDFs
- Upload PDFs: Files are stored in user-specific directories
- Manual Ingestion: Process PDFs to create vector embeddings
- Metadata Preservation: User information stored with embeddings
- Upload PDFs to user directory
- Ingest PDFs to vector database
- Delete PDFs (files + database records + embeddings)
- Clear all vector embeddings
POST /login- User authenticationPOST /admin/login- Admin authentication
GET /users- List all users (admin only)POST /users- Create new userPUT /users/{user_id}/password- Reset user password (admin only)
POST /upload/{user_id}- Upload PDF for userPOST /ingest/{user_id}- Ingest PDFs for userDELETE /pdfs/{user_id}- Delete all PDFs for userDELETE /pdfs/{user_id}/{filename}- Delete specific PDF
POST /chat- Chat with RAG system
- Azure CLI
- Docker
- SSH access
-
Azure CLI setup
az login az group create --name rag-chatbot-rg --location eastus
-
Create VM
az vm create --resource-group rag-chatbot-rg --name rag-vm \ --image UbuntuLTS --admin-username azureuser \ --generate-ssh-keys --size Standard_DS2_v2
-
Configure VM
az vm open-port --port 8000 --resource-group rag-chatbot-rg --name rag-vm
-
Deploy with Docker
docker build -t ragbot . docker run -d -p 8000:8000 --name rag_container ragbot
python Client/test_multi_chat.pyRAG_chatbot/
├── Client/
│ ├── admin_tools.py
│ ├── chat_client.py
│ ├── test_multi_chat.py
│ ├── user_tools.py
├── data/
│ ├── public/
│ │ └── ... (public PDFs)
│ ├── user_1/
│ │ └── ... (user_1's PDFs)
│ └── ... (other user folders)
├── Dockerfile
├── main.py
├── README.md
├── requirements.txt
├── routes/
│ ├── admin/
│ │ ├── admin_auth.py
│ │ ├── chat_manage.py
│ │ ├── data_manage.py
│ │ ├── user_manage.py
│ │ └── vectordb_manage.py
│ └── user/
│ ├── chat_manage.py
│ ├── data_manage.py
│ ├── user_auth.py
│ ├── user_manage.py
│ └── vectordb_manage.py
└── utils/
├── ingest.py
├── llm.py
├── vectordb.py
└── sqlitedb.py
OPENAI_API_KEY: Your OpenAI API keyADMIN_USERNAME: Admin username (default: admin)ADMIN_PASSWORD: Admin password
- SQLite: User management and PDF metadata
- ChromaDB: Vector embeddings storage
-
Authentication Errors
- Verify .env file exists with correct credentials
- Check user exists in SQLite database
-
PDF Upload Issues
- Ensure data directory exists
- Check file permissions
-
Vector Database Issues
- Clear chroma directory if corrupted
- Re-ingest PDFs after clearing
-
Azure Deployment
- Verify port 8000 is open
- Check Docker container is running
- Ensure environment variables are set
# Clear vector database
python Client/memory_management.py --clear-vectors
# List all users
python Client/user_management.py --list-users
# Delete user PDFs
python Client/data_management.py --delete-user-pdfs USER_ID
# Admin operations
python Client/admin_tools.py --reset-password USER_ID
# User operations
python Client/user_tools.py --create-user USERNAME PASSWORD- Update API endpoints in
main.py - Add corresponding client functions
- Update database schema if needed
- Test with multiple users
- Use
test_multi_chat.pyfor Azure deployment testing - Test user isolation and permissions
- Verify PDF operations work correctly
For detailed deployment instructions and troubleshooting, see the original documentation sections below.