CLOUD CONCEPT

Retrieval-Augmented Generation

Retrieval-Augmented Generation is an application pattern that retrieves relevant external information and supplies it as context to a generative model when producing an answer.

Cloud Concepts Hub →

What is Retrieval-Augmented Generation

RAG connects a foundation model to information outside its learned parameters, such as enterprise documents, product catalogs, or operational records. It helps applications answer questions using organization-specific or recently updated information without retraining the model, although accuracy still depends on retrieval quality and how the model uses the evidence.

Retrieval-Augmented Generation (RAG) combines information retrieval with generative inference. An application retrieves information relevant to a user's request, includes that information in the model's input context, and asks the model to produce a response grounded in the retrieved evidence. The retrieval step does not, by itself, change the model's weights. This distinction matters when choosing between RAG, prompt engineering, and fine-tuning: RAG supplies external knowledge at request time, while fine-tuning changes model parameters to influence behavior or task performance.

A typical document-based implementation has ingestion and query stages. During ingestion, documents are parsed, divided into chunks, and indexed with metadata such as document identifiers, update timestamps, and access restrictions. Many systems create vector embeddings that represent semantic meaning. At query time, the application searches for relevant chunks using vector similarity, keyword search, or a hybrid approach. It may rerank results before supplying selected passages to the generation model. RAG does not require a vector database; retrieval can also use conventional search, databases, or other knowledge sources.

In the cloud, object storage can hold source files, a search service or database can maintain an index, and a managed model service can provide embeddings and text generation. Managed capabilities such as Amazon Bedrock Knowledge Bases can coordinate ingestion, retrieval, and generation. Engineers still need to choose source data, configure retrieval behavior, enforce permissions, and evaluate the resulting answers. Updating a source document does not necessarily update its indexed representation immediately, so ingestion schedules and deletion propagation affect freshness.

Business applications include employee policy assistants, customer-support tools, technical documentation search, and product-selection assistants. For example, a support application can retrieve troubleshooting instructions for a specific device model and firmware version, then generate an explanation with references to the relevant manual. A policy assistant can retrieve the policy applicable to an employee's location instead of relying on general information learned during model training.

RAG is an important part of context engineering: deliberately selecting and organizing the instructions, evidence, conversation history, and tool outputs available to a model. Chunk size, metadata filters, query rewriting, reranking, and context ordering all affect whether the model receives useful evidence. Adding more documents is not automatically better. Irrelevant or conflicting passages consume context capacity, increase token costs, and can distract the model. Instructions should specify how to handle insufficient evidence, conflicting sources, and requests for citations.

Evaluate retrieval and generation separately, then test the complete application. Retrieval evaluation can measure whether relevant evidence appears among the top results, using metrics such as recall at k and ranking quality. Generation evaluation should examine correctness, relevance, completeness, faithfulness to retrieved evidence, and whether citations actually support the claims. Use representative questions, expected answers, and reference passages, including unanswerable questions and permission-sensitive cases. Human review and calibrated model-based judges can complement automated checks. For agents and workflows, also evaluate tool selection, intermediate steps, and final task completion rather than scoring only the last response.

RAG reduces some causes of hallucination but does not guarantee factual answers. A model can misinterpret evidence, invent unsupported details, or cite an irrelevant passage. Retrieved documents can also contain prompt-injection instructions, so treat their contents as untrusted data rather than authoritative commands. Apply document-level authorization before retrieved content reaches the model, protect sensitive context, and monitor latency, cost, retrieval failures, and answer quality. RAG introduces search and indexing overhead, but it can make knowledge updates more manageable than repeatedly retraining a model.

Key aspects of Retrieval-Augmented Generation

Effective RAG combines relevant retrieval, deliberate context construction, evidence-grounded generation, layered evaluation, and secure management of external knowledge.

External knowledge at inference time

RAG supplies relevant information when a request is processed rather than relying only on knowledge stored in model parameters. Updating the knowledge source and its index can change available evidence without retraining the generation model.

Retrieval quality determines available evidence

Chunking, embeddings, keyword matching, metadata filters, and reranking influence which information reaches the model. Test retrieval independently because a fluent answer cannot compensate for missing or incorrect evidence.

Context engineering

Select and organize retrieved passages alongside instructions, conversation history, and tool results within the model's context budget. Define how the model should respond when evidence is missing or contradictory instead of simply adding more text.

Grounding and traceability

Responses can include references to retrieved source passages so users can inspect the supporting evidence. Citation presence alone is insufficient; verify that the cited material supports the associated claim.

Layered application evaluation

Measure retrieval relevance, answer correctness, faithfulness, citation support, latency, and cost using representative test cases. For agentic or multi-step implementations, also test tool use, workflow execution, and successful completion of the user's task.

Security and knowledge lifecycle

Enforce source-level permissions during retrieval and prevent unauthorized passages from entering model context. Maintain index freshness, propagate deletions, and treat retrieved text as potentially malicious input rather than trusted instructions.

Cloud services for Retrieval-Augmented Generation

A typical AWS implementation stores source documents in Amazon S3, retrieves indexed evidence through Amazon OpenSearch Service or a suitable Amazon Aurora PostgreSQL vector configuration, and invokes models through Amazon Bedrock. Amazon Bedrock Knowledge Bases can manage ingestion and retrieval for supported configurations, reducing custom pipeline code. OpenSearch and Aurora are alternative retrieval-store choices rather than mandatory components used together. Across either design, the application must enforce access controls, synchronize source changes, assemble useful context, and evaluate both retrieved evidence and generated answers.

Amazon Bedrock

Amazon Bedrock provides access to foundation models for embeddings and generation. Amazon Bedrock Knowledge Bases provides managed RAG capabilities for supported data sources and retrieval stores, while engineers remain responsible for data selection, authorization design, and application evaluation.

Open Amazon Bedrock →
Amazon OpenSearch Service image Amazon OpenSearch Service

Amazon OpenSearch Service can index document text, metadata, and vectors for keyword, vector, or hybrid retrieval. It supplies relevant evidence to a RAG application; the generation model is a separate component.

Open Amazon OpenSearch Service →
Amazon Simple Storage Service image Amazon S3

Amazon S3 can store source documents and ingestion artifacts for a RAG pipeline. Source updates and deletions must be reflected in the retrieval index before queries reliably use the changed information.

Open Amazon S3 →
Amazon Aurora image Amazon Aurora

Amazon Aurora PostgreSQL-Compatible Edition supports the pgvector extension for storing and searching embeddings alongside relational data. This can support RAG retrieval where application records, metadata filtering, and vector search need to share a database.

Open Amazon Aurora →