docs(wiki): 添加 Ollama 配置文档和 AI 分析故障排除
Some checks failed
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / frontend-build (push) Has been cancelled
CI / security-audit (push) Has been cancelled

- infrastructure.md: 新增 Ollama 服务连接、环境变量、GPU 注意事项
- index.md: 症状导航新增 qwen3 thinking、Ollama 内存/安全、模板渲染等问题
This commit is contained in:
iven
2026-05-05 22:56:30 +08:00
parent b1a96ace1f
commit 4f84c94a42
2 changed files with 23 additions and 0 deletions

View File

@@ -55,6 +55,10 @@
| AI 分析 SSE 无 UI 入口 | [[erp-health]] AI 分析 | 前端未调用 | 4 个 SSE 端点无管理界面触发 |
| AI 分析返回对话式回复 | [[erp-ai]] prompt 模板 | 迁移 000123 | system_prompt 未加非对话指令 / 数据为空 |
| AI 分析结果显示原始 JSON | [[erp-ai]] 缓存回放 | `replay_cached` | 迁移 000123 前的嵌套 JSON bug前端 `extractPlainText` 兼容 |
| AI 分析输出全空SSE content="" | [[erp-ai]] qwen3 thinking | `strip_think_block` | qwen3 流式 API content 为空,改非流式 + 剥离 think 块 |
| Ollama 内存不足 `memory layout` | [[infrastructure]] Ollama 配置 | `OLLAMA_CONTEXT_LENGTH` | 默认 262144 导致 35GB KV cache设为 4096 |
| Ollama 暴露到局域网 | [[infrastructure]] Ollama 安全 | `OLLAMA_HOST` | 默认 `0.0.0.0`,必须设 `127.0.0.1` |
| AI 趋势/报告分析 500 模板渲染失败 | [[erp-ai]] Handlebars 模板 | `anomalies.length` | `.length` 不是有效 Handlebars 语法,改为 `{{#if anomalies}}` |
| AI 分析 400 缺少数据 | 后端预校验 | handler 层 | 化验报告 items 为空 / 趋势数据 metrics 为空 |
## 模块导航

View File

@@ -36,6 +36,7 @@ tags: [infrastructure, dev-environment, windows, postgresql]
| 后端 API | `http://localhost:3000/api/v1` | Axum 服务 |
| 前端 SPA | `http://localhost:5174` | Vite 开发服务器 |
| 微信小程序 | 微信开发者工具 | 患者端小程序(`apps/miniprogram/dist/` |
| Ollama | `http://127.0.0.1:11434` | 本地 AI 推理qwen3:4b |
### 登录凭据
@@ -63,6 +64,24 @@ psql: `D:\postgreSQL\bin\psql.exe -U postgres -h localhost -d erp`
> 开发环境 AES/HMAC 密钥生成: `python -c "import secrets; print(secrets.token_hex(32))"`
### Ollama 本地 AI 配置
启动脚本:`tmp/start-ollama.ps1`(必须用 `ollama serve` 而非 `ollama app`,否则环境变量不生效)
| 环境变量 | 值 | 说明 |
|----------|-----|------|
| `OLLAMA_HOST` | `http://127.0.0.1:11434` | 只监听本地(默认 `0.0.0.0` 暴露局域网) |
| `OLLAMA_CONTEXT_LENGTH` | `4096` | 4b 模型足够,默认 262144 会导致 35GB+ KV cache |
| `OLLAMA_MAX_LOADED_MODELS` | `1` | 开发环境只加载一个模型 |
| `OLLAMA_FLASH_ATTENTION` | `true` | RTX 3070 (Ampere) 支持,降低显存占用 |
| `OLLAMA_KEEP_ALIVE` | `10m` | 模型保留 10 分钟避免频繁重载 |
| `OLLAMA_ORIGINS` | `http://localhost:3000,http://localhost:5174` | CORS 限制 |
| `OLLAMA_NO_CLOUD` | `true` | 禁用云功能 |
> **GPU 注意事项:** 默认 `OLLAMA_CONTEXT_LENGTH=262144` 会使 KV cache 需要 35GB+ CPU 内存 + 1.8GB GPU 显存RTX 3070 8GB 无法加载。设为 4096 后模型可完全加载到 GPU~3GB 显存),推理速度正常。
> **qwen3 thinking 模式:** qwen3:4b 默认开启 thinking流式 API 中 `message.content` 为空(全部 token 消耗在 thinking 上)。`erp-ai` Ollama provider 对 qwen3 自动改用非流式 API + `strip_think_block` 剥离 `<think...` 块。
### 微信小程序配置
| 配置 | 位置 | 说明 |