# Search API and UI Setup

FastAPI semantic search backend + vanilla HTML UI, proxied through Caddy.

## Architecture

```
/search/ → Caddy (handle_path /search/*) → reverse_proxy → FastAPI :8900
/api/*   → Caddy (handle /api/*)          → reverse_proxy → FastAPI :8900
```

## FastAPI Server (`search_api.py`)

### Endpoints
- `GET /` — Serves `search-ui/index.html`
- `GET /api/search?q=<query>&top_k=<N>` — Returns JSON results

### Response format
```json
{
  "results": [
    {
      "rank": 1,
      "score": 0.85,
      "path": "obsidian-vault/my-note.md",
      "title": "my-note",
      "preview": "file content preview (first 300 chars)..."
    }
  ],
  "total": 20
}
```

### Startup
```bash
cd /home/ubuntu/files
/path/to/venv/bin/python3 search-ui/search_api.py
# Runs on 127.0.0.1:8900
```

## Search UI (`index.html`)

Single-file dark-themed search page with:
- GitHub-dark color scheme
- Input + search button
- Loading spinner
- Results: path link, score badge, content preview
- URL query persistence (`?q=...`)
- Error handling

## Caddy routes
```caddy
handle_path /search/* {
    reverse_proxy 127.0.0.1:8900
}
redir /search /search/

handle /api/* {
    reverse_proxy 127.0.0.1:8900
}
```
