# AI Session Summary — geonet-console ```yaml session: 2026-07-06-ai-chat-endpoint project: server-connection/geonet-console version: ai-fase3 status: deployed next: UI chat Super Apps PWA + user memory + ai.chat permission guard agent: Cascade branch: main ``` ## TL;DR - `POST /api/v1/ai/chat` + `GET /api/v1/ai/status` live di production (`console.gisportal.id`) - RAG pipeline: embed query → pgvector `10.100.1.24:5433` → 5 context chunks → Ollama `10.100.1.14:11434` → jawaban - Verified: query "route untuk feedback" → jawab `POST /api/v1/feedback` dengan akurat ## Files baru | File | Fungsi | |------|--------| | `app/Services/AiChatService.php` | Embed query, similarity search pgvector, generate via Ollama | | `app/Http/Controllers/Api/V1/AiChatController.php` | Handler `POST /api/v1/ai/chat` + `GET /api/v1/ai/status` | | `config/pgvector.php` | Config pgvector — baca env `PGVECTOR_HOST/PORT/DB/USER/PASSWORD` | ## Files dimodifikasi | File | Perubahan | |------|-----------| | `config/ollama.php` | Default URL → `10.100.1.14:11434`, model → `qwen2.5-coder:14b` | | `routes/api.php` | Tambah 2 route AI Chat, import `AiChatController` | ## Env vars baru di server `.env` ``` OLLAMA_BASE_URL=http://10.100.1.14:11434 OLLAMA_CHAT_MODEL=qwen2.5-coder:14b OLLAMA_EMBED_MODEL=nomic-embed-text PGVECTOR_HOST=10.100.1.24 PGVECTOR_PORT=5433 PGVECTOR_DB=geonet_project_search PGVECTOR_USER=geonet_ai PGVECTOR_PASSWORD= ``` ## API endpoint | Method | Path | Auth | Keterangan | |--------|------|------|-----------| | `GET` | `/api/v1/ai/status` | Bearer | Cek ketersediaan + model aktif | | `POST` | `/api/v1/ai/chat` | Bearer | Chat dengan RAG codebase | Request body `/ai/chat`: ```json { "message": "pertanyaan...", "history": [{"role":"user","content":"..."},{"role":"assistant","content":"..."}] } ``` ## Deploy notes - Image di-rebuild di `10.100.1.24` via `docker compose build geonet-console` - **Bug:** jangan gunakan `scp config/*.php routes/api.php root@host:/path/config/` dalam satu perintah — `routes/api.php` akan tertimpa ke `config/api.php` - Selalu deploy config dan routes terpisah ## Lanjut dari sini 1. **UI chat** di Super Apps PWA — React window, kirim ke `/api/v1/ai/chat` 2. **User memory** — `POST /api/v1/ai/memory`, simpan ke tabel `user_memory` di pgvector 3. **Permission guard** — tambah `ai.chat` ke `group_permissions`, guard di middleware 4. **Streaming** — opsional, tambah `stream: true` ke `OllamaService::chat()` ## Jangan - Jangan hardcode `PGVECTOR_PASSWORD` di source — baca dari env - Jangan expose `/api/v1/ai/chat` tanpa auth (`api.auth` middleware sudah aktif) - Jangan rebuild image tanpa verifikasi `config/api.php` isi yang benar