AI & DATA / TECHNICAL EXPLAINER

AWS AIP-C01: Building RAG Applications with Amazon Bedrock

Retrieval-Augmented Generation combines a foundation model with external evidence so responses can use enterprise documents, product knowledge, policies, support content, or other domain data that […]

In this article

Retrieval-Augmented Generation combines a foundation model with external evidence so responses can use enterprise documents, product knowledge, policies, support content, or other domain data that the model may not know reliably. Amazon Bedrock Knowledge Bases provides managed ingestion, embedding, vector-store integration, retrieval, and retrieve-and-generate workflows, allowing teams to build RAG applications without implementing every retrieval component from scratch.

The current AWS Certified Generative AI Developer – Professional (AIP-C01) scope includes RAG, vector databases, embeddings, model evaluation, security, and cost optimization. The adjacent AWS AIF-C01 and AWS Certified Machine Learning Engineer – Associate (MLA-C01) relationships are useful for foundational AI and production ML context.
As of October 22, 2026, MLA-C01 English testing has ended (September 28), while English MLA-C02 beta delivery began September 29. MLA-C01 remains available in Japanese, Korean, and Simplified Chinese during the beta transition until January 14, 2027; see AWS’s September 2026 transition notice.

Start with the retrieval question, not the model

A customer’s exact product code can match several policies with similar words. Before blaming generation, test whether metadata filters limit evidence to the correct tenant, locale and policy effective date. Compare lexical and semantic candidates on a held-out query set. Reranking can improve candidate order, but it cannot recover missing evidence or correct a broken authorization boundary. A fluent answer citing a revoked source is still wrong. Trace the current document version from ingestion through retrieval to the final cited passage. Knowledge Base retrieval settings affect candidate chunks and their order, so changes should be tested with representative queries and known evidence.
Define which questions require enterprise evidence, what sources are authoritative, how fresh they must be, and what the application should do when evidence is missing. RAG is most valuable when the answer depends on a corpus the model cannot safely infer from general training alone.

Query rewriting can improve recall by expanding acronyms, correcting product names, or transforming conversational questions into clearer search terms. Keep the original query in traces so operators can distinguish user intent from rewritten retrieval intent. No-result behavior should be explicit. If retrieval returns weak evidence, the application can ask for clarification, search another source, escalate, or state that the knowledge base lacks sufficient information. Lowering thresholds until something always returns creates hallucination risk. Structured data may be better answered through a tool or database query than through vector retrieval. Account balance, order status, or live inventory should usually come from authoritative systems rather than embedded snapshots. Hybrid RAG applications can therefore route questions between knowledge retrieval, structured tools, or both. The routing decision should be evaluated and observable because a wrong route can produce stale or unauthorized answers.

Prepare documents for reliable retrieval

Ingestion should preserve source identity, ownership, effective date, permissions, and document structure. Chunking affects how much context each retrieval unit contains and whether one answer spans several chunks. Evaluate chunk size and overlap on real questions. Small chunks can lose context; very large chunks can reduce precision and consume prompt budget.
Corpus preparation should remove obvious duplicates before embedding. Repeated copies of the same policy can occupy several top retrieval positions and reduce evidence diversity even when semantic search is working as designed. Documents should also carry status such as draft, approved, superseded, or archived. A semantically similar superseded policy should not answer a current-policy question merely because the vector score is high. Chunking should follow document structure where possible. Headings, sections, paragraphs, tables, and lists can be more meaningful boundaries than fixed character counts. Preserve enough hierarchy metadata that retrieved passages can be understood in context.

Table-heavy documents deserve special evaluation. Flattened table text can lose row/column meaning, while large screenshots or PDFs may require extraction workflows before retrieval becomes useful. Source onboarding should begin with ownership and trust classification. Documents from a regulated policy repository, a team wiki, and user-uploaded files may all be text, but they should not have equal authority or retention rules. Source preprocessing should preserve language, document version, and source system. Multilingual corpora may need embedding and evaluation strategies that work consistently across languages rather than assuming one English benchmark represents all users. Large PDFs can contain headers, footers, duplicated page furniture, or OCR noise that pollutes embeddings. Clean repeated boilerplate before chunking so retrieval ranks meaningful content instead of document chrome.

Choose embeddings and vector storage from the corpus

