Build a workload cost model before optimizing
Model the path a request actually takes: ingestion and embeddings, vector storage and indexing, retrieval and reranking, model input and output, tool calls, evaluations, logs, and egress. Use current service pricing and observed usage rather than a fixed monthly conclusion.
Unit-economics worksheet
| Stage | Measure | Question |
|---|---|---|
| Ingest and index | Documents, chunks, embeddings, writes | How often does corpus change? |
| Query and answer | Retrievals, candidates, tokens, tool calls | Which user intent drives the cost? |
| Operate | Evaluations, traces, logs, transfers | What evidence is retained and for how long? |
Review the Pareto frontier with product, security, and operations owners rather than letting a cost dashboard select the winner. A configuration may reduce token use while increasing denied-access errors because it loses filtering context, or it may improve median latency while causing a p95 timeout that forces users to retry. Keep an experiment receipt containing workload composition, measured usage, cache hit and invalidation behavior, error and fallback rates, and the exact pricing inputs used at the time. Re-run the lab after a material corpus change, a model-route change, or a different Region deployment. This guards against treating a past optimization result as a timeless architectural property.
Budget latency by stage and percentile
An end-to-end average hides tail behaviour. Allocate an observed p50 and p95 budget across authentication, query rewrite, retrieval, reranking, context assembly, model inference, tool calls, and rendering. Measure where waiting occurs before adding caches or changing models.
Latency-budget measurement path
Loading diagram...
A faster model is not automatically a faster or better user experience if retrieval, tool, or retry latency dominates. Quality, permission, and citation checks remain part of the budget.
Tune retrieval only behind quality gates
Chunk boundaries, top-K, candidate count, reranking, context packing, model routing, and compression create coupled tradeoffs. Change one factor against a stable corpus, permissions, and evaluation set. Retain a change only when it improves the chosen measure without violating citation, safety, or latency boundaries.
Optimization experiment record
A reproducible, workload-owned experiment template.
Click on an annotation to highlight it in the JSON
Cache and route with correctness and isolation controls
Cache only values whose identity, freshness, permissions, and invalidation behaviour are understood. Include tenant and authorization scope in cache keys where relevant, never serve an entry across isolation boundaries, and invalidate on corpus, policy, or permission changes.
For Bedrock prompt caching, verify the selected model and request structure support it, then measure the configured cache-point, TTL, write and read behaviour, latency, and cost for the target workload. It is an optimization mechanism, not an authorization or data-retention policy.
Isolation-safe retrieval cache decision
Loading diagram...
- Batch or compress only when it preserves retrieval and answer quality.
- Route to a smaller or different model only after scenario-specific evaluation.
- Use storage tiers and lifecycle policies only after retention, recovery, and access patterns are known.
Optimize for less unnecessary work, then prove it
Useful sustainability work removes wasteful retrievals, tokens, retries, duplicated indexing, and idle capacity while preserving user outcomes. Track measured requests, tokens, cache effectiveness, storage footprint, and failed work. Do not convert those measurements into an invented universal carbon figure.
- Choose a representative workload and baseline configuration.
- Set quality, security, and reliability stop criteria before changing an efficiency lever.
- Measure usage and latency distributions alongside evaluation results.
- Roll back a reduction that harms the evidence contract, then record the result for the next experiment.
Account for the unit of work a user actually receives
A monthly bill is a lagging aggregate, not a decision model. Define a request class such as “cited policy answer” or “agent-assisted triage”, then attribute the observed units that make it possible: documents and embeddings during ingestion, index reads and candidates during retrieval, reranker calls, input and output tokens, tool calls, evaluation runs, telemetry retention, and data transfer. Keep fixed platform costs separate from variable usage. The result is a measured hypothesis for a target account and Region, not a portable price claim; service pricing, quotas, model availability, and cache behavior must be rechecked before a production forecast.
Unit-economics measurement record
Illustrative application accounting; populate it with current service pricing and observed usage rather than assumed rates.
Click on an annotation to highlight it in the JSON
Use a latency waterfall to choose the next experiment
Instrument wall-clock duration and wait time at every request boundary, then compare p50, p95, and timeout or fallback rates for the same query class. A waterfall distinguishes a slow dependency from too many candidates, an oversized context, repeated agent steps, or client rendering. It also makes “fast enough” a product decision: allocate a budget to the user-visible objective and reserve time for citation, authorization, and safe fallback rather than optimizing generation in isolation. Do not infer a universal latency target from a Lens; set and validate one for the workload.
Latency waterfall payload
One sampled request with stage timings and a bounded tuning decision.
Click on an annotation to highlight it in the JSON
Choose Pareto improvements and make cache invalidation contractual
Run a Pareto lab: test a small set of configurations against a frozen workload, retaining any configuration that is not worse on every required dimension. Compare quality, authorization behavior, p95 latency, variable usage, operational failures, and retained data. A cache is eligible only when its key contains the inputs that determine correctness: normalized request, tenant or authorization scope where applicable, corpus and policy version, selected route, and an explicit expiry or invalidation event. A hit is not proof of a benefit if it serves stale or cross-scope evidence.
Sustainability decision checklist
| Decision | Control | Validation evidence |
|---|---|---|
| Reduce candidates or tokens | Freeze corpus and answer contract | Ablation shows quality and citation validity remain acceptable. |
| Introduce a cache | Scope key and invalidate on data, policy, or permission change | Freshness, isolation, miss, and invalidation tests pass. |
| Change storage or processing schedule | Respect retention, recovery, and access requirements | Measured resource use and required recovery behavior are preserved. |
AWS guidance for memory, context, and RAG optimization
Primary Agentic AI Lens guidance for workload-specific performance choices and a measured optimization loop.
Read the Agentic AI Lens performance practiceAttribute change cost with a decision-ready experiment ledger
A cost or latency result is only useful when a reviewer can tell what changed and what else remained stable. Create an experiment ledger before deployment: state the hypothesis, baseline and candidate configuration, corpus and permission snapshot, traffic-selection rule, pricing-input date, measured usage, quality guardrails, and rollback trigger. Record both the planned and observed request mix because a candidate that appears cheaper can simply have received easier requests. Attribute shared overhead carefully; do not charge every evaluation or ingestion run to an individual query unless the allocation method says so. The ledger supports a decision, not a universal saving claim.
Experiment and cost-attribution ledger
Illustrative record that separates a measured workload result from a future forecast.
Click on an annotation to highlight it in the JSON
Review rejected experiments as carefully as retained ones. A negative result can identify a cache key that is too broad, a context reduction that drops authority information, or an apparent model gain that merely shifts work to retries. Keep the receipt so the next engineer does not repeat the same unsafe optimization.
Degrade performance without degrading the evidence contract
When a latency budget is at risk, select a pre-evaluated degradation tier rather than stripping controls at runtime. For example, preserve authorization filters and source citations while reducing candidate breadth only for a named low-risk query class; disable optional enrichment before disabling validation; or return a bounded retrieval result with an honest status rather than manufacture an answer. Each tier needs entry criteria, a maximum duration, telemetry, an owner, and a recovery test. Never use a cache or a smaller model route to bypass tenant isolation, freshness, policy evaluation, or required human approval.
Safe performance-degradation policy
| Condition | Allowed action | Forbidden shortcut |
|---|---|---|
| Reranker saturation | Use tested candidate cap and preserve citations | Drop authorization filters or invent unsupported sources. |
| Model wait exceeds budget | Return approved retrieval-only result or abstain | Reuse a cross-tenant cached response. |
| Tool dependency unavailable | Use static approved route or human handoff | Retry an unsafe write or widen tool access. |
Test the policy with concurrent recovery rather than a single synthetic request. A dependency may appear healthy while queues drain, caches repopulate, or a traffic spike causes the degraded tier to become the new bottleneck. Observe tier-entry count, duration, user-visible fallback, and recovery checks by request class. If the degradation route changes answer shape, state that explicitly in the response so consumers do not mistake a bounded result for a complete answer.
Glossary: terms first introduced here
These are the technical terms introduced in this step. Later modules build on them rather than redefining them from scratch.
New vocabulary for this step
| Term | Plain-language meaning | Why it matters here |
|---|---|---|
| Token | A unit of text processed by many language and embedding models for input, output, or both. | Token volume connects context size and retries to cost and latency, but does not replace quality measures. |
| P95 latency | The response time at which 95% of measured requests finish at or below that value. | It reveals slow-tail experiences that an average response time can conceal. |
| Cache | A stored result reused to avoid repeating work for a compatible future request. | A cache key and invalidation rule must preserve identity, permission, source freshness, and answer semantics. |
Knowledge Check
Test your understanding with this quiz. You need to answer all questions correctly to mark this section as complete.