# RAG architecture on AWS with Bedrock Knowledge Bases

> A retrieval-augmented generation design on AWS: documents in S3, a Bedrock knowledge base, a vector index and a generation model, plus the permission, freshness and quality decisions that matter.

## Key takeaways

- Two flows share one knowledge base: indexing on each sync, and answering on each question.
- Metadata files next to your documents let you filter retrieval, by year, team or customer.
- The knowledge base does not know your users' permissions. If people must only see some documents, you must scope retrieval yourself.
- Plan evaluation and guardrails from the start; they are not extras.

[Open this diagram in archhy](https://archhy.com/app#d=N4IgLglmA2CmIC4QCUCCBxABAewHadQHUBlTAdygAsCBbAQwC89MAhWAEwCdsBjAa0wBpXNjJx2Ac1is6AZ1iyQAGhDQ6AT2wBXMABEInWD0h5EIADLJlIGrDB1EoCdGwAjOtEUJQsyqIBy2OywACrqAA4KiGCcWrAqELLEuHThAKIpruLRsfEgEpwQ7MQQDPAIAEwADCqUHgBm6IXsyHQQnoj1HvIqnG3QxGDqcGY8cHS41uEQxlqGjuBQIwgxcQC+GyoiwV4A2qBFZrL29fXWaq6w0GaDdKeYcnwQuBKYAI5xxxB4iipDkWYAKryTjnDTaMALAAeiBqIHUiAAzAA2OEUdhgSiIACMqNqsAgEkokIQ2OxVU2B3YZjoZF+qjol2uSCIpAAwi4tNS-hFyiBWRztNyGZodNDEBVqioEQg0UVMTjEQAWOGUAlEkkAdhVKgYAElcMEYQgALTkqoUtZKKlmQwSb6TFQXK5mZCwe2mHkApBuj2OkDhOiGXBgPXUpC0+lqUUk0DGqXwxA6kDohWkxEW-GE4mIZEADkt1pAhyQzyNzwkYKZZgN5ZemAAFLFcLIcPhYHQeNRZOpcDwAJTWf58ljaQ1BhEqQPB0PhkB2h3WVzYTjBTiDYZ89jYMBgDhgmPiypwmUZlSprGkqrJtXZknVQs2pDbnhRxkupC6XhaWwh1sAakwWx7HYOh7Ewep2iiL0+WIREpiDWAQzDMwy1gKEKwPCEjwTGU8RTeVL1xVV1RzUlyUpYs51gGhLmFZ1mRAEIoAmTAQnQsBMDSWiOHYCtWwANwqIdeTMdAk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NXnt1Z1aZj2g7319kNZxMC2XjjnCh0Md2sOUOQam4jvTsX5svdjqtswQKsNIDBcChd87gIwsJ-raHA6vbCnJ3dlj8Hm1rCAA)

A RAG architecture on AWS answers questions from your own documents instead of from what a model happened to learn. With Amazon Bedrock Knowledge Bases, most of the plumbing (chunking, embedding, storing vectors, retrieving and prompting) is managed for you, which leaves the decisions that actually matter: what goes in, who may see it, and how you know the answers are good. This post draws the design and walks through those decisions.

## The problem: answers from your own documents

Staff want to ask "what did we agree with this supplier?" and get an answer with its source, not search results to read. A general model cannot know your documents, and fine-tuning one on them is slow, costly and goes stale. Retrieval-augmented generation (RAG) fetches the relevant passages at question time and hands them to the model with the question.

## The design

The diagram has two lanes inside one Region ([open the diagram](https://archhy.com/app#d=N4IgLglmA2CmIC4QCUCCBxABAewHadQHUBlTAdygAsCBbAQwC89MAhWAEwCdsBjAa0wBpXNjJx2Ac1is6AZ1iyQAGhDQ6AT2wBXMABEInWD0h5EIADLJlIGrDB1EoCdGwAjOtEUJQsyqIBy2OywACrqAA4KiGCcWrAqELLEuHThAKIpruLRsfEgEpwQ7MQQDPAIAEwADCqUHgBm6IXsyHQQnoj1HvIqnG3QxGDqcGY8cHS41uEQxlqGjuBQIwgxcQC+GyoiwV4A2qBFZrL29fXWaq6w0GaDdKeYcnwQuBKYAI5xxxB4iipDkWYAKryTjnDTaMALAAeiBqIHUiAAzAA2OEUdhgSiIACMqNqsAgEkokIQ2OxVU2B3YZjoZF+qjol2uSCIpAAwi4tNS-hFyiBWRztNyGZodNDEBVqioEQg0UVMTjEQAWOGUAlEkkAdhVKgYAElcMEYQgALTkqoUtZKKlmQwSb6TFQXK5mZCwe2mHkApBuj2OkDhOiGXBgPXUpC0+lqUUk0DGqXwxA6kDohWkxEW-GE4mIZEADkt1pAhyQzyNzwkYKZZgN5ZemAAFLFcLIcPhYHQeNRZOpcDwAJTWf58ljaQ1BhEqQPB0PhkB2h3WVzYTjBTiDYZ89jYMBgDhgmPiypwmUZlSprGk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+kXnpP7hWH5kAxXAsqfUxVs9kXwDVf0z2+L+Qmm1NaUONDTWLOMUyx5SSmBwh9s6a2CY87C7FyjM8WAbstw7hk5NpjM3coxbY3Fjj85-HTxIw+sdbo52YFcFofgdhIVkEKHuLahkYROnO5dswnsbtha01Vh7NXnt1Z1aZj2g7319kNZxMC2XjjnCh0Md2sOUOQam4jvTsX5svdjqtswQKsNIDBcChd87gIwsJ-raHA6vbCnJ3dlj8Hm1rCAA)).

### Indexing: on each sync

1. Documents sit in an Amazon S3 bucket. Each can have a companion metadata file with attributes such as company or year.
2. When you sync, the knowledge base splits the documents into chunks.
3. An embedding model, Amazon Titan Text Embeddings v2 in the AWS example, turns each chunk into a vector.
4. The vectors go into a vector index with a link back to their source. The console's quick-create option sets up Amazon OpenSearch Serverless; Aurora and several third-party stores are alternatives.

### Answering: on each question

1. The user asks a question in your app.
2. The app calls the knowledge base's RetrieveAndGenerate API. The example asks for hybrid search, which combines meaning-based and keyword matching.
3. The knowledge base embeds the question, finds the closest chunks, and sends the question plus those chunks to a generation model; the example uses Anthropic's Claude 3 Haiku on Bedrock.
4. The answer goes back to the app.

Around this sit an IAM service role that lets the knowledge base read the bucket and write the index, encryption keys in AWS KMS, CloudWatch for logs and alarms, and, optionally, Amazon Bedrock Guardrails to filter what goes into and comes out of the model.

## Decisions that matter more than the diagram

- **Permissions.** Anything in the index can appear in an answer to anyone who can call the app. If HR files and engineering notes share a bucket, either keep separate knowledge bases or attach metadata (department, customer) and filter on it for each request, based on who is asking.
- **Freshness.** The index only changes when you sync. Decide how often, and make "last synced" visible, so nobody trusts a stale answer.
- **Chunking.** Long policies and short tickets want different chunk sizes. Test with real questions before you load everything.
- **Quality.** Keep a set of questions with known answers and run it after every change of model, chunking or documents. Without it, "it seems better" is the only measure you have.
- **Fallback.** AWS's public sector example lets the system answer from the model's own knowledge when retrieval finds nothing. That widens coverage but invites confident answers with no source. For most internal tools, "I couldn't find that in our documents" is the safer reply.

## Cost and security notes

- You pay per token for embedding during each sync and for generation on every question. Long retrieved passages make every answer dearer, so retrieve fewer, better chunks.
- Price the vector store on its own, including what it costs when nobody is asking anything.
- Encrypt the bucket and index with KMS keys you control, turn on versioning for the source bucket, and give the service role only the bucket and index it needs.
- Log questions and answers with care: they may contain the very data you are protecting.

## When not to use RAG

- The answers are in a database. Querying it directly, or letting a model write the query, is more exact than retrieving text.
- You need the model to change how it writes or behaves, not what it knows. That is prompting or fine-tuning.
- The corpus is tiny. If it fits in the model's context window, you may not need retrieval at all.

## How to draw it in archhy

1. From the **Services** drawer (AWS pack), place an AWS Cloud and a Region, then two dotted boundaries from the **Draw** drawer: "Indexing" and "Answering".
2. Place S3, IAM and a Server for your app. Bedrock, OpenSearch, CloudWatch and KMS have no palette item of their own: use Generic Resources, each with a clear name; their official AWS icons are not in the palette.
3. Colour the indexing rails purple and the question path blue, and animate the question path, so readers see two flows, not one tangle.
4. Label the app's rail with the API name, "RetrieveAndGenerate", so developers know which call it is.
5. Add an info box to the knowledge base listing the embedding model, chunking and vector store, then download a PNG or SVG.

Related: [a governed data lake on AWS](https://archhy.com/blog/aws-data-lake-architecture) and [multi-tenant SaaS on AWS](https://archhy.com/blog/aws-multi-tenant-saas-architecture).

## Frequently asked questions

### What is RAG on AWS?

Retrieval-augmented generation: your app retrieves relevant passages from your own documents and gives them to a model on Amazon Bedrock with the question, so the answer is grounded in your content.

### Which vector database does Bedrock Knowledge Bases use?

Quick create sets up Amazon OpenSearch Serverless. You can also choose Amazon Aurora or supported third-party stores.

### Does a Bedrock knowledge base respect document permissions?

Not by itself. Use separate knowledge bases or metadata filters chosen per user to keep people to the documents they may see.

### How do I keep a RAG index up to date?

Sync the knowledge base when documents change, on a schedule or after uploads, and show users when it last synced.

*Based on:* Redrawn and discussed from [Add Retrieval Augmented Generation (RAG) to your .NET applications with Amazon Bedrock Knowledge Bases](https://aws.amazon.com/blogs/dotnet/add-retrieval-augmented-generation-rag-to-your-net-applications-with-amazon-bedrock-knowledge-bases/) by Jagadeesh Chitikesi, Ashish Bhatia and Ty Augustine (.NET on AWS Blog, 4 October 2024), with security and guardrail points from [Well-rounded technical architecture for a RAG implementation on AWS](https://aws.amazon.com/blogs/publicsector/well-rounded-technical-architecture-for-a-rag-implementation-on-aws/) (AWS Public Sector Blog, 19 February 2025). The diagram and commentary are archhy's own.
