Harden and deploy the RAG service¶
Deployment is where every hidden assumption becomes a failure mode. A local database may always be available. Your model provider will not be. A notebook can wait forever. A public request cannot.
Hardening means deciding how the system fails before those failures happen.
Put a deadline around dependencies¶
Set separate timeouts for PostgreSQL, embedding, reranking, and generation. A request-wide timeout alone tells you too late which dependency consumed the budget.
Retry transient failures such as a short provider outage or connection reset. Use bounded exponential backoff and stop after a small number of attempts. Invalid input, access denial, and malformed model output will not improve because you tried them five more times.
If dense retrieval fails and lexical retrieval is still available, you may return a lexical-only result. Record that fallback in the trace and response diagnostics. Do not present degraded retrieval as if the full pipeline ran.
Expose two kinds of health¶
A liveness check answers, “Is the process running?” A readiness check answers, “Can this process reach the dependencies needed to serve a Query?” Keep them separate so an orchestrator can restart a dead process without sending traffic to one that cannot reach PostgreSQL.
Package configuration, not secrets¶
Build the FastAPI service into a container. Pass database URLs, model names, provider keys, timeouts, and feature flags through environment variables. Commit .env.example, never a real .env file.
Use the adopter's existing database migration process to apply the PostgreSQL and pgvector schema. This Course teaches the schema and query behavior, not a general migration framework.
Run the gates before release¶
A release should pass chunking and ingestion tests, retrieval evaluation, Citation and abstention checks, malicious-Source tests, and the API contract tests. Pin Python and dependency versions so the container and evaluation run use the same code.
Emit structured logs and OpenTelemetry traces with request IDs. Keep raw protected content out of normal telemetry.
The Course stays provider-neutral because free tiers and hosting products change. The deployment Reference lists current inexpensive options, while the service depends only on a Python runtime, PostgreSQL with pgvector, environment-injected secrets, and outbound model access.
The static BuildRAG website can live on Cloudflare Pages. The Course API remains code you can deploy into the access controls and infrastructure your application already uses.
You have now followed one system from discovering a filename to operating a cited RAG service. The Advanced lessons explore techniques you can add when a measured problem calls for them.