14. Observability and Production Operations
Trace requests, monitor ingestion freshness, manage queues, and prepare incident recovery.
Trace a RAG Request
Trace request IDs, corpus version, filters, retrieved chunk IDs and scores, reranking, prompt/model versions, citation validation, stage latency, usage, and final status. Avoid logging raw confidential text by default; restrict trace access and retention. Correlation IDs should connect API, retrieval, model, and worker events without exposing secrets.
{
"traceId":"rag_abc123",
"corpusVersion":"kb-2026-10-28",
"retrievedChunkIds":["doc-1:4","doc-8:2"],
"rerankerUsed":true,
"latencyMs":1850,
"status":"success"
}- Inspect the relevant pipeline stage instead of guessing.
- Preserve source provenance, versions, and access scope.
- Measure quality on representative queries.
What is a benefit of stage-level traces?
Monitor Ingestion Health and Freshness
Track source counts, last successful sync, ingestion lag, stage failures, dead letters, deletion lag, index version, and age of newest indexed content. Reconcile source counts and sample content: a successful job does not prove all documents were parsed correctly. Alert when freshness SLOs are missed.
Metrics:
ingestion lag | indexed documents | parse failure rate
deletion lag | dead-letter count | last successful sync
index version | stale-source rate- Inspect the relevant pipeline stage instead of guessing.
- Preserve source provenance, versions, and access scope.
- Measure quality on representative queries.
Which metric captures whether updates become searchable promptly?
Queues, Retries, and Backpressure
Use durable queues, bounded concurrency, exponential backoff with jitter, checkpoints, and idempotent upserts. Respect provider retry hints and distinguish transient errors from invalid input. Backpressure protects parsers, embedding APIs, and indexes. Quarantine poison documents instead of retrying forever. Keep ingestion capacity separate from interactive query capacity.
async function processJob(job) {
try { await ingest(job); await queue.ack(job.id); }
catch (e) {
if (isRetryable(e)) await queue.retry(job.id, backoff(job.attempt));
else await queue.deadLetter(job.id, safeError(e));
}
}- Inspect the relevant pipeline stage instead of guessing.
- Preserve source provenance, versions, and access scope.
- Measure quality on representative queries.
Why bound worker concurrency?
Incident Response and Rollback
Incidents include leakage, stale policy answers, poisoned sources, provider outages, and index corruption. Prepare runbooks to disable a source or tool, switch to a prior index, limit traffic, or fall back to safe search. Preserve evidence securely, rotate exposed credentials, assess impact, and add regression cases after remediation. Audit emergency controls and practice rollback before incidents.
Detect -> contain source/tool/index -> protect users
-> preserve evidence -> remediate -> validate -> restore gradually- Inspect the relevant pipeline stage instead of guessing.
- Preserve source provenance, versions, and access scope.
- Measure quality on representative queries.
What should follow a RAG incident fix?