Files
ewoooc/docs/adr/ADR-002-pgvector-as-sole-km-store.md
ogt 1b4f3a7bbe
Some checks failed
CD Pipeline / deploy (push) Failing after 59s
feat: EwoooC 初始化 — 完整專案推版至 Gitea
- 建立 Gitea Actions CD pipeline (.gitea/workflows/cd.yaml)
- 部署模式: rsync Python 檔案至 188 → docker restart (volume mount)
- Dockerfile/requirements 變動時自動重建 Docker image
- 部署通知: Telegram (開始/成功/失敗)
- 健康檢查: https://mo.wooo.work/health (最多 5 次重試)
- 同步最新 CLAUDE.md / ADR-008 / memory (2026-04-19)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-19 01:21:13 +08:00

69 lines
2.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ADR-002pgvector 作為唯一 KM 向量庫
- **Status**: Accepted
- **Date**: 2026-04-18
- **Decision Maker**: 統帥
- **Author**: Claude
## Context
KM知識管理需要向量化檢索能力來支援 RAGRetrieval-Augmented Generation。市面選項pgvector、ChromaDB、Qdrant、Weaviate、Milvus。
現況MOMO Pro 已使用 PostgreSQL且生產環境的 PG 實例192.168.0.188)映像為 `pgvector/pgvector:pg14` —— 即 pgvector 擴充已內建。
## Decision
**KM 唯一向量庫 = pgvector**。禁用任何其他向量資料庫ChromaDB、Qdrant、Weaviate、Milvus
## Alternatives Considered
| 方案 | 拒絕原因 |
|---|---|
| ChromaDB輕量獨立 | 必須在兩個 DB 之間 JOIN「結構化篩選 + 語意檢索」要兩階段,痛苦 |
| Qdrant性能最好 | 需獨立部署、運維成本、與現有 PG 切割記憶 |
| Weaviate / Milvus | 過度工程化,超出當前需求量 |
## Consequences
### Positive
- **零部署**pgvector 已在 192.168.0.188 PG 實例上運行
- **零維運**:沿用既有備份/監控/擴容機制
- **單條 SQL** 同時做語意檢索 + 結構化篩選:
```sql
SELECT insight_text, generated_at, ai_model
FROM ai_insights
WHERE insight_type = 'monthly'
AND created_at > NOW() - INTERVAL '90 days'
AND status = 'approved'
ORDER BY embedding <-> :query_vector
LIMIT 5;
```
- **事務一致性**:洞察寫入 + embedding 寫入同一 transaction原子性
### Negative / Trade-offs
- pgvector 在百萬向量量級時HNSW 索引需要調優IVFFlat or HNSW
- 與專業向量庫相比cluster 化方案較少(但短中期不需要)
## Implementation Notes
```sql
-- 1. 確認擴充
CREATE EXTENSION IF NOT EXISTS vector;
-- 2. ai_insights 表加 embedding 欄
ALTER TABLE ai_insights
ADD COLUMN embedding vector(1024); -- bge-m3 維度(見 ADR-003
-- 3. HNSW 索引v0.5.0+
CREATE INDEX ON ai_insights
USING hnsw (embedding vector_cosine_ops)
WITH (m = 16, ef_construction = 64);
```
## Related ADRs
- ADR-001三 Agent 分工
- ADR-003embedding 模型選型決定向量維度