Embeddings represent semantic meaning for similarity retrieval, while the vector store indexes those representations and metadata. Different models and backends can vary in dimensionality, filtering, scale, and cost. Benchmark with the actual corpus and query set instead of assuming one embedding model is universally best.
Reranking can improve the order of a broader candidate set. Evaluate whether the extra latency and cost materially improve answer quality before adding a reranker to every query path.

Use metadata filtering for authority and scope

Semantic similarity alone cannot enforce region, product version, document status, or user permissions. Store metadata that lets the retriever filter candidates before they enter the model context. This is critical for regulated or multi-tenant knowledge bases where the most similar document may still be unauthorized.
Effective dates can support temporal correctness. Metadata such as `effective_from` and `effective_to` lets the application filter historical material while retaining it for audit or time-specific questions. Document updates should not create two active versions unless the application intentionally supports historical queries. Mark superseded versions or remove them from current retrieval candidates. Tenant isolation can be implemented through separate knowledge bases, index namespaces, metadata filters, or other supported patterns. Choose a model that makes authorization easy to prove and operationally manageable.

Control source permissions end to end

RAG can expose confidential text if the retrieval layer ignores caller authorization. Apply IAM, application authorization, storage permissions, and metadata filters so users retrieve only evidence they are entitled to see. The PII-handling and data-exfiltration principles are especially relevant because retrieval can surface information the model itself would never otherwise contain.
Authorization testing should use paired identities. Ask the same question as users with different permissions and verify that restricted documents never enter the retrieved context for the unauthorized identity. Deletion workflows should remove data from the source and propagate to the index or vector store according to the application’s retention objective. A deleted document remaining retrievable is a governance defect.

Security review should consider prompt injection inside retrieved documents. An untrusted document can contain instructions attempting to manipulate the model. Treat retrieved text as data, keep tool authorization independent, and apply guardrails or content controls according to the threat model. RAG prompts should clearly distinguish quoted source content from system and developer instructions. This helps reduce the impact of malicious text embedded in source documents. Guardrails can add another content-control layer, but they do not replace source authorization or prompt-injection-resistant application design. Protect each boundary for the risk it actually controls. Deletion should be tested end to end. Remove a sensitive source, synchronize the knowledge base, then verify the document cannot be retrieved from normal queries or caches. Query logging can improve the system, but user questions may contain sensitive data. Store logs according to privacy policy and minimize raw prompt retention where aggregate metrics are sufficient.

Assemble context without flooding the model

Retrieve enough evidence to answer the question but avoid sending dozens of weak passages. Reranking, metadata filtering, result limits, and query rewriting can improve the signal-to-noise ratio. Longer context increases token cost and can dilute the strongest evidence. More retrieved text is not automatically better grounding. Generated answers should preserve provenance. Applications should retain source identifiers and expose citations or links where users need verification. The original document remains the authority; the generated answer is a synthesized view. If evidence conflicts, the application should surface uncertainty instead of merging incompatible policies into one confident response.
Hybrid retrieval can combine semantic and lexical signals where supported by the architecture. Exact product IDs, error codes, policy numbers, and names often benefit from lexical matching that pure semantic similarity can underweight.

Context packing should preserve source boundaries. Several adjacent chunks from one document can be grouped coherently rather than appearing as independent evidence, while diverse sources should remain distinguishable. Citations should map to accessible originals. Store source URI, document ID, section, page, or other location data during ingestion so users can verify the evidence without hunting manually. Source citations should be stable even if storage locations change. Use durable document identifiers and resolve them to current URLs or pages at presentation time where possible.

Evaluate retrieval and generation separately

A bad answer can come from retrieval failure or model-generation failure. Bedrock RAG evaluation supports metrics for retrieval and retrieve-and-generate workflows using test prompts and expected results. Measure relevance, correctness, faithfulness, citation quality, and task usefulness on hard examples, including stale-document and near-match traps.
Evaluation sets should include near-match traps: old versions, wrong regions, similar products, ambiguous acronyms, and documents using the same terminology for different policies. Retrieval-only evaluation isolates whether the system found the correct evidence, while retrieve-and-generate evaluation measures the complete answer path. Use both so model quality does not hide poor retrieval. Generation evaluation should include faithfulness to retrieved context. A model can produce a plausible answer that is not supported by the passages it received, which defeats the purpose of grounding.

