|
1 | | -# RAG-based-Flight-Query-Bot |
| 1 | +# RAG-based Flight Query Bot |
| 2 | + |
| 3 | +## Project Overview |
| 4 | +The RAG-based Flight Query Bot is a Streamlit-powered web application that allows users to query flight information using natural language (e.g., "Show me flights from New York to London"). It uses Retrieval-Augmented Generation (RAG) with an Ollama language model to extract entities from queries and retrieve flight data from a mock database. The project is deployed on a local Kubernetes cluster using Minikube and includes a CI/CD pipeline with GitHub Actions for automated testing. |
| 5 | + |
| 6 | +### Architecture |
| 7 | +- **Frontend**: Streamlit UI (`app.py`) for user interaction. |
| 8 | +- **Backend**: |
| 9 | + - `query_handler.py`: Processes queries and extracts entities using Ollama. |
| 10 | + - `ollama_api.py`: Integrates with the Ollama LLM for natural language responses. |
| 11 | + - `mock_database.py`: Provides mock flight data and search functionality. |
| 12 | +- **Deployment**: Kubernetes on Minikube with two services: `flight-assistant-service` (Streamlit) and `ollama-service` (Ollama server). |
| 13 | +- **CI/CD**: GitHub Actions runs unit tests on every push or pull request. |
| 14 | + |
| 15 | +--- |
| 16 | + |
| 17 | +## Setup Instructions |
| 18 | + |
| 19 | +### Prerequisites |
| 20 | +- **Windows, macOS, or Linux** |
| 21 | +- **Python 3.10 or 3.11** |
| 22 | +- **Docker Desktop** (for building images and running Minikube) |
| 23 | +- **Minikube** (for local Kubernetes) |
| 24 | +- **kubectl** (Kubernetes CLI) |
| 25 | +- **Git** (for cloning the repository) |
| 26 | + |
| 27 | +### Step 1: Clone the Repository |
| 28 | +Clone this project to your local machine: |
| 29 | +```bash |
| 30 | +git clone https://github.com/RobuRishabh/RAG-based-Flight-Query-Bot.git |
| 31 | +cd RAG-based-Flight-Query-Bot |
| 32 | +``` |
| 33 | + |
| 34 | +### Step 2: Install Python Dependencies |
| 35 | +Create a virtual environment and install required Python packages: |
| 36 | +```bash |
| 37 | +# Create a virtual environment (optional but recommended) |
| 38 | +python -m venv flightquerybot |
| 39 | + |
| 40 | +# Activate it (Windows) |
| 41 | +flightquerybot\Scripts\activate |
| 42 | + |
| 43 | +# Activate it (macOS/Linux) |
| 44 | +source flightquerybot/bin/activate |
| 45 | + |
| 46 | +# Install dependencies |
| 47 | +pip install -r requirements.txt |
| 48 | +``` |
| 49 | + |
| 50 | +### Step 3: Set Up and Run the Local Ollama Server |
| 51 | +The project uses a local Ollama server for language processing. |
| 52 | + |
| 53 | +#### Install Ollama: |
| 54 | +- Download and install Ollama from [ollama.com](https://ollama.com). |
| 55 | +- Follow the installation instructions for your OS. |
| 56 | + |
| 57 | +#### Pull the Model: |
| 58 | +```bash |
| 59 | +ollama pull llama2:latest |
| 60 | +``` |
| 61 | +This downloads the `llama2:latest` model (default for this project). |
| 62 | + |
| 63 | +#### Run the Ollama Server: |
| 64 | +```bash |
| 65 | +ollama serve |
| 66 | +``` |
| 67 | +Keep this terminal open. The server runs at `http://localhost:11434`. |
| 68 | + |
| 69 | +### Step 4: Set Up Minikube |
| 70 | +Minikube creates a local Kubernetes cluster. |
| 71 | + |
| 72 | +#### Install Minikube: |
| 73 | +Follow the [official Minikube installation guide](https://minikube.sigs.k8s.io/docs/start/) for your OS. |
| 74 | +Example for Windows (using PowerShell as admin): |
| 75 | +#### Start Minikube: |
| 76 | +```bash |
| 77 | +minikube start |
| 78 | +``` |
| 79 | + |
| 80 | +#### Verify Minikube: |
| 81 | +```bash |
| 82 | +minikube status |
| 83 | +``` |
| 84 | +Ensure `host`, `kubelet`, and `apiserver` are `Running`. |
| 85 | + |
| 86 | +--- |
| 87 | + |
| 88 | +## Deployment Steps |
| 89 | + |
| 90 | +### Step 1: Build the Docker Image |
| 91 | +Build the `flight-assistant` Docker image using Minikube’s Docker daemon: |
| 92 | +```bash |
| 93 | +# Set Minikube's Docker environment |
| 94 | +eval $(minikube docker-env) |
| 95 | + |
| 96 | +# Build the image |
| 97 | +docker build -t flight-assistant:latest . |
| 98 | +``` |
| 99 | + |
| 100 | +### Step 2: Apply Kubernetes YAML Files |
| 101 | +Deploy the application and Ollama server to Minikube: |
| 102 | +```bash |
| 103 | +# Deploy Ollama server |
| 104 | +kubectl apply -f ollama-deployment.yaml |
| 105 | +kubectl apply -f ollama-service.yaml |
| 106 | + |
| 107 | +# Deploy Flight Assistant app |
| 108 | +kubectl apply -f deployment.yaml |
| 109 | +kubectl apply -f service.yaml |
| 110 | +``` |
| 111 | + |
| 112 | +### Step 3: Expose and Access the Services |
| 113 | +#### Start Minikube Tunnel: |
| 114 | +```bash |
| 115 | +minikube tunnel |
| 116 | +``` |
| 117 | +Keep this running to assign an external IP. |
| 118 | + |
| 119 | +#### Get the Service URL: |
| 120 | +```bash |
| 121 | +minikube service flight-assistant-service --url |
| 122 | +``` |
| 123 | +Example output: `http://192.168.49.2:8501`. |
| 124 | + |
| 125 | +#### Access the App: |
| 126 | +Open the URL in your browser to interact with the chatbot. |
| 127 | + |
| 128 | +--- |
| 129 | + |
| 130 | +## Usage |
| 131 | + |
| 132 | +### Interacting with the Chatbot UI |
| 133 | +1. Open the Streamlit app in your browser. |
| 134 | +2. Enter a query in the text box and press Enter. |
| 135 | +3. The bot processes your query and displays flight details or a "no flights found" message. |
| 136 | + |
| 137 | +#### Example Queries |
| 138 | +- `"Show me flight NY100"` → Shows details for flight `NY100`. |
| 139 | +- `"What are the flights from New York to London?"` → Lists matching flights. |
| 140 | +- `"Flights from Chicago"` → Shows flights departing from Chicago. |
| 141 | +- `"Flight XYZ999"` → Returns "No flights found" (invalid flight). |
| 142 | + |
| 143 | +--- |
| 144 | + |
| 145 | +## CI/CD Explanation |
| 146 | + |
| 147 | +### GitHub Actions Configuration |
| 148 | +This project uses GitHub Actions for Continuous Integration (CI) to ensure code quality. The workflow is defined in `.github/workflows/test.yml`. |
| 149 | + |
| 150 | +#### Workflow Details |
| 151 | +- **Trigger**: Runs on every `push` or `pull_request` to the `main` branch. |
| 152 | +- **Environment**: Uses an `ubuntu-latest` runner with Python 3.10. |
| 153 | +- **Steps**: |
| 154 | + - Checkout code: |
| 155 | + ```yaml |
| 156 | + - uses: actions/checkout@v4 |
| 157 | + ``` |
| 158 | + - Set up Python: |
| 159 | + ```yaml |
| 160 | + - uses: actions/setup-python@v5 |
| 161 | + with: |
| 162 | + python-version: '3.10' |
| 163 | + ``` |
| 164 | + - Install dependencies: |
| 165 | + ```yaml |
| 166 | + - run: | |
| 167 | + python -m pip install --upgrade pip |
| 168 | + pip install -r requirements.txt |
| 169 | + ``` |
| 170 | + - Run tests: |
| 171 | + ```yaml |
| 172 | + - run: | |
| 173 | + python -m unittest discover -s tests -p "test_*.py" |
| 174 | + ``` |
| 175 | +
|
| 176 | +--- |
| 177 | +
|
| 178 | +## Running Tests Locally |
| 179 | +To test before pushing: |
| 180 | +```bash |
| 181 | +# Activate virtual environment |
| 182 | +flightquerybot\Scripts\activate # Windows |
| 183 | +source flightquerybot/bin/activate # macOS/Linux |
| 184 | + |
| 185 | +# Run all tests |
| 186 | +python -m unittest discover -s tests -p "test_*.py" |
| 187 | +``` |
| 188 | +Expected output: `Ran X tests in Y.YYYs OK`. |
| 189 | + |
| 190 | +--- |
| 191 | + |
| 192 | +## Documentation Notes |
| 193 | + |
| 194 | +### Stopping Minikube |
| 195 | +```bash |
| 196 | +minikube stop |
| 197 | +``` |
| 198 | + |
| 199 | +### Cleanup (Reset Everything) |
| 200 | +```bash |
| 201 | +minikube delete |
| 202 | +``` |
| 203 | + |
| 204 | +### Troubleshooting |
| 205 | +If the UI doesn’t load, check pod logs: |
| 206 | +```bash |
| 207 | +kubectl logs -l app=flight-assistant |
| 208 | +kubectl logs -l app=ollama |
| 209 | +``` |
| 210 | +Ensure `minikube tunnel` is running for external access. |
| 211 | + |
| 212 | +--- |
0 commit comments