|
| 1 | +# Web Hosting Guide for Archive-RAG |
| 2 | + |
| 3 | +This guide explains how to host your Archive-RAG system publicly using the built-in web interface. |
| 4 | + |
| 5 | +## Quick Start |
| 6 | + |
| 7 | +### 1. Create an Index |
| 8 | + |
| 9 | +First, ensure you have an index file. If you don't have one yet: |
| 10 | + |
| 11 | +```bash |
| 12 | +# Index sample data from GitHub |
| 13 | +archive-rag index "https://raw.githubusercontent.com/SingularityNET-Archive/SingularityNET-Archive/refs/heads/main/Data/Snet-Ambassador-Program/Meeting-Summaries/2025/meeting-summaries-array.json" indexes/sample-meetings.faiss --no-redact-pii |
| 14 | +``` |
| 15 | + |
| 16 | +### 2. Start the Web Server |
| 17 | + |
| 18 | +```bash |
| 19 | +# Start on default port 8000 |
| 20 | +archive-rag web |
| 21 | + |
| 22 | +# Or specify custom host and port |
| 23 | +archive-rag web --host 0.0.0.0 --port 8080 |
| 24 | + |
| 25 | +# For development with auto-reload |
| 26 | +archive-rag web --reload |
| 27 | +``` |
| 28 | + |
| 29 | +### 3. Access the Interface |
| 30 | + |
| 31 | +Open your browser and navigate to: |
| 32 | +- **Local access**: http://localhost:8000 |
| 33 | +- **Network access**: http://YOUR_IP:8000 |
| 34 | + |
| 35 | +## Configuration |
| 36 | + |
| 37 | +### Environment Variables |
| 38 | + |
| 39 | +You can configure the web server using environment variables: |
| 40 | + |
| 41 | +```bash |
| 42 | +# Set default index file path |
| 43 | +export ARCHIVE_RAG_INDEX_PATH="indexes/sample-meetings.faiss" |
| 44 | + |
| 45 | +# Start the server |
| 46 | +archive-rag web |
| 47 | +``` |
| 48 | + |
| 49 | +### Default Index Selection |
| 50 | + |
| 51 | +If `ARCHIVE_RAG_INDEX_PATH` is not set, the server will: |
| 52 | +1. Look for `indexes/sample-meetings.faiss` |
| 53 | +2. If not found, use the first `.faiss` file found in `indexes/` |
| 54 | +3. If no index is found, return an error |
| 55 | + |
| 56 | +## API Endpoints |
| 57 | + |
| 58 | +The web server provides both a web interface and a REST API: |
| 59 | + |
| 60 | +### Web Interface |
| 61 | +- `GET /` - Web UI for querying |
| 62 | + |
| 63 | +### REST API |
| 64 | +- `POST /api/query` - Query the RAG system |
| 65 | +- `GET /api/health` - Health check endpoint |
| 66 | + |
| 67 | +### Example API Usage |
| 68 | + |
| 69 | +```bash |
| 70 | +# Query via API |
| 71 | +curl -X POST "http://localhost:8000/api/query" \ |
| 72 | + -H "Content-Type: application/json" \ |
| 73 | + -d '{ |
| 74 | + "query": "What decisions were made about budget allocation?", |
| 75 | + "top_k": 5 |
| 76 | + }' |
| 77 | + |
| 78 | +# Health check |
| 79 | +curl http://localhost:8000/api/health |
| 80 | +``` |
| 81 | + |
| 82 | +## Deployment Options |
| 83 | + |
| 84 | +### Option 1: Railway |
| 85 | + |
| 86 | +1. **Create a Railway account** at https://railway.app |
| 87 | + |
| 88 | +2. **Create a new project** and connect your GitHub repository |
| 89 | + |
| 90 | +3. **Add environment variables**: |
| 91 | + - `ARCHIVE_RAG_INDEX_PATH`: Path to your index file (if not using default) |
| 92 | + |
| 93 | +4. **Configure the start command**: |
| 94 | + ```bash |
| 95 | + archive-rag web --host 0.0.0.0 --port $PORT |
| 96 | + ``` |
| 97 | + |
| 98 | +5. **Deploy**: Railway will automatically deploy when you push to your repository |
| 99 | + |
| 100 | +### Option 2: Render |
| 101 | + |
| 102 | +1. **Create a Render account** at https://render.com |
| 103 | + |
| 104 | +2. **Create a new Web Service**: |
| 105 | + - Connect your GitHub repository |
| 106 | + - Build command: `pip install -r requirements.txt` |
| 107 | + - Start command: `archive-rag web --host 0.0.0.0 --port $PORT` |
| 108 | + |
| 109 | +3. **Add environment variables**: |
| 110 | + - `ARCHIVE_RAG_INDEX_PATH`: Path to your index file |
| 111 | + |
| 112 | +4. **Deploy**: Render will build and deploy your service |
| 113 | + |
| 114 | +### Option 3: Fly.io |
| 115 | + |
| 116 | +1. **Install Fly CLI**: `curl -L https://fly.io/install.sh | sh` |
| 117 | + |
| 118 | +2. **Create a `fly.toml`**: |
| 119 | + ```toml |
| 120 | + app = "your-app-name" |
| 121 | + primary_region = "iad" |
| 122 | + |
| 123 | + [build] |
| 124 | + |
| 125 | + [http_service] |
| 126 | + internal_port = 8000 |
| 127 | + force_https = true |
| 128 | + auto_stop_machines = true |
| 129 | + auto_start_machines = true |
| 130 | + min_machines_running = 0 |
| 131 | + |
| 132 | + [[services]] |
| 133 | + protocol = "tcp" |
| 134 | + internal_port = 8000 |
| 135 | + ``` |
| 136 | + |
| 137 | +3. **Deploy**: |
| 138 | + ```bash |
| 139 | + fly launch |
| 140 | + fly deploy |
| 141 | + ``` |
| 142 | + |
| 143 | +### Option 4: Docker |
| 144 | + |
| 145 | +1. **Create a `Dockerfile`**: |
| 146 | + ```dockerfile |
| 147 | + FROM python:3.11-slim |
| 148 | + |
| 149 | + WORKDIR /app |
| 150 | + |
| 151 | + # Install system dependencies |
| 152 | + RUN apt-get update && apt-get install -y \ |
| 153 | + build-essential \ |
| 154 | + && rm -rf /var/lib/apt/lists/* |
| 155 | + |
| 156 | + # Copy requirements and install Python dependencies |
| 157 | + COPY requirements.txt . |
| 158 | + RUN pip install --no-cache-dir -r requirements.txt |
| 159 | + |
| 160 | + # Download spaCy model |
| 161 | + RUN python -m spacy download en_core_web_sm |
| 162 | + |
| 163 | + # Copy application code |
| 164 | + COPY . . |
| 165 | + |
| 166 | + # Install the package |
| 167 | + RUN pip install -e . |
| 168 | + |
| 169 | + # Expose port |
| 170 | + EXPOSE 8000 |
| 171 | + |
| 172 | + # Start the web server |
| 173 | + CMD ["archive-rag", "web", "--host", "0.0.0.0", "--port", "8000"] |
| 174 | + ``` |
| 175 | + |
| 176 | +2. **Build and run**: |
| 177 | + ```bash |
| 178 | + docker build -t archive-rag . |
| 179 | + docker run -p 8000:8000 -e ARCHIVE_RAG_INDEX_PATH=indexes/sample-meetings.faiss archive-rag |
| 180 | + ``` |
| 181 | + |
| 182 | +### Option 5: VPS (DigitalOcean, AWS EC2, etc.) |
| 183 | + |
| 184 | +1. **Set up your server** with Python 3.11+ |
| 185 | + |
| 186 | +2. **Clone and install**: |
| 187 | + ```bash |
| 188 | + git clone <your-repo> |
| 189 | + cd Archive-RAG |
| 190 | + python3 -m venv venv |
| 191 | + source venv/bin/activate |
| 192 | + pip install -r requirements.txt |
| 193 | + pip install -e . |
| 194 | + ``` |
| 195 | + |
| 196 | +3. **Create a systemd service** (`/etc/systemd/system/archive-rag.service`): |
| 197 | + ```ini |
| 198 | + [Unit] |
| 199 | + Description=Archive-RAG Web Server |
| 200 | + After=network.target |
| 201 | + |
| 202 | + [Service] |
| 203 | + Type=simple |
| 204 | + User=your-user |
| 205 | + WorkingDirectory=/path/to/Archive-RAG |
| 206 | + Environment="PATH=/path/to/Archive-RAG/venv/bin" |
| 207 | + Environment="ARCHIVE_RAG_INDEX_PATH=indexes/sample-meetings.faiss" |
| 208 | + ExecStart=/path/to/Archive-RAG/venv/bin/archive-rag web --host 0.0.0.0 --port 8000 |
| 209 | + Restart=always |
| 210 | + |
| 211 | + [Install] |
| 212 | + WantedBy=multi-user.target |
| 213 | + ``` |
| 214 | + |
| 215 | +4. **Start the service**: |
| 216 | + ```bash |
| 217 | + sudo systemctl enable archive-rag |
| 218 | + sudo systemctl start archive-rag |
| 219 | + ``` |
| 220 | + |
| 221 | +5. **Set up Nginx reverse proxy** (optional but recommended): |
| 222 | + ```nginx |
| 223 | + server { |
| 224 | + listen 80; |
| 225 | + server_name your-domain.com; |
| 226 | +
|
| 227 | + location / { |
| 228 | + proxy_pass http://localhost:8000; |
| 229 | + proxy_set_header Host $host; |
| 230 | + proxy_set_header X-Real-IP $remote_addr; |
| 231 | + } |
| 232 | + } |
| 233 | + ``` |
| 234 | + |
| 235 | +## Security Considerations |
| 236 | + |
| 237 | +### For Production Deployment |
| 238 | + |
| 239 | +1. **Restrict CORS**: Update `src/web/app.py` to restrict CORS origins: |
| 240 | + ```python |
| 241 | + app.add_middleware( |
| 242 | + CORSMiddleware, |
| 243 | + allow_origins=["https://your-domain.com"], # Replace with your domain |
| 244 | + allow_credentials=True, |
| 245 | + allow_methods=["GET", "POST"], |
| 246 | + allow_headers=["*"], |
| 247 | + ) |
| 248 | + ``` |
| 249 | + |
| 250 | +2. **Add Rate Limiting**: Consider adding rate limiting middleware to prevent abuse |
| 251 | + |
| 252 | +3. **Use HTTPS**: Always use HTTPS in production (most platforms provide this automatically) |
| 253 | + |
| 254 | +4. **Environment Variables**: Store sensitive configuration in environment variables, not in code |
| 255 | + |
| 256 | +5. **Authentication**: For private deployments, consider adding authentication middleware |
| 257 | + |
| 258 | +## Troubleshooting |
| 259 | + |
| 260 | +### Index Not Found |
| 261 | + |
| 262 | +If you see "No index file found": |
| 263 | +1. Ensure you've created an index using `archive-rag index` |
| 264 | +2. Set `ARCHIVE_RAG_INDEX_PATH` environment variable |
| 265 | +3. Check that the index file exists in the `indexes/` directory |
| 266 | + |
| 267 | +### Port Already in Use |
| 268 | + |
| 269 | +If port 8000 is already in use: |
| 270 | +```bash |
| 271 | +# Use a different port |
| 272 | +archive-rag web --port 8080 |
| 273 | +``` |
| 274 | + |
| 275 | +### Memory Issues |
| 276 | + |
| 277 | +The RAG system loads models into memory. For large deployments: |
| 278 | +- Ensure your server has at least 4GB RAM |
| 279 | +- Consider using a larger instance for production |
| 280 | +- Monitor memory usage and scale as needed |
| 281 | + |
| 282 | +## Performance Tips |
| 283 | + |
| 284 | +1. **Pre-load models**: The first query may be slower as models load |
| 285 | +2. **Use caching**: Consider adding Redis for query result caching |
| 286 | +3. **Load balancing**: For high traffic, use multiple instances behind a load balancer |
| 287 | +4. **CDN**: Serve static assets through a CDN if customizing the UI |
| 288 | + |
| 289 | +## Next Steps |
| 290 | + |
| 291 | +- Customize the web interface in `src/web/app.py` |
| 292 | +- Add authentication if needed |
| 293 | +- Set up monitoring and logging |
| 294 | +- Configure backups for your index files |
| 295 | + |
| 296 | + |
0 commit comments