-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-rag.ps1
More file actions
61 lines (51 loc) · 1.77 KB
/
run-rag.ps1
File metadata and controls
61 lines (51 loc) · 1.77 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
$ErrorActionPreference = "Stop"
$projectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $projectRoot
$containerName = "cocoindex-pg"
$dbUrl = "postgresql://cocoindex:cocoindex@localhost:5432/cocoindex"
if (-not (Get-Command docker -ErrorAction SilentlyContinue)) {
throw "Docker is not installed or not available in PATH."
}
$containerExists = docker ps -a --format "{{.Names}}" | Select-String -Pattern "^$containerName$" -Quiet
if (-not $containerExists) {
Write-Host "Creating pgvector container: $containerName"
docker run -d `
--name $containerName `
-e POSTGRES_USER=cocoindex `
-e POSTGRES_PASSWORD=cocoindex `
-e POSTGRES_DB=cocoindex `
-p 5432:5432 `
pgvector/pgvector:pg16 | Out-Null
}
else {
$isRunning = (docker inspect -f "{{.State.Running}}" $containerName).Trim()
if ($isRunning -ne "true") {
Write-Host "Starting existing container: $containerName"
docker start $containerName | Out-Null
}
}
Write-Host "Waiting for Postgres readiness..."
$ready = $false
for ($i = 0; $i -lt 30; $i++) {
$health = docker exec $containerName pg_isready -U cocoindex -d cocoindex 2>$null
if ($LASTEXITCODE -eq 0) {
$ready = $true
break
}
Start-Sleep -Seconds 1
}
if (-not $ready) {
throw "Postgres did not become ready in time."
}
$env:COCOINDEX_DATABASE_URL = $dbUrl
$cocoindexExe = Join-Path $env:APPDATA "Python\Python312\Scripts\cocoindex.exe"
if (Test-Path $cocoindexExe) {
& $cocoindexExe update -f cocoindex_rag.index_flow
}
else {
& cocoindex update -f cocoindex_rag.index_flow
}
Write-Host ""
Write-Host "RAG is ready."
Write-Host "MCP server config: .cursor/mcp.json"
Write-Host "If Cursor still shows red, restart MCP servers in Cursor."