#Requires -Version 5.1 <# .SYNOPSIS 新机器一键灌库:jinrong_agent(底座+Agent专用)→ jinrong_core(模拟库+归属同步)→ 可选 RAG 知识库 .EXAMPLE .\scripts\bootstrap.ps1 -MysqlPassword 123456 -SkipNeo4j .\scripts\bootstrap.ps1 -MysqlPassword 123456 -SkipNeo4j -WithKb # 连同 RAG 知识库一起灌入 .NOTES 前置依赖: 1. Python 3.12 + 项目依赖(pip install -r requirements.txt) 2. MySQL 8.x 本地运行,且 mysql CLI 在 PATH 中 3. Redis 8.x 本地运行(会话短期记忆) 4. Milvus(Lite 本地文件或 standalone)运行中 5. .env 已按 .env.example 配置(DEEPSEEK_API_KEY、KB_ROOT_DIR 等) 灌库完成后:agent 库 18 张表(底座 11 + Agent 专用 7),core 模拟库种子数据为相对跑库日日期。 #> param( [string]$MysqlUser = "root", [string]$MysqlHost = "127.0.0.1", [string]$MysqlPassword = "", [switch]$SkipNeo4j, [switch]$WithKb ) $ErrorActionPreference = "Stop" $Root = Split-Path $PSScriptRoot -Parent Set-Location $Root # 密码经 MYSQL_PWD 环境变量传递:Python 脚本与 mysql CLI 共用,避免命令行明文 if ($MysqlPassword -ne "") { $env:MYSQL_PWD = $MysqlPassword } if (-not $env:MYSQL_PWD) { Write-Error "缺少密码:请用 -MysqlPassword 传参,或预设 MYSQL_PWD 环境变量" exit 1 } # --- 前置检查 ------------------------------------------------------------- Write-Host "=== 前置检查 ===" -ForegroundColor Cyan foreach ($cmd in @("python", "mysql")) { if (-not (Get-Command $cmd -ErrorAction SilentlyContinue)) { Write-Error "未找到命令 '$cmd',请先安装并加入 PATH" exit 1 } } if (-not (Test-Path (Join-Path $Root ".env"))) { Write-Host "[WARN] 未找到 .env,请复制 .env.example 为 .env 并填写 DEEPSEEK_API_KEY 等配置" -ForegroundColor Yellow } Write-Host "python / mysql 均可用" -ForegroundColor Green # --- 步骤 1:jinrong_agent(01 底座 11 张 + 02 Agent 专用 7 张)----------- Write-Host "`n=== [1/3] 初始化 jinrong_agent(底座 + Agent 专用表)===" -ForegroundColor Cyan python scripts/init_agent_db.py --mysql-host $MysqlHost --mysql-user $MysqlUser if ($LASTEXITCODE -ne 0) { Write-Error "agent 库初始化失败" } # --- 步骤 2:jinrong_core 模拟库(DROP 重建 + 种子 + 归属同步)------------ Write-Host "`n=== [2/3] 重建 jinrong_core 模拟库并同步归属 ===" -ForegroundColor Cyan $resetArgs = @("-MysqlPassword", $MysqlPassword, "-MysqlHost", $MysqlHost, "-MysqlUser", $MysqlUser) if ($SkipNeo4j) { $resetArgs += "-SkipNeo4j" } & powershell -ExecutionPolicy Bypass -File (Join-Path $Root "scripts/core/reset.ps1") @resetArgs if ($LASTEXITCODE -ne 0) { Write-Error "core 模拟库重建失败" } # --- 步骤 3(可选):RAG 知识库灌入 Milvus -------------------------------- if ($WithKb) { Write-Host "`n=== [3/3] RAG 知识库灌入 Milvus ===" -ForegroundColor Cyan & powershell -ExecutionPolicy Bypass -File (Join-Path $Root "scripts/kb/reset.ps1") -Rebuild if ($LASTEXITCODE -ne 0) { Write-Host "[WARN] 知识库灌入失败,请检查 Milvus / DEEPSEEK_API_KEY / KB_ROOT_DIR" -ForegroundColor Yellow } } else { Write-Host "`n=== [3/3] 跳过 RAG 知识库(如需灌入加 -WithKb;需自备知识库源文档并配置 KB_ROOT_DIR)===" -ForegroundColor DarkGray } Write-Host "`n=== 全部完成 ===" -ForegroundColor Green Write-Host "后续:确认 Redis 8.x 与 Milvus 已启动,.env 配置就绪后即可启动服务(uvicorn app.main:app --reload)" -ForegroundColor Green