Commit Graph
9 Commits
Author SHA1 Message Date
poimenandrock 4169effd8a feat: complete observability stack (O1-O13) (#52)
CI / CI (push) Successful in 12m36s
Deploy / Tag & Push Latest (push) Successful in 1m56s
## Complete Observability Stack (O1-O13)

Implements all 13 observability issues in a single PR. 119 metrics total.

### Commits (one per issue)

| Issue | Title | Metrics |
|-------|-------|---------|
| **O10** | Prometheus metrics module + /metrics endpoint | Foundation |
| **O1** | Instrument ingest handler | I1-I12 (12) |
| **O2** | Instrument query handler | Q1-Q12 (12) |
| **O3** | Instrument context endpoint | C1-C8 (8) |
| **O4** | Relevance judge | R1-R9 (9) |
| **O5** | Write volume + storage metrics | W1-W12 (12) |
| **O6** | Pod resource observability | P1-P13 |
| **O7** | Availability + dependency health | A1-A10 (10) |
| **O8** | Ingest rate pattern tracking | IR1-IR10 (10) |
| **O9** | Postgres internal observability | PG1-PG33 |
| **O11** | Grafana dashboard | 12 panels |
| **O12** | Prometheus alerting rules | 11 alerts |
| **O13** | Relevance evaluation CronJob | K8s manifest |

### Key Changes

- **metrics.rs**: Zero-dependency Prometheus metrics (Counter, Gauge, Histogram, Timer)
- **GET /metrics**: Prometheus text exposition format endpoint
- **Ingest/Query/Context handlers**: Instrumented with latency, errors, auth failures
- **Health check**: DB dependency check with latency tracking
- **Background task**: Periodic DB stats collection (entity/edge counts, pool stats)
- **Relevance judge**: Threshold-based eval with precision/recall/F1 tracking
- **Grafana dashboard**: 12 panels covering all metric groups
- **Alert rules**: 11 PrometheusRule alerts (availability, latency, errors, quality)
- **CronJob**: Periodic relevance evaluation with sample queries

### Testing

- 506 tests passing (0 failures)
- All metrics modules have unit tests
- Relevance judge: 4 tests

### Deploy

```bash
# Grafana dashboard
kubectl apply -f k8s/infra/grafana-dashboard.json

# Prometheus alerts
kubectl apply -f k8s/infra/prometheus-alerts.yaml

# Relevance eval CronJob
kubectl apply -f k8s/infra/relevance-eval-cronjob.yaml
```

Closes #27 #28 #29 #30 #31 #32 #33 #34 #35 #36 #37 #38 #39

---------

Co-authored-by: rock <[email protected]>
Reviewed-on: #52
Co-authored-by: poimen <[email protected]>
2026-09-13 13:53:50 +00:00
rock 96ae855d35 fix: default auth to Bearer token (riotpiao gateway uses JWT now) 2026-08-30 18:02:25 -07:00
rock 343a4f224f feat: multi-provider auth for ChatClient (OpenRouter, OpenAI, Ollama)
Auto-detect auth mode from base URL:
- openrouter.ai, api.openai.com → Bearer token
- api.riotpiao.com → apikey header
- localhost → no auth
Explicit override via with_auth_mode()
2026-08-30 17:58:27 -07:00
rock b43baf8147 feat: Configurable embeddings models via EMBEDDINGS_MODEL env var
Allow customers to choose embedding model without schema changes.

All models standardized to 768-dim (matching pgvector schema):
- nomic-ai/nomic-embed-text-v2-moe (default, fast, multilingual)
- nomic-ai/nomic-embed-text-v1.5 (slower but better quality)
- all-MiniLM-L6-v2 (very fast, English-only)
- BAAI/bge-small-en-v1.5 (fast retrieval)
- BAAI/bge-base-en-v1.5 (best English quality)

Changes:
- EmbeddingsClient::from_env() reads EMBEDDINGS_MODEL env var
- New validate_model() checks model is supported and 768-compatible
- New model_name() getter for logging
- Startup validation prevents unsupported models

Configuration:
  EMBEDDINGS_MODEL=nomic-ai/nomic-embed-text-v1.5
  LLM_API_BASE=https://api.riotpiao.com
  LLM_API_KEY=<optional>

Documentation:
- docs/EMBEDDINGS_MODELS.md (performance comparison, troubleshooting)
- Kubernetes example for switching models
- Migration guide for re-embedding existing chunks
- Custom model integration instructions

Performance impact:
- Default (v2-moe): ~200 texts/sec
- Fast (all-MiniLM): ~330 texts/sec
- Quality (bge-base): ~165 texts/sec
2026-08-28 13:16:52 -07:00
Story Crater Bot e83b8ef3da feat: Implement M2.1 Embeddings client (768-dim batching @32)
M2.1 Complete: TEI embeddings via api.riotpiao.com gateway

Implementation (crates/mem-llm/src/embeddings.rs):
- EmbeddingsClient::embed(texts) batches at ≤32 per request
- Preserves input order across batch boundaries
- Asserts 768-dim vectors, errors loudly with model name on mismatch
- Sends apikey header (future-proofing for auth plugin enablement)
- 30s timeout, retry on 5xx via reqwest Client
- Constants: EMBEDDINGS_DIM=768, BATCH_SIZE=32 (single source for schema migration)

Tests (tests/it_embeddings.rs): 8 tests
1. a1_batches_at_32 — 100 inputs → 4 requests (32+32+32+4)
2. a2_order_preserved — identifiable vectors, cross-batch order assertion
3. a3_dimension_asserted — 512-dim response → error naming model & dimensions
4. a4_apikey_sent — header present even when route doesn't require auth
5. a5_live_dims — #[ignore] live gateway test (768-dim confirmation)
6. test_empty_input — empty batch → empty output
7. test_batch_boundary_32 — exact 32 inputs = 1 batch
8. test_batch_boundary_33 — 33 inputs = 2 batches (32+1)

All tests pass locally. Builds cleanly:

Updated INDEX.md:
- Added M2.x row to progress table (6/8 , 2 )
- Updated total: 73 tasks, 48 + 2🟡 + 23 (was 65 tasks)
- Updated gate count: 6/11 green (was 5/10)
- Test count: 247 passing, 2 ignored (was 239)

Blocks: M1.1  (already complete, unblocked)
2026-08-27 20:36:57 -07:00
rock af6f22217d feat(core): implement full memory pipeline (#11) 2026-08-24 01:37:16 +00:00
Story Crater Bot 54d1879464 Fix LLM gateway path, update M1.8 gate test to load real chunks (Option B) 2026-08-23 00:32:27 -07:00
Story Crater Bot 695e115212 Deploy Poimen Memory K8s cluster with ArgoCD tracking (M2.2, M3.5-M3.7) 2026-08-22 23:13:42 -07:00
Story Crater Bot 33b7150f56 feat: complete M0.1-M0.4 phases
M0.1 - Cargo workspace + crate skeletons
  - 6-crate workspace with correct dependency direction
  - CI/CD pipeline with GitHub Actions
  - Integration tests verifying build and dependency structure

M0.2 - Domain types and sha256 identity
  - Level (L0, L1, L2) enum with proper serde formatting
  - Role enum (User, Assistant, ToolResult, System)
  - Record, Chunk, and MemoryNode domain types
  - Content-hash identity system ensuring rebuild idempotence
  - Newtypes (ProjectId, QueryId, RunId) with validation
  - Round-trip serde tests for all types

M0.3 - RecordSource trait + ChunkPolicy
  - RecordSource trait for streaming record sources
  - Chunk policy with token budgets and boundary modes
  - TokenCounter trait with CharsOverFourCounter stub
  - Chunking stream that respects budgets without splitting records
  - VecSource for testing
  - Integration tests verifying lossless chunking and budget adherence

M0.4 - Tokenizer-backed chunk sizing
  - Vendored Qwen2 tokenizer with hash verification
  - QwenTokenCounter implementing proper token counting
  - Hash guard that fails on modified tokenizer
  - mem tokens CLI subcommand for token counting
  - Integration tests with known string counts, hash guards, and budget verification

Total: 19 integration tests passing, all phases verified to compose correctly
Workspace builds cleanly with no clippy warnings
2026-08-22 23:13:42 -07:00