Capstone 3: Build a Governed PostgreSQL RAG Assistant
Build the complete AI-native layer for SignalDesk: versioned documents, ACLs, staged ingestion, full-text and pgvector retrieval, rank fusion, citations, scoped memory, a safe ticket-summary tool, human approval for sending replies, evaluation datasets, traces, budgets, fallback, re-embedding migration, deletion propagation, restore, and adversarial tenant testing.
What will you be able to do?
- Operate a RAG pipeline as a governed data product.
- Measure retrieval, generation, authorization, latency, and cost separately.
- Expose bounded semantic tools with approval and idempotency.
- Rebuild and recover AI projections from canonical truth.
Prerequisites and mental model
Complete the whole book and Capstone 2. The deliverable is not a chatbot UI. It is evidence that an authorized question receives supported context and a safe answer under normal, stale, malicious, failure, and recovery conditions.
Required system
- Immutable document versions, ACLs, checksums, and staged states.
- Idempotent parse/chunk/embed jobs with exact citation coordinates.
- pgvector exact baseline and evaluated approximate index where justified.
- PostgreSQL full-text retrieval and versioned fusion/rerank settings.
- Policy-before-ranking tenant/group/document authorization.
- Bounded context, no-answer behavior, and claim-support citations.
- Scoped conversation memory with retention and deletion.
- Semantic summarize_ticket read tool and send_reply proposal/approval/execution.
- Thirty-plus evaluation cases covering exact, semantic, stale, unauthorized, malicious, and no-answer inputs.
- Stage traces, SLOs, cost units, drift monitoring, canary rollout, and rollback.
- Embedding-model migration with dual versions.
- Restore canonical state, rebuild derived data, and prove recovery time.
Adversarial tests
- document prompt injection asks for another tenant;
- user asks to reveal system/catalog secrets;
- revoked document remains in cache;
- approximate index returns too few filtered candidates;
- model invents citation or tool parameter;
- approval is replayed after ticket changes;
- embedding provider fails halfway;
- model is unavailable while ticket operations continue;
- deletion request removes source, chunks, embeddings, memory, cache, and governed traces.
Prove it worked: rubric
Authorization is never averaged into a quality score.
Common mistakes
- Great demo, no dataset: no reproducible quality → version cases and baselines.
- RAG uses latest rows blindly: publication/version state ignored → retrieve active validated versions.
- Model can send directly: proposal and authority conflated → approval state machine.
AI Pair-Programmer Prompt
Hands-on exercise
Run the full adversarial suite against a candidate release and compare it to the baseline.
Acceptance criterion: all hard gates pass, quality improvements are measured with variance, and rollback is demonstrated.
Knowledge check
- What is the first hard gate?
- Why keep exact vector search?
- What should recovery rebuild rather than restore as truth?
Answers
- Authorization/isolation with zero leakage.
- It provides an approximate-recall baseline and diagnostic truth.
- Chunks/search vectors/embeddings and other derived projections, from canonical sources and lineage.
Completion checklist
Primary references