Grounding Answers in Your Data with RAG and Bedrock Knowledge Bases
This lesson explains how retrieval augmented generation (RAG) grounds a model's answers in your own, current data without retraining it, and how Amazon Bedrock Knowledge Bases provides RAG as a managed feature.
Learning outcomes
After completing this lesson, you will be able to:
- Explain the benefits of RAG.
- Describe the steps of retrieval augmented generation.
- Identify the AWS services that can serve as vector stores.
- Distinguish RAG from fine-tuning.
Why RAG
Foundation models do not know your private data, and their knowledge stops at a training cut-off. RAG retrieves relevant information at question time and adds it to the prompt, so answers are:
- Current: update the documents, not the model.
- Based on private data.
- Backed by citations.
- Less prone to hallucination.
How RAG works
Retrieval-augmented generation supplies a model with relevant information at query time. The process consists of the following steps.
-
Ingest and chunk
Ingest documents and split them into chunks.
-
Embed
Create an embedding for each chunk.
-
Store
Store the vectors in a vector store.
-
Retrieve
At query time, embed the question and retrieve the most similar chunks.
-
Generate
Add the chunks to the prompt so the model generates an answer based on them.
The following diagram shows the ingestion and query paths of RAG.

RAG step by step
Amazon Bedrock Knowledge Bases
Retrieval Augmented Generation (RAG) gives a model relevant information from your own documents at the moment it answers, so its answers are grounded in your data. Amazon Bedrock Knowledge Bases manages the whole process. The following list describes its principal features.
- Data connectors: S3, web crawler, Confluence, SharePoint, Salesforce and more.
- Chunking strategies: fixed-size, hierarchical, semantic or none; parsing of complex documents with tables and images, using a foundation model or Bedrock Data Automation.
- A choice of embedding model, automatic synchronisation, metadata filtering, reranking and source citations.
- Natural-language queries over structured data in Amazon Redshift, and GraphRAG with Amazon Neptune.
Applications query a knowledge base through two APIs. Retrieve returns only the most relevant chunks of documents, which the application can then pass to a model of its choice in its own prompt. RetrieveAndGenerate does both steps: it retrieves the chunks and asks a model to write an answer from them, with citations to the sources. The following table summarises the two.
| API | Returns |
|---|---|
| Retrieve | The relevant chunks only |
| RetrieveAndGenerate | The chunks plus a generated answer |
Using a knowledge base
Vector stores on AWS
A knowledge base turns each chunk of a document into an embedding, a vector that captures its meaning, and stores it in a vector store, which can find the chunks most similar to a question. Several AWS services can be the vector store. Amazon OpenSearch Serverless and OpenSearch Service provide fast vector search at large scale. Aurora PostgreSQL or RDS for PostgreSQL with the pgvector extension keep vectors next to existing relational data. Amazon Neptune Analytics combines graphs with vectors, and Amazon S3 Vectors provides the lowest-cost vector storage. Other options include Amazon DocumentDB, Amazon ElastiCache and partner products such as Pinecone. The following table summarises the stores.
| Store | Best for |
|---|---|
| Amazon OpenSearch Serverless / OpenSearch Service | Vector search at scale |
| Aurora PostgreSQL or RDS for PostgreSQL with pgvector | Vectors alongside existing relational data |
| Amazon Neptune Analytics | Graphs combined with vectors |
| Amazon S3 Vectors | Lowest-cost vector storage |
| Others | Amazon DocumentDB, Amazon ElastiCache; partners such as Pinecone, Redis, MongoDB Atlas |
Vector stores
RAG or fine-tuning?
RAG and fine-tuning are often presented as alternatives, but they change different things. RAG changes what the model knows when it answers: relevant documents are retrieved and added to the prompt, so the model can use facts it was never trained on, including data that changes often. Updating the knowledge means updating the documents, with no retraining. Fine-tuning changes how the model behaves: training on examples teaches it a style, format or specialised task, such as always replying in a company's tone. It is not a good way to add facts, which would need retraining whenever they change. The following table summarises the distinction.
| Use | To change the model's | Example |
|---|---|---|
| RAG | Knowledge | Facts, documents, frequently changing data |
| Fine-tuning | Behaviour | Style, format, specialisation in a task |
Many applications use both.
RAG or fine-tuning?
A policy assistant built on a knowledge base
An HR team wants an assistant that answers employees' questions from 300 policy documents and shows where each answer came from. The design uses Bedrock Knowledge Bases:
| Step | Configuration |
|---|---|
| Data source | An S3 bucket containing the policy PDFs; re-synced whenever HR updates a policy |
| Chunking | Hierarchical chunking, so answers keep the surrounding section's context |
| Embeddings | Amazon Titan Text Embeddings |
| Vector store | Amazon S3 Vectors (lowest cost) or OpenSearch Serverless |
| Query | RetrieveAndGenerate with a low temperature and citations |
response = bedrock_agent_runtime.retrieve_and_generate(
input={"text": "How many days can I work from abroad each year?"},
retrieveAndGenerateConfiguration={
"type": "KNOWLEDGE_BASE",
"knowledgeBaseConfiguration": {
"knowledgeBaseId": "KB12345678",
"modelArn": "arn:aws:bedrock:us-east-1:111122223333:inference-profile/us.amazon.nova-2-lite-v1:0",
},
},
)
print(response["output"]["text"]) # the answer
print(response["citations"]) # which document passages it came fromWhen the remote-working policy changes, HR uploads the new document and syncs the knowledge base; the next answer reflects it immediately. Fine-tuning a model on the policies would have been slower, more expensive, and out of date at the first policy change.
Why is RAG usually better than fine-tuning for company information that changes often?
Show answer
Updating the documents in the knowledge base keeps answers current at once, while a fine-tuned model would need retraining after every change.
Exam Tips
Remember for the exam
- A chatbot that answers from company documents with citations points to Bedrock Knowledge Bases (RAG).
- For frequently changing data, use RAG rather than fine-tuning.
- RAG reduces hallucinations by grounding answers in retrieved sources.
- For vector search alongside existing relational data, use Aurora or RDS for PostgreSQL with pgvector.
- For serverless vector search at scale use OpenSearch Serverless; for the lowest-cost vector storage use S3 Vectors.
- To return only the relevant chunks use the Retrieve API; to retrieve and answer use RetrieveAndGenerate.