-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathinstall.ps1
More file actions
495 lines (425 loc) · 15.7 KB
/
Copy pathinstall.ps1
File metadata and controls
495 lines (425 loc) · 15.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
# Nosia Installation Script for Windows
# Usage: Invoke-WebRequest https://get.nosia.ai/install.ps1 -OutFile install.ps1; .\install.ps1
# Set strict mode
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
# Detect system resources and return as hashtable
function Detect-SystemResources {
Write-Host "Detecting system resources..."
# Get total RAM in GB
$SYSTEM_RAM_GB = 0
$computerInfo = Get-CimInstance -ClassName Win32_ComputerSystem
if ($computerInfo.TotalPhysicalMemory) {
$SYSTEM_RAM_GB = [math]::Round($computerInfo.TotalPhysicalMemory / 1GB, 0)
}
# Get CPU cores/threads
$CPU_CORES = 1
$processorInfo = Get-CimInstance -ClassName Win32_Processor
if ($processorInfo) {
$CPU_CORES = $processorInfo.NumberOfLogicalProcessors
}
# Detect GPU type and VRAM - Windows specific
$GPU_TYPE = "none"
$GPU_VRAM_GB = 0
try {
$gpuInfo = Get-CimInstance -ClassName Win32_VideoController | Select-Object -First 1
if ($gpuInfo) {
$adapterRAM = $gpuInfo.AdapterRAM
if ($adapterRAM -gt 0) {
$GPU_VRAM_GB = [math]::Round($adapterRAM / 1GB, 0)
# Try to detect GPU type
$description = $gpuInfo.Description -replace "\s+", " "
if ($description -match "NVIDIA|GeForce|RTX|GTX") {
$GPU_TYPE = "nvidia"
Write-Host "Detected NVIDIA GPU with $GPU_VRAM_GB GB VRAM"
} elseif ($description -match "AMD|Radeon|ATI") {
$GPU_TYPE = "amd"
Write-Host "Detected AMD GPU with $GPU_VRAM_GB GB VRAM"
} elseif ($description -match "Intel|HD Graphics|Iris") {
$GPU_TYPE = "integrated"
Write-Host "Detected integrated GPU"
}
}
}
} catch {
# GPU detection failed, continue with defaults
}
# If no GPU found, estimate based on RAM
if ($GPU_TYPE -eq "none") {
if ($SYSTEM_RAM_GB -ge 16) {
$GPU_TYPE = "cpu_highmem"
Write-Host "No GPU detected, treating as CPU with high RAM"
} else {
$GPU_TYPE = "cpu"
Write-Host "No GPU detected, treating as CPU with standard RAM"
}
}
Write-Host "System resources: $SYSTEM_RAM_GB GB RAM, $CPU_CORES CPU cores, $GPU_TYPE ($GPU_VRAM_GB GB VRAM)"
return @{
SYSTEM_RAM_GB = $SYSTEM_RAM_GB
CPU_CORES = $CPU_CORES
GPU_TYPE = $GPU_TYPE
GPU_VRAM_GB = $GPU_VRAM_GB
}
}
# Memory available to model inference: the larger of GPU VRAM (GPU/offloaded
# inference) or system RAM (CPU inference). Docker Model Runner can run on
# either, so the bigger pool bounds the largest model that fits.
function Get-UsableMemoryGB {
param(
[int]$gpu_vram,
[int]$system_ram
)
if ($gpu_vram -gt $system_ram) {
return $gpu_vram
} else {
return $system_ram
}
}
# Select LLM model based on system resources.
# Footprints (approx, with context + a concurrent embedding model):
# ai/mistral-small4:119B ~70GB | ai/gemma4:26B ~16GB
# ai/gemma4:E4B ~4GB | ai/gemma4:E2B ~2GB
function Select-LLMModel {
param(
[int]$gpu_vram,
[int]$system_ram
)
$available = Get-UsableMemoryGB -gpu_vram $gpu_vram -system_ram $system_ram
if ($available -ge 96) {
return "ai/mistral-small4:119B|32768|1024|256"
} elseif ($available -ge 24) {
return "ai/gemma4:26B|32768|1024|256"
} elseif ($available -ge 8) {
return "ai/gemma4:E4B|32768|512|128"
} else {
return "ai/gemma4:E2B|32768|512|128"
}
}
# Select embedding model based on system resources.
# ai/qwen3-embedding:8B-F16 needs ~16GB on top of the LLM, so it is reserved
# for machines that also comfortably run a large LLM. Everything else uses the
# tiny ~0.6GB ai/granite-embedding-multilingual:278M-F16.
function Select-EmbeddingModel {
param(
[int]$gpu_vram,
[int]$system_ram
)
$available = Get-UsableMemoryGB -gpu_vram $gpu_vram -system_ram $system_ram
if ($available -ge 48) {
return "ai/qwen3-embedding:8B-F16|4096|1024|256"
} else {
return "ai/granite-embedding-multilingual:278M-F16|768|512|128"
}
}
# Generate docker-compose.yml
function Generate-DockerCompose {
$composeContent = @"
services:
reverse-proxy:
image: caddy:latest
depends_on:
- web
restart: unless-stopped
ports:
- "80:80"
- "443:443"
environment:
- NOSIA_URL=`${NOSIA_URL}
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- caddy-config:/config
- caddy-data:/data
db-migrate:
image: dilolabs/nosia:latest
command: bundle exec rails db:prepare
environment:
- DATABASE_URL=`${DATABASE_URL}
- SECRET_KEY_BASE=`${SECRET_KEY_BASE}
- ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY=`${ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY}
- ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY=`${ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY}
- ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT=`${ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT}
depends_on:
postgres-db:
condition: service_healthy
restart: "no"
web:
image: dilolabs/nosia:latest
environment:
- DATABASE_URL=`${DATABASE_URL}
- SECRET_KEY_BASE=`${SECRET_KEY_BASE}
- ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY=`${ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY}
- ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY=`${ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY}
- ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT=`${ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT}
- AI_BASE_URL=`${AI_BASE_URL}
- AI_API_KEY=`${AI_API_KEY}
- LLM_MODEL=`${LLM_MODEL}
- LLM_TEMPERATURE=`${LLM_TEMPERATURE}
- LLM_MAX_TOKENS=`${LLM_MAX_TOKENS}
- LLM_TOP_P=`${LLM_TOP_P}
- EMBEDDING_MODEL=`${EMBEDDING_MODEL}
- EMBEDDING_DIMENSIONS=`${EMBEDDING_DIMENSIONS}
- CHUNK_SIZE=`${CHUNK_SIZE}
- CHUNK_OVERLAP=`${CHUNK_OVERLAP}
- RETRIEVAL_FETCH_K=`${RETRIEVAL_FETCH_K}
- GUARD_MODEL=`${GUARD_MODEL}
- AUGMENTED_CONTEXT=`${AUGMENTED_CONTEXT}
models:
- llm
- embedding
volumes:
- rails-storage:/rails/storage
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/up"]
interval: 2s
timeout: 5s
retries: 30
depends_on:
postgres-db:
condition: service_healthy
db-migrate:
condition: service_completed_successfully
restart: on-failure:5
postgres-db:
image: pgvector/pgvector:pg16
environment:
- POSTGRES_DB=`${POSTGRES_DB}
- POSTGRES_USER=`${POSTGRES_USER}
- POSTGRES_PASSWORD=`${POSTGRES_PASSWORD}
volumes:
- postgres-db-data:/var/lib/postgresql/data
ports:
- "5432:5432"
healthcheck:
test: pg_isready -U `${POSTGRES_USER} -d `${POSTGRES_DB}
interval: 2s
timeout: 5s
retries: 30
restart: on-failure:5
solidq:
image: dilolabs/nosia:latest
command: bundle exec rake solid_queue:start
environment:
- DATABASE_URL=`${DATABASE_URL}
- SECRET_KEY_BASE=`${SECRET_KEY_BASE}
- ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY=`${ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY}
- ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY=`${ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY}
- ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT=`${ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT}
- AI_BASE_URL=`${AI_BASE_URL}
- AI_API_KEY=`${AI_API_KEY}
- LLM_MODEL=`${LLM_MODEL}
- LLM_TEMPERATURE=`${LLM_TEMPERATURE}
- LLM_MAX_TOKENS=`${LLM_MAX_TOKENS}
- LLM_TOP_P=`${LLM_TOP_P}
- EMBEDDING_MODEL=`${EMBEDDING_MODEL}
- EMBEDDING_DIMENSIONS=`${EMBEDDING_DIMENSIONS}
- CHUNK_SIZE=`${CHUNK_SIZE}
- CHUNK_OVERLAP=`${CHUNK_OVERLAP}
- RETRIEVAL_FETCH_K=`${RETRIEVAL_FETCH_K}
- GUARD_MODEL=`${GUARD_MODEL}
- AUGMENTED_CONTEXT=`${AUGMENTED_CONTEXT}
models:
- llm
- embedding
volumes:
- rails-storage:/rails/storage
depends_on:
postgres-db:
condition: service_healthy
web:
condition: service_healthy
restart: on-failure:5
models:
llm:
model: `${LLM_MODEL}
embedding:
model: `${EMBEDDING_MODEL}
volumes:
caddy-config:
caddy-data:
postgres-db-data:
rails-storage:
"@
$composeContent | Out-File -FilePath "docker-compose.yml" -Encoding utf8
}
# Setup environment file
function Setup-Env {
param(
[int]$system_ram,
[int]$gpu_vram
)
if (Test-Path ".env") {
Write-Host ".env file exists, checking for missing encryption keys..."
$envContent = Get-Content ".env" -Raw
# Add missing encryption keys
if ($envContent -notmatch "ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY=") {
Write-Host "Adding ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY..."
$envContent += "`n" + "# Active Record Encryption Keys (generated by install script)`n"
$envContent += "ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY=" + (Get-RandomHexString 32) + "`n"
}
if ($envContent -notmatch "ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY=") {
Write-Host "Adding ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY..."
$envContent += "ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY=" + (Get-RandomHexString 32) + "`n"
}
if ($envContent -notmatch "ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT=") {
Write-Host "Adding ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT..."
$envContent += "ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT=" + (Get-RandomHexString 32) + "`n"
}
$envContent | Out-File -FilePath ".env" -Encoding utf8 -Force
Write-Host "Encryption keys check complete."
return
}
Write-Host "Generating environment variables..."
# Set NOSIA_URL
$NOSIA_URL = $env:NOSIA_URL
if ([string]::IsNullOrEmpty($NOSIA_URL)) {
$NOSIA_URL = "https://nosia.localhost"
}
# Set AI_BASE_URL for Windows
$AI_BASE_URL = $env:AI_BASE_URL
if ([string]::IsNullOrEmpty($AI_BASE_URL)) {
$AI_BASE_URL = "http://model-runner.docker.internal/engines/llama.cpp/v1"
}
# Auto-select LLM model if not set
$LLM_MODEL = $env:LLM_MODEL
if ([string]::IsNullOrEmpty($LLM_MODEL)) {
Write-Host "Auto-selecting LLM model based on system resources..."
$llm_config = Select-LLMModel -gpu_vram $gpu_vram -system_ram $system_ram
$llm_parts = $llm_config -split '\|'
$LLM_MODEL = $llm_parts[0]
$LLM_MAX_TOKENS = $llm_parts[1]
$CHUNK_SIZE = $llm_parts[2]
$CHUNK_OVERLAP = $llm_parts[3]
Write-Host "Selected $LLM_MODEL"
}
# Auto-select embedding model if not set
$EMBEDDING_MODEL = $env:EMBEDDING_MODEL
if ([string]::IsNullOrEmpty($EMBEDDING_MODEL)) {
Write-Host "Auto-selecting embedding model..."
$embedding_config = Select-EmbeddingModel -gpu_vram $gpu_vram -system_ram $system_ram
$embedding_parts = $embedding_config -split '\|'
$EMBEDDING_MODEL = $embedding_parts[0]
$EMBEDDING_DIMENSIONS = $embedding_parts[1]
$CHUNK_SIZE = $embedding_parts[2]
$CHUNK_OVERLAP = $embedding_parts[3]
Write-Host "Selected $EMBEDDING_MODEL"
}
# Set embedding dimensions if not set but model is
if ([string]::IsNullOrEmpty($EMBEDDING_DIMENSIONS) -and -not [string]::IsNullOrEmpty($EMBEDDING_MODEL)) {
switch -Regex ($EMBEDDING_MODEL) {
"granite-embedding|278M" { $EMBEDDING_DIMENSIONS = 768 }
"qwen3-embedding|8B" { $EMBEDDING_DIMENSIONS = 4096 }
"384|384d" { $EMBEDDING_DIMENSIONS = 384 }
"768|768d" { $EMBEDDING_DIMENSIONS = 768 }
default { $EMBEDDING_DIMENSIONS = 768 }
}
}
# Generate secrets
$SECRET_KEY_BASE = Get-RandomHexString 64
$ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY = Get-RandomHexString 32
$ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY = Get-RandomHexString 32
$ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT = Get-RandomHexString 32
$POSTGRES_PASSWORD = Get-RandomHexString 32
# Database configuration
$POSTGRES_HOST = "postgres-db"
$POSTGRES_PORT = 5432
$POSTGRES_DB = "nosia_production"
$POSTGRES_USER = "nosia"
$AUGMENTED_CONTEXT = "true"
$envContent = @"
# Nosia Environment Configuration
# Application URL
NOSIA_URL=${NOSIA_URL}
# Allow user registration
REGISTRATION_ALLOWED=true
# Secret Key Base
SECRET_KEY_BASE=${SECRET_KEY_BASE}
# Active Record Encryption Keys
ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY=${ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY}
ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY=${ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY}
ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT=${ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT}
# AI Service Configuration
AI_BASE_URL=${AI_BASE_URL}
AI_API_KEY=${env:AI_API_KEY}
# LLM Model Configuration
LLM_MODEL=${LLM_MODEL}
LLM_TEMPERATURE=0.1
LLM_MAX_TOKENS=${LLM_MAX_TOKENS}
LLM_TOP_P=0.9
# Embedding Model Configuration
EMBEDDING_MODEL=${EMBEDDING_MODEL}
EMBEDDING_DIMENSIONS=${EMBEDDING_DIMENSIONS}
# Document Processing Configuration
CHUNK_SIZE=${CHUNK_SIZE}
CHUNK_OVERLAP=${CHUNK_OVERLAP}
RETRIEVAL_FETCH_K=3
# Optional: Guard Model
GUARD_MODEL=${env:GUARD_MODEL}
# Database Configuration
POSTGRES_HOST=${POSTGRES_HOST}
POSTGRES_PORT=${POSTGRES_PORT}
POSTGRES_DB=${POSTGRES_DB}
POSTGRES_USER=${POSTGRES_USER}
POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
# Optional: Augmented Context
AUGMENTED_CONTEXT=${AUGMENTED_CONTEXT}
"@
$envContent | Out-File -FilePath ".env" -Encoding utf8
Write-Host ".env file generated successfully."
}
# Helper function to generate random hex string
function Get-RandomHexString {
param([int]$length)
$bytes = New-Object byte[]($length)
$rng = [System.Security.Cryptography.RandomNumberGenerator]::Create()
$rng.GetBytes($bytes)
return [System.BitConverter]::ToString($bytes).Replace("-", "").ToLower()
}
# Setup Windows prerequisites
function Setup-Windows {
Write-Host "Setting up Windows prerequisites..."
# Check if Docker is installed
try {
$dockerVersion = docker --version
Write-Host "Docker is already installed: $dockerVersion"
return
} catch {
Write-Host "Docker is not installed."
}
Write-Host "Please install Docker Desktop from https://www.docker.com/products/docker-desktop/"
Write-Host "After installing Docker Desktop, restart your computer and run this script again."
exit 1
}
# Main installation
function Do-Install {
# Detect system resources
$resources = Detect-SystemResources
$SYSTEM_RAM_GB = $resources.SYSTEM_RAM_GB
$GPU_VRAM_GB = $resources.GPU_VRAM_GB
# Generate docker-compose.yml
Generate-DockerCompose
# Setup environment
Setup-Env -system_ram $SYSTEM_RAM_GB -gpu_vram $GPU_VRAM_GB
# Install prerequisites
Setup-Windows
# Pull latest files
Write-Host "Pulling latest Caddyfile..."
try {
Invoke-WebRequest -Uri "https://raw.githubusercontent.com/dilolabs/nosia/main/Caddyfile" -OutFile "Caddyfile"
Write-Host "Caddyfile pulled successfully."
} catch {
Write-Host "Warning: Could not download Caddyfile - $_"
}
Write-Host "Pulling latest Docker images..."
docker compose pull
Write-Host "Docker images pulled successfully."
Write-Host "Setup complete. Start with: docker compose up -d"
}
# Run installation
try {
Do-Install
} catch {
Write-Host "Error during installation: $_" -ForegroundColor Red
exit 1
}