Enterprise RAG
Release Gates for Enterprise RAG: When a Better Score Ships a Worse System
A RAG release is safe only when retrieval, figures, schema, grounding and isolation each pass on their own. Five suites, never averaged, and a skipped check counts as a failure.
Most RAG teams decide a release on one golden set and a few aggregate scores. If nDCG rises and nothing turns red, the release ships. I think this is where regulated firms carry the most unexamined risk. The score that improved usually measures ranking. The defects that reach a client sit in section coverage, in figures, in the schema and in access control, and an aggregate ranking score sees none of them.
A production RAG system answers through mechanisms that fail independently: a ranked document path, a SQL path for figures, the schema beneath it, the model that writes the answer, and the authorization layer around all of them. The release gate I describe in my book gives each of them its own suite and its own verdict. Quality metrics are compared with an absolute floor and with the last release, security probes must pass without exception, the verdicts are never averaged, and a suite that did not run blocks the release in the same way as a suite that failed.
In the reference case, the best ranking score of the program shipped two failures
The reference case in my book is AegisFin Corp, a fictional regulated M&A advisory and wealth management firm. Every figure in this article comes from that case and its tested reference code, and none from a client engagement. One release carried two changes, and CI passed on both. The retrieval team had fine-tuned the reranker on 6,000 analyst click pairs, which lifted golden-set nDCG@10 to the best score of the program, and a finance pull request pointed a semantic model at a new dbt view.
The reranker had learned that leverage questions are answered by one article of the credit agreement. The equity-cure section fell to rank 10, and the assistant told an analyst that the agreement contained no equity cure. The new view was owned by a role with BYPASSRLS. By default, PostgreSQL applies the row-level security policies of a view’s owner to every query through that view. The security_invoker option, available since PostgreSQL 15, switches to the caller’s policies, and an owner with BYPASSRLS is exempt from all of them. Every query through the view therefore returned every tenant’s rows. The metric it fed had no ledger control total, so the Balance Guard described in Dual-path RAG had nothing to reconcile it against. The tests written to catch this never ran. The CI runner image had no PostgreSQL server binaries, so the row-level security suites skipped themselves and the test run reported zero failures.
| Signal | What CI reported | What was true |
|---|---|---|
| Golden-set nDCG@10 | 0.71 to 0.78 | Ranking improved on average |
| Cross-Section Recall@5, 118 multi-section questions | Not measured | Fell from 0.83 to 0.47 in an offline replay |
| Row-level security suites | Zero failures | Skipped |
| Closed-EV answers over 31 hours | No ledger control on that metric | 9 of 23 carried out-of-scope rows |
Source: AegisFin Corp reference case (fictional), Production-Grade Enterprise RAG Architecture, Vol. 1.
Deal counsel corrected the false answer the same afternoon, before the sponsor call. The leaked rows took longer to contain and led to legal counsel, a client notification and an information-barrier review. The pipeline lacked three measurements, and its gate treated a missing measurement as a pass.
Retrieval needs metrics that see document structure
nDCG, MRR and Recall@k reward putting relevant chunks near the top. None of them tells you whether a question that depends on two sections of a contract retrieved both. The book defines two structural metrics for that gap, using the section key each chunk already carries from parsing. SecCov@k is the share of a question’s required sections present in the top k. CS Recall@k scores a multi-section question 1 when every required section is present and 0 otherwise. Neither is a standard information-retrieval metric, so a team adopting them should publish the definitions with the scores.
| Metric | Before tuning | After tuning |
|---|---|---|
| nDCG@10 | 0.79 | 0.91 |
| Recall@5 | 0.33 | 0.56 |
| MRR | 1.0 | 1.0 |
| SecCov@5 | 1.0 | 0.67 |
| CS Recall@5 | 1 | 0 |
Source: AegisFin Corp reference case (fictional), Production-Grade Enterprise RAG Architecture, Vol. 1.
I keep the ranking metrics in the gate because a release can degrade ranking across the board, and the structural metrics would miss that. When the book replays this release through the gate, no ranking metric falls, and the structural metrics block it on their own. The price is labelling the required sections of every golden question, which took two analyst-days for 118 questions in the reference case. On a corpus of single-section FAQ answers, those labels would add little.
Figures are tested against rows a controller froze
The usual test for a text-to-SQL path executes a gold query and compares results. The book’s replay of the incident shows the weakness: with gold rows produced through the same leaky view, the broken layer agreed with itself and scored an execution accuracy of 1.0. Against rows a finance controller had frozen for each synthetic user, the same answers scored 0.5.
The held-out suite compares each answer with the frozen rows as a multiset of Decimal values, to the cent. A float fails, and so does an answer to a question where the system should have abstained. Controllers own the cases in a repository the planner team cannot read, and the harness rejects any case that also appears in the planner’s few-shot examples or in the calibration set of the schema retrieval step. Execution accuracy has a floor of 0.95 and no allowed drop from the last release. Re-certifying the frozen rows when the staging ledger changes costs the controllers about a day per quarter.
Schema changes get their own check, which runs in about 90 seconds. The drift hook restores the production schema into an ephemeral PostgreSQL, applies the pull request’s Flyway and dbt changes, and requires every relation that exposes tenant_id, directly or through a view, to enforce the caller’s scope. Replayed on the incident view, it returns BLOCK. With security_invoker = true set on the view, it returns REINDEX: the change is safe, and the schema index the SQL planner reads must be rebuilt.
Graded quality is gated as a rate, and security is asserted in code
Context relevance, groundedness and answer relevance, the “RAG triad” introduced by TruEra, are scored in Promptfoo with its context-relevance, context-faithfulness and answer-relevance assertions, using one fixed grader model at temperature 0. I do not treat any model grader as repeatable row by row, so the gate reads these scores as rates against a floor and a regression margin. Groundedness has the tightest pair: a floor of 0.97 and a maximum drop of 0.01.
Groundedness covers a gap the citation guard leaves open. The guard, which Dual-path RAG describes, checks that every sentence cites a valid source and that every number in the sentence matches that source. It cannot tell whether the source says what the sentence says. The false “no equity cure” sentence had a valid citation and contained no number, so the guard released it, and only a graded groundedness check could have flagged it.
Isolation, canary and injection probes are code assertions over the structured response, and a single failure blocks the release. I would not let tenant isolation depend on a grader’s judgment, however well calibrated. A generated red team runs nightly, outside pull requests, and each confirmed finding becomes a fixed probe. The isolation suite also needs at least 50 probes; below that count it blocks even with no failures, so deleting probes cannot turn the suite green.
One gate reads every pillar of evidence and never averages them
Each suite writes its evidence as one file per pillar. The reference implementation has seven pillars: ranking, structure, SQL, schema drift, the graded triad, isolation, and the 23-item go-live checklist. The five suites produce six of them, because the retrieval suite reports ranking and structure separately. The seventh comes from the ordinary unit-test job, which counts a checklist item only when that item’s tests ran and passed on the commit being released. The gate blocks when a pillar is missing, reported twice, measured on another commit, or reports a failure. It then checks every metric against an absolute floor and against the last released baseline.
Source: Author's diagram of the release gate in Production-Grade Enterprise RAG Architecture, Vol. 1.
Floors and margins live in one policy file. An excerpt from the reference implementation:
metrics:
structure:
sec_cov_k: {min: 0.85, max_drop: 0.02}
cs_recall_k: {min: 0.80, max_drop: 0.02}
sql:
execution_accuracy: {min: 0.95, max_drop: 0.0}
triad:
groundedness: {min: 0.97, max_drop: 0.01}
isolation:
cases: {min: 50}
The CTO owns the quality floors and the CISO the zero-tolerance pillars, and a change to the file needs both approvals in CODEOWNERS.
The wiring in GitHub Actions has one trap. Branch protection requires a single status check, release-gate, which depends on every suite job through needs. When a suite fails, the dependent job is skipped by default, and GitHub documents that a skipped job reports its status as Success and will not prevent a merge, even when it is a required check. The gate job therefore runs with if: always(), and its first step fails unless every job it depends on succeeded:
release-gate:
needs: [unit, retrieval, sql-heldout, schema-drift,
promptfoo]
if: always()
steps:
- name: Every suite must have run and succeeded
run: |
echo '${{ toJSON(needs) }}' \
| jq -e 'all(.[]; .result == "success")'
A dependency can end as success, failure, cancelled or skipped. Only the first lets the gate go on to read the evidence.
| Suite | CI time | Main cost driver |
|---|---|---|
| Structural retrieval | 6 min | Section labels for 118 questions |
| Held-out SQL | 4 min | Controller hours each quarter |
| Schema drift hook | 90 s | Ephemeral PostgreSQL |
| Graded triad | 7 min | About $4 of grader tokens per run |
| Isolation probes | 3 min | Staging gateway |
| Generated red team | 45 min, nightly | Kept off pull requests |
Source: AegisFin Corp reference case (fictional), Production-Grade Enterprise RAG Architecture, Vol. 1.
With the suites running in parallel, a pull request in the reference case waits about 14 minutes instead of 6. Every suite runs against staging on a synthetic two-tenant corpus, so the grader never sees client data.
In production, invariants page on the first event
The book’s next incident shipped with all 23 go-live checks green. A refactor of the purge job had moved an index-epoch bump ahead of the re-count that verifies a purge. Counsel then revoked a privileged memo while a vector-store replica was still recovering. The purge failed verification, retried every minute and bumped the epoch on each attempt, and each bump invalidated the retrieval cache. Degraded answers rose from 0.6% to 31%, and the verified purge took 4 hours and 12 minutes against a 15-minute objective.
The dashboards stayed green. A degraded answer is still an HTTP 200, so the error rate read 0.2%, and document time-to-first-token p95 peaked at 2,482 ms, under its 2,500 ms objective. A user raised the alarm. By then the revoked memo had been cited in three answers, and the firm needed an outside-counsel privilege review.
The fix splits signals into two classes. Invariants have no error budget and page on the first event: a revocation still unpurged after 15 minutes, an epoch bump that no writer explains, a synthetic probe that sees another tenant’s canary. Quality signals spend a budget and alert on burn rate: the bad share over a window divided by the error budget, so a burn of 1 spends the budget exactly over the SLO period. The book adopts the multiwindow pairs that the Google SRE Workbook recommends as a starting point. A burn of 14.4 times over one hour and five minutes pages, 6 times over six hours and 30 minutes pages, and 1 time over three days and six hours opens a ticket. Both windows of a pair must reach the factor. With the reference case’s 2% budget for degraded answers, the fastest pair pages once the degraded share reaches 14.4 × 2% = 28.8% over both the last hour and the last five minutes.
Source: Author's diagram of the operating model in Production-Grade Enterprise RAG Architecture, Vol. 1.
| Time | Signal | Route |
|---|---|---|
| 09:02 | Memo revoked; purge starts failing | None |
| 09:03 | Epoch bump with no writer (invariant) | Page SRE, then CTO |
| 09:17 | Revocation unpurged after 15 minutes (invariant) | Page SRE, then CISO |
| 09:19 | Cache hit rate below its floor | Ticket |
| 11:31 | Degraded share, slow burn (three-day pair) | Ticket |
| 12:20 | Degraded share, fast burn | Page |
| 13:40 | User complaint, in the original incident | None |
Source: AegisFin Corp reference case (fictional), Production-Grade Enterprise RAG Architecture, Vol. 1; times from the book's tested alert replay.
Burn-rate pairs need traffic to mean anything. The book’s rule of thumb is that below about 1,000 answers an hour, deployments should rely on the six-hour pair. The arithmetic behind it is easy to check. Take 100 answers an hour as an illustrative input: each degraded answer is then 1% of the one-hour window, and 29 of them (28.8% of 100, rounded up) are enough to page. The five-minute window holds about 8 answers (100 × 5 / 60), so there a single degraded answer moves the share by about 12 points.
Rollback follows the same discipline. It moves the release and never lowers an epoch. Restoring an older epoch would let a conversation started before the revocation, whose earlier turns quote the revoked memo, pass the scope check again. A reverted reranker has the golden set replayed before users return to it.
Five questions show whether a release process would have caught these failures
I use five questions when I review a RAG release process. Each should be answerable by pointing to a file, a rule and an owner.
- Does the gate measure multi-section coverage (SecCov@k, CS Recall@k), or only top-rank relevance (nDCG, MRR)?
- Are figures compared with rows a controller froze, in a repository the SQL team cannot edit?
- Are tenant isolation and access boundaries enforced by deterministic code and database policy, with no model grader in the decision?
- What happens to a release when a suite is skipped, cancelled or missing?
- Which invariant pages if a revoked document is not verified as purged within 15 minutes?