memoryweave/Makefile

153 lines
6.1 KiB
Makefile

# 织忆 MemoryWeave — Makefile
# Go daemon (zhiyid) + Rust sidecar (zhiyi-consolidate)
.PHONY: all build test bench eval deploy clean
# ─── 变量 ────────────────────────────────────────────
GO_CMD := go
RUST_CMD := cargo
GO_DIR := go
RUST_DIR := rust
BINARY_GO := $(GO_DIR)/cmd/zhiyid/zhiyid
BINARY_RUST := $(RUST_DIR)/target/release/zhiyi-consolidate
# ─── 构建 ────────────────────────────────────────────
all: build-go build-rust
build-go:
cd $(GO_DIR) && CGO_ENABLED=1 $(GO_CMD) build -o cmd/zhiyid/zhiyid ./cmd/zhiyid
build-rust:
cd $(RUST_DIR) && $(RUST_CMD) build --release
build: build-go ## 只构建 Go (Rust 需单独 build-rust)
# ─── Obsidian 插件 ────────────────────────────────────
OBSIDIAN_PLUGIN := plugins/obsidian
OBSIDIAN_DEST := $(HOME)/.obsidian/plugins/zhiyi-memory
build-obsidian:
cd $(OBSIDIAN_PLUGIN) && node esbuild.config.mjs
install-obsidian: build-obsidian
cp $(OBSIDIAN_PLUGIN)/main.js $(OBSIDIAN_DEST)/
cp $(OBSIDIAN_PLUGIN)/manifest.json $(OBSIDIAN_DEST)/
cp $(OBSIDIAN_PLUGIN)/styles.css $(OBSIDIAN_DEST)/
# ─── 测试 ────────────────────────────────────────────
test:
cd $(GO_DIR) && $(GO_CMD) test ./... -v -count=1
test-go: test
test-rust:
cd $(RUST_DIR) && $(RUST_CMD) test
# ─── 性能基准 ────────────────────────────────────────
bench:
cd $(GO_DIR) && $(GO_CMD) test ./internal/storage -bench=. -benchmem -count=3
# ─── 评估 ────────────────────────────────────────────
eval:
@echo "=== 织忆评估链路 ==="
@curl -s -X POST http://localhost:7821/api/v1/eval/generate \
-H "Content-Type: application/json" \
-H "X-API-Key: $$API_KEY" \
-d '{"namespace":"shared","count":12}' | jq '.count'
@echo "---"
@curl -s -X POST http://localhost:7821/api/v1/eval/run \
-H "Content-Type: application/json" \
-H "X-API-Key: $$API_KEY" \
-d '{"queries":[]}' | jq '{recall_at_5,precision_at_5,mean_reciprocal_rank}'
# ─── CI/CD 自动评估 ──────────────────────────────────
ci-eval:
@echo "--- CI/CD 自动评估 ---"
@TIMESTAMP=$$(date -Iseconds); \
RESULT=$$(curl -s -X POST http://localhost:7821/api/v1/eval/run \
-H "Content-Type: application/json" \
-H "X-API-Key: $$API_KEY" \
-d '{"queries":[]}'); \
RECALL=$$(echo $$RESULT | jq -r '.recall_at_5 // 0'); \
echo "$$TIMESTAMP | recall@5=$$RECALL"; \
PREV=$$(curl -s http://localhost:7821/api/v1/eval/history \
-H "X-API-Key: $$API_KEY" | jq -r '.trend // "first_run"'); \
echo "Trend: $$PREV"; \
if [ "$$PREV" = "degrading" ]; then \
echo "⚠️ ALERT: Eval degradation detected!"; \
exit 1; \
fi
# ─── 部署 ────────────────────────────────────────────
deploy: build-go
sudo cp $(BINARY_GO) /usr/local/bin/zhiyid
sudo cp deploy/zhiyid.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl restart zhiyid
deploy-rust: build-rust
sudo cp $(BINARY_RUST) /usr/local/bin/zhiyi-consolidate
sudo cp deploy/zhiyi-consolidate.service /etc/systemd/system/
sudo cp deploy/zhiyi-consolidate.timer /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now zhiyi-consolidate.timer
deploy-nginx:
sudo cp deploy/nginx-zhiyi.conf /etc/nginx/sites-enabled/zhiyi.conf
sudo nginx -t && sudo systemctl reload nginx
deploy-prometheus:
sudo cp deploy/prometheus-alerts.yml /etc/prometheus/rules/zhiyi.yml
sudo systemctl reload prometheus
# ─── 健康检查 ────────────────────────────────────────
health:
@curl -sf http://localhost:7821/health > /dev/null && echo "✅ zhiyid: OK" || echo "❌ zhiyid: DOWN"
@curl -sf http://localhost:8000/v1/embeddings -H "Content-Type: application/json" -d '{"input":["test"]}' > /dev/null 2>&1 && echo "✅ BGE-M3 ONNX: OK" || echo "⚠️ BGE-M3 ONNX: NOT REACHABLE"
@redis-cli PING > /dev/null 2>&1 && echo "✅ Redis: OK" || echo "⚠️ Redis: NOT REACHABLE"
@curl -sf http://localhost:7821/api/v1/stats -H "X-API-Key: $$API_KEY" | jq '{total_memories,total_episodes}'
# ─── 清理 ────────────────────────────────────────────
clean:
cd $(GO_DIR) && $(GO_CMD) clean
cd $(RUST_DIR) && $(RUST_CMD) clean
# ─── 迁移 ────────────────────────────────────────────
migrate:
cd $(GO_DIR) && $(GO_CMD) run ../scripts/migrate_faiss_to_lance.go \
--faiss-path ~/projects/zhiyi/memory_faiss.index \
--metadata-path ~/projects/zhiyi/memory_metadata.json \
--target sqlite \
--db-path /var/lib/memoryweave/memoryweave.db
migrate-dry-run:
cd $(GO_DIR) && $(GO_CMD) run ../scripts/migrate_faiss_to_lance.go \
--faiss-path ~/projects/zhiyi/memory_faiss.index \
--metadata-path ~/projects/zhiyi/memory_metadata.json \
--dry-run
# ─── 帮助 ────────────────────────────────────────────
help:
@echo "织忆 MemoryWeave — Build & Deploy"
@echo ""
@echo "Usage:"
@echo " make build 构建 Go daemon"
@echo " make build-rust 构建 Rust sidecar"
@echo " make test 运行测试"
@echo " make bench 性能基准"
@echo " make eval 运行评估"
@echo " make ci-eval CI/CD 自动评估 (含退化检测)"
@echo " make health 健康检查"
@echo " make deploy 部署 Go daemon"
@echo " make clean 清理"