Prompt templates should tell the model how to behave when sources disagree or fail to answer. Encourage explicit uncertainty and source citation rather than free-form completion from background knowledge. Question-answer pairs for evaluation should be built from real user intents where possible. Synthetic questions are useful for coverage, but production logs often reveal ambiguous phrasing and vocabulary that internal authors did not anticipate. Hard-negative examples are especially valuable. Include documents that share terminology but are wrong because of version, geography, product, customer, or effective date. These cases test whether metadata and ranking work together. Retrieval metrics should distinguish recall from precision. A broad retriever may include the correct passage somewhere in the top 20 but still overwhelm the generator with irrelevant context. Measure the rank and quality of the evidence that actually reaches the model.

Reranking or query decomposition can improve difficult multi-part questions, but both add processing. Use them for query classes that benefit rather than adding several retrieval stages to every request.

Monitor index freshness and ingestion failures

A knowledge base can appear healthy while source synchronization stops. Track latest successful ingestion, document counts, failed records, deletion propagation, and source-to-index freshness. When source documents are retired or permissions change, confirm the retrieval index reflects those changes quickly enough for the application’s risk level.
Index refresh should be observable. Track last successful synchronization, source object count, indexed document count, failed documents, and deletion status. Freshness needs evidence, not assumption. A mature Bedrock RAG application operates like a governed search product plus a generative layer: authoritative sources, controlled ingestion, permission-aware retrieval, measured relevance, traceable citations, and explicit fallback when evidence is insufficient. Vector-store backup and recovery should be considered, but many indexes can be rebuilt from authoritative sources. Decide whether faster restore justifies backup complexity or whether repeatable re-ingestion is sufficient.

Index rebuild time becomes an operational metric at scale. If rebuilding millions of documents takes many hours, incident recovery and model migrations need plans that preserve service availability during reindexing. Operational dashboards should show query volume, retrieval latency, generation latency, no-result rate, citation count, safety interventions, and evaluation scores. This gives teams a full view from search to answer. RAG releases should be versioned across prompt, embedding model, chunker, metadata schema, retrieval settings, reranker, vector store, and generator model. Any one of these can change output behavior. When users report a bad answer, preserve the trace: original query, rewritten query, retrieved passages, ranks, generator prompt, model version, and citations. This evidence shortens root-cause analysis dramatically. The long-term goal is not to maximize retrieval sophistication. It is to create a knowledge system whose evidence is current, authorized, relevant, traceable, and cheap enough to operate at the required scale.

RAG governance should also define corpus ownership. Every source collection needs a team responsible for document freshness, permission changes, deletion, and deprecation so the AI team does not become the manual steward of all enterprise content. Keep an index-version or ingestion-run identifier in traces. When one answer changes after a source update, operators can determine whether the difference came from the model, prompt, retrieval configuration, or corpus state. This is what makes a production RAG system explainable rather than merely impressive in a demo. Keep that corpus/version evidence available for every production answer investigation.

Optimize cost across retrieval and inference

RAG cost includes ingestion, embeddings, vector storage, retrieval, reranking, model input tokens, output tokens, and observability. Prompt caching can help supported models when large stable context prefixes repeat, but the design should not rely on cache hits that are not guaranteed. The AWS RAG architecture is successful when retrieval is governed like a search system and generation is evaluated like an AI application. Trusted evidence, authorization, freshness, and measurable retrieval quality matter as much as the model choice. Similarity scores should not be treated as universal confidence probabilities. Score distributions vary across embedding models and corpora. Calibrate thresholds on labeled retrieval examples rather than copying a number from another project. RAG latency includes embedding the query, retrieval, reranking, model inference, and sometimes access checks or source expansion. Trace each stage separately so optimization targets the real bottleneck.

Cost can often be reduced by improving retrieval precision because fewer irrelevant chunks means fewer input tokens. Better search quality and lower generation cost can therefore reinforce one another. Prompt caching can help when a long stable system prompt or repeated context prefix is reused across calls on supported models, but cache behavior should be measured rather than assumed. Cost attribution should separate ingestion from query-time spend. A corpus with frequent document churn can spend significantly on repeated embedding even if user query volume is modest.