# Hindsight

來源: https://docs.aicentos.com/zh-TW/clients/hindsight

Language: zh-TW

> 為 Hindsight 記憶服務設定 aicentos 的模型 —— 四個環境變數搞定，OpenAI 相容

Hindsight 是開源的 agent 記憶系統，提供自架服務、HTTP / MCP 介面、SDK 和 CLI。它自己不是聊天用戶端，但**記憶提煉要用一個 LLM**，那個 LLM 可以指向 aicentos。

## 準備工作

先在控制台為 Hindsight 建一個專用 Key（建議命名 `hindsight`）。

* 控制台：[https://aicentos.com](https://aicentos.com)
* 建立 Key：[https://aicentos.com/keys](https://aicentos.com/keys)
* 錢包儲值：[https://aicentos.com/wallet](https://aicentos.com/wallet)

Hindsight 伺服器端需要 PostgreSQL 14 及以上。它自帶的 `pg0` 只適合開發，生產環境請接自己的執行個體。

```bash
pip install hindsight-api
```

## 需要填寫的設定

| 環境變數                         | 值                         |
| ---------------------------- | ------------------------- |
| `HINDSIGHT_API_LLM_PROVIDER` | `openai`                  |
| `HINDSIGHT_API_LLM_BASE_URL` | `https://aicentos.com/v1` |
| `HINDSIGHT_API_LLM_API_KEY`  | 控制台建立的 Key                |
| `HINDSIGHT_API_LLM_MODEL`    | 控制台「模型廣場」中的模型名            |

## 設定步驟

寫進啟動環境即可，不需要改程式碼：

```bash
export HINDSIGHT_API_LLM_PROVIDER="openai"
export HINDSIGHT_API_LLM_BASE_URL="https://aicentos.com/v1"
export HINDSIGHT_API_LLM_API_KEY="sk-你的-API-Key"
export HINDSIGHT_API_LLM_MODEL="你的模型名"

hindsight-api
```

用 Docker 部署時把這些變數放進 compose 的 `environment`。注意官方映像檔不含 `llama.cpp`，別指望在容器裡跑本地模型。

## 測試

```bash
curl -fsSL https://hindsight.vectorize.io/get-cli | bash
hindsight health
```

服務起來後寫入一條記憶、再檢索回來，能走通說明 LLM 呼叫正常。也可以直接看控制台用量：Hindsight 每提煉一次記憶都會產生一條請求。

## 注意事項

* `BASE_URL` 必須以 `/v1` 結尾，且上游要能服務 `/chat/completions`；寫成 `https://aicentos.com` 會 404。
* 沒設定 LLM Key 時服務會拒絕啟動，這是它的強制校驗，不是 Key 填錯。
* 記憶提煉是背景批次處理，用量會隨記憶條數成長，建議給 Hindsight 單獨一個 Key 便於觀察。
* `HINDSIGHT_API_LLM_PROVIDER` 填 `openai` 表示走 OpenAI 相容協議，不是指只能用 OpenAI 模型。

## 相關連結

* [Hindsight 模型設定](https://hindsight.vectorize.io/developer/models)
* [hindsight 儲存庫](https://github.com/vectorize-io/hindsight)