rag on aws · build guide

How to build a RAG system on AWS.

Retrieval-augmented generation (RAG) makes a model answer from your own documents. On AWS, start with Amazon Bedrock Knowledge Bases: point it at S3 and it chunks, embeds, stores and retrieves for you, then returns cited answers. Build your own pipeline only when you need custom chunking, hybrid search or strict multi-tenant access control.

pipeline stages
7
build paths
2
managed RAG service
Bedrock KB
TL;DR
  • RAG grounds a model in your data. You embed your documents into a vector store, retrieve the most relevant chunks for each question, and pass them to the model as context. The pipeline is ingest, chunk, embed, store, retrieve, re-rank, generate.
  • Two ways to build it. Managed: Bedrock Knowledge Bases runs chunking, embedding, storage, retrieval and re-ranking behind the Retrieve and RetrieveAndGenerate APIs. DIY: you run each stage yourself on Bedrock plus a vector store you control.
  • Quality is won in retrieval: parsing, chunking, the embedding model, hybrid search and re-ranking. Measure faithfulness, answer relevance and context precision and recall on a fixed question set.
  • Funding: if the build qualifies, a vetted AWS partner can file POC funding for a test, or incremental workload (IW) funding if you already run on AWS. For startups this is typically $50K to $150K. Depends on the workload; AWS approves. You apply for Activate credits yourself.
the core idea

IWhat RAG is, and the problem it solves

RAG is a pattern, not a product. Before the model answers, you retrieve the most relevant passages from your own data and put them in the prompt. The model answers from those passages instead of from memory alone.

A foundation model only knows its training data, frozen at a cutoff date. It knows nothing about your wiki, tickets, contracts or last night's product change, and if you ask, it may invent an answer. RAG separates knowledge from reasoning. The model does the language and reasoning; the facts come from data you control and can update at any time.

Offline, you split documents into chunks, turn each chunk into a vector with an embedding model, and store the vectors. At query time, you embed the question with the same model, find the nearest chunks, optionally re-rank them, and put the best ones in the prompt with an instruction such as "answer only from the context below and cite the passage you used."

You get three things. Freshness: update a document and the next answer reflects it, with no retraining. Citations: users can check the source. Governance: you decide what is in the corpus and who can retrieve what. Fine-tuning bakes knowledge into weights, is costly to update, gives no citations and cannot enforce per-user access. Use RAG for knowledge; use fine-tuning for style or a narrow skill.

end to end

IIThe reference RAG architecture on AWS, stage by stage

Every RAG system, managed or DIY, runs the same seven stages. Most quality problems trace back to one of them.

Indexing: ingest, chunk, embed, store

1. Ingest. Land documents in Amazon S3 from your wiki, CRM, ticketing system or database exports. PDFs, HTML and Word files need clean text extraction (Amazon Textract helps with scans and tables). Messy extraction is the most common silent cause of bad answers.

2. Chunk. Split documents into passages small enough to embed precisely and large enough to carry meaning. A common starting point is 300 to 800 tokens with 10 to 20% overlap. Tune it on your data.

3. Embed. Turn each chunk into a vector with Amazon Titan Text Embeddings V2 or Cohere Embed on Bedrock. Change the embedding model later and you must re-embed everything.

4. Store. Write each vector, its text and its metadata (document ID, title, access tags, timestamps) to a vector store. Options are in section IV.

Query: retrieve, re-rank, generate

5. Retrieve. Embed the question with the same model and fetch the nearest chunks, often 10 to 50 at this stage. Hybrid retrieval (vectors plus keyword search) usually beats vectors alone, because it catches exact terms, product names and acronyms.

6. Re-rank. A re-ranker (Amazon Rerank or Cohere Rerank on Bedrock) scores each candidate against the question and keeps the best few. It is often the biggest single quality gain.

7. Generate. Send the instruction, the re-ranked chunks and the question to a model on Bedrock (Claude, Amazon Nova, Llama, Mistral). Ask it to answer only from the context and to cite sources, and show those citations to the user.

the seven RAG stages mapped to AWS services
StagePhaseWhat it doesTypical AWS service
1. IngestIndexingLand and parse documentsAmazon S3, Textract
2. ChunkIndexingSplit into passagesBedrock KB built-in, or Lambda or Glue (DIY)
3. EmbedIndexingText to vectorsTitan Text Embeddings V2, Cohere Embed (Bedrock)
4. StoreIndexingIndex vectors and metadataOpenSearch Serverless, Aurora pgvector, S3 Vectors, Pinecone and others
5. RetrieveQueryFind the nearest chunksVector store query, plus keyword search for hybrid
6. Re-rankQueryKeep the best few chunksAmazon Rerank, Cohere Rerank (Bedrock)
7. GenerateQueryAnswer with citationsClaude, Nova, Llama, Mistral (Bedrock)
Bedrock Knowledge Bases runs stages 2 to 6 behind two API calls (Retrieve and RetrieveAndGenerate). A DIY pipeline builds each stage. Both use the same Bedrock models.
the central decision

IIITwo paths: Bedrock Knowledge Bases or DIY

Start managed. Move a stage to DIY only when a specific requirement forces it.

Path A: Amazon Bedrock Knowledge Bases (managed)

Point a knowledge base at S3 or a connector (web crawler, Confluence, Salesforce, SharePoint), pick an embedding model and a vector store, and Bedrock handles ingestion, chunking, embedding, indexing, retrieval and optional re-ranking. Call Retrieve for chunks or RetrieveAndGenerate for a cited answer. It syncs changed documents, returns citations and works with Bedrock Guardrails.

Choose it when you want to ship fast, your documents live in S3 or a supported source, the built-in chunking (fixed, semantic or hierarchical) is good enough, and you do not need unusual retrieval logic. That covers most internal-knowledge and support use cases.

Path B: a DIY pipeline (Bedrock plus your own vector store)

You still call Bedrock for embeddings and generation, but you own every other stage: parser, chunker (Lambda, Glue or Step Functions), writes to the vector store, retrieval and hybrid search, re-ranking and prompt assembly. LangChain or LlamaIndex are common but optional.

Choose it when you need document-aware chunking, hybrid search with your own score fusion, row-level or strict multi-tenant access control, an existing vector store, or tight cost and latency tuning. The cost is more engineering time and upkeep.

the practical rule

Prototype on Bedrock Knowledge Bases to prove the use case and get baseline quality. Move a stage to DIY only when a concrete requirement forces it. Many production systems mix both: a knowledge base for the bulk corpus, DIY for one demanding source.

where the vectors live

IVVector store options on AWS

The vector store holds your embeddings and answers nearest-neighbour queries. The right one depends on how you operate, your cost shape and your scale.

Bedrock Knowledge Bases can use Amazon OpenSearch Serverless, OpenSearch Service managed clusters, Amazon S3 Vectors, Amazon Aurora PostgreSQL (pgvector), Neptune Analytics (for GraphRAG), Pinecone, Redis Enterprise Cloud and MongoDB Atlas. A DIY pipeline can use any of these, plus stores such as Amazon MemoryDB. The current list is in the Bedrock user guide.

OpenSearch Serverless is the common default. It does vector and keyword search in one engine, so hybrid retrieval is built in, but it bills by capacity units with a baseline, which can feel high for a small corpus. Aurora PostgreSQL with pgvector suits teams already on Postgres: vectors sit next to your relational data and you filter with SQL. S3 Vectors targets large vector sets that are queried less often, at lower storage cost. Pinecone is a vector-only managed service from a third party. In-memory stores such as MemoryDB fit retrieval where latency matters most, at a higher cost per GB.

common vector stores for RAG on AWS
Vector storeHybrid searchBest fitWatch out for
OpenSearch ServerlessBuilt in (vector and keyword)Default for Bedrock KB; one engine for bothBaseline cost on small corpora
Aurora PostgreSQL (pgvector)Vector plus SQL filtersTeams already on PostgresSpecialist engines win at very high scale
Amazon S3 VectorsVector plus metadata filtersLarge, less-queried vector setsHigher query latency than in-memory stores
PineconeVector plus metadata filtersVector-first workloads with little tuningSeparate vendor and contract
MemoryDB (DIY)Vector plus filtersLowest-latency retrievalMemory pricing on large indexes
Check each store's pricing page before you commit. pgvector is the least new infrastructure if you already run Postgres; OpenSearch Serverless is the least setup inside Bedrock Knowledge Bases.
the quality knobs

VEmbeddings, chunking and re-ranking

If the right chunk never reaches the prompt, no model can answer well. Three knobs matter most.

Embedding model: Titan or Cohere

Amazon Titan Text Embeddings V2 is AWS-native, low cost and lets you choose output dimensions (256, 512 or 1,024); smaller vectors save storage and speed search at a small recall cost. Cohere Embed (English and multilingual) is a common pick for multilingual corpora. Two rules matter more than the winner: embed queries and documents with the same model and version, and benchmark on your own questions before you commit, because switching later means re-embedding everything.

Chunking

Chunks that are too large blur the embedding and waste tokens; chunks that are too small lose context. Start around 300 to 800 tokens with some overlap, then tune. Split on headings, keep tables and code blocks whole, and store the section title in metadata. For long technical or legal documents, hierarchical chunking (retrieve small child chunks, send the larger parent to the model) is one of the most reliable upgrades. Bedrock Knowledge Bases offers fixed, semantic and hierarchical chunking.

Re-ranking

Vector search is fast but approximate. A re-ranker reads the question and each candidate together and scores real relevance. Retrieve a wide set cheaply, then re-rank and keep the best few. Amazon Rerank and Cohere Rerank are on Bedrock, and Knowledge Bases can apply re-ranking for you. You get better answers and fewer input tokens.

the debugging order

When answers are bad, check retrieval before generation: (1) is the right chunk in the index? (2) does it come back in the wide candidate set? (3) does it survive re-ranking? (4) only then, is the prompt or model the problem? Most RAG quality issues are retrieval problems.

measuring it

VIEvaluating a RAG system

A demo is not an evaluation. Use metrics that separate retrieval problems from generation problems.

Build a fixed set of real questions with correct answers and, ideally, the source passage. Run it on every change. Amazon Bedrock includes RAG evaluation that uses a model as a judge to score retrieval and answers; open-source tools such as Ragas do the same for DIY pipelines.

  • Faithfulness: Does the answer follow from the retrieved context? Low faithfulness with good context is a prompt or model problem.
  • Answer relevance: Does the answer address the question that was asked?
  • Context precision: How many retrieved chunks were relevant? Low precision means a noisy retriever: add re-ranking or hybrid search.
  • Context recall: Did retrieval find everything needed? Low recall means fix chunking, the embedding model, the candidate count or hybrid search.

In production, log every query with its retrieved chunks and answer, and have a person review a sample. Automated judges miss domain errors an expert catches at once.

shipping it

VIIProduction: freshness, access control, latency and cost

Four things rarely show up in a prototype and always show up in production.

  • Freshness: Knowledge Bases can sync changed documents; in DIY, re-embed on S3 events or a schedule. Set a freshness target per source and keep a timestamp in each chunk's metadata.
  • Access control: Enforce it in retrieval, not after generation. Tag each chunk with user, group or tenant metadata and filter every query. Knowledge Bases supports metadata filters; DIY stores support them too. For multi-tenant SaaS, filter by tenant at least, or use separate indexes.
  • Latency: Generation usually dominates, so stream the response. Keep the re-ranked context short.
  • Cost: Route easy questions to a smaller model, pass fewer chunks, use prompt caching for a static system prompt, and run offline generation as batch, which AWS prices 50% below on-demand for select models. Size the vector store to the corpus, since you pay for it with or without traffic.
before launch

A fixed evaluation set in CI · citations on every answer · access filters on every retrieval · a freshness target per source · Guardrails on inputs and outputs · query, context and answer logging · streaming · billing alarms.

what people build

VIIICommon RAG apps on AWS: chatbots, document Q&A, voice

Most GenAI assistants are RAG underneath. The differences are the sources, the channel and the controls.

  • Support chatbot: Retrieve from your help center and resolved tickets, ground answers with citations, add a Guardrail, and hand off to a person when the model is unsure or the customer asks.
  • Document Q&A: Answer questions over contracts, policies or reports. Use hierarchical chunking for long documents, filter by who may see each document, and always show the source passage.
  • Internal knowledge assistant: Connect the wiki, Confluence or SharePoint through Knowledge Bases connectors, and filter by team or group.
  • Voice assistant: Add speech in front of the same pipeline: Amazon Transcribe for speech to text and Amazon Polly for text to speech, or a speech model on Bedrock. Keep answers short and stream them to cut perceived latency.
the build, in order

IXA step-by-step build (managed path)

The fastest credible path to a cited RAG system on AWS. A DIY build follows the same order.

  • Step 1: stage the corpus in S3: Land documents in S3 and extract clean text first (Textract for scans and tables).
  • Step 2: check model access: Access to many Bedrock models is on by default. The first call to a third-party model needs AWS Marketplace permissions, and Anthropic models need a one-time use-case form.
  • Step 3: create the Knowledge Base: Point it at the bucket, pick an embedding model and a vector store, and start with semantic or hierarchical chunking.
  • Step 4: sync and inspect: Run ingestion, then use the Retrieve API on a handful of known questions. Fix parsing and chunking before anyone sees an answer.
  • Step 5: wire RetrieveAndGenerate: Instruct the model to answer only from context and cite sources. Turn on re-ranking, attach a Guardrail and show citations in the UI.
  • Step 6: add access control and freshness: Tag chunks with access metadata, filter every query and turn on incremental sync.
  • Step 7: evaluate and iterate: Score faithfulness, relevance, precision and recall with Bedrock RAG evaluation. Tune chunk size, candidate count and re-ranking against the numbers. Add logging and human review before scaling traffic.
what it costs

XWhere the money goes in a RAG system

A RAG bill has five lines. Generation is usually the largest, then the vector store baseline. Check the AWS pricing pages for current rates.

the RAG cost lines on AWS
Cost lineWhen you payMain lever
Embeddings (indexing)Once per corpus, then on updatesChunk size, smaller dimensions, re-embed only changed documents
Vector storeContinuouslyRight-size the engine; use pgvector if Postgres already runs
Query embeddingsPer querySmall per call; cache repeated questions
Re-rankingPer queryRe-rank a modest candidate set; skip trivial queries
GenerationPer query, usually the largestSmaller model for easy questions, fewer chunks, prompt caching, a max-token limit
Prompt caching and re-ranking down to a few tight chunks cut the generation line the most. See <a href="https://aws.amazon.com/bedrock/pricing/">Bedrock pricing</a>.
who pays for it

XIWho files AWS funding for a RAG build

A partner files one kind of AWS funding. You apply for the other.

Partner-filed funding. If the build qualifies, your matched AWS partner can file POC (proof of concept) funding to test the use case, or incremental workload (IW) funding if you already run on AWS and are launching new work such as an AI assistant. If you are moving to AWS from another cloud, it can file MAP migration funding. For startups this is typically $50K to $150K. Depends on the workload; AWS approves. See AWS partner funding.

AWS Activate credits. You apply yourself at aws.amazon.com/startups/credits: Activate Founders gives $1,000 to start, up to $5,000; Activate Portfolio gives up to $200,000 with an Org ID from your VC, accelerator or angel group if it is an Activate Provider. A consulting partner cannot file Activate for you.

If your team can build RAG and you only need Activate credits, apply yourself; you do not need a partner. A partner helps when you want the build done with you, or when the work qualifies for funding only a partner can file.

side by side

Bedrock Knowledge Bases vs DIY RAG

Default to managed. Move a stage to DIY only when a row in the right column is a hard requirement.

DimensionBedrock Knowledge BasesDIY (Bedrock plus your stack)
Time to first answerFast: point at S3, sync, call an APISlower: build every stage
Pipeline you maintainAlmost noneAll of it
ChunkingFixed, semantic or hierarchical presetsAnything, fully custom
Retrieval logicManaged retrieval, optional re-rank, metadata filtersCustom hybrid search and score fusion
Access controlMetadata filtersAnything: row-level, per tenant, external policy engine
Vector storeThe supported list in the Bedrock user guideAny store
Cost controlLess granularTune every stage
Best forMost internal-knowledge and support use casesCustom chunking, hybrid search, strict multi-tenancy, cost squeeze
Both paths call the same Bedrock models. The difference is who runs the stages in between.
building this for real?
Get matched with an AWS partner that builds RAG on Bedrock, and ask if your build qualifies for POC or IW funding.
Get matched free with a vetted AWS partner who can file it
how a match works

How a match works (example)

  1. You tell us about the work

    You fill in a short form: what you run today, what you want to move, test or build, your stage and your region.

  2. We pick one partner

    We read your answers and pick one vetted AWS consulting partner that fits the work, the stack and the region. We reply within 24 hours; your matched partner reaches out within 5 business days.

  3. The partner checks POC funding

    Your matched partner scopes the test with you. Then it checks whether the test qualifies for POC (proof of concept) funding. A POC can fit whether or not you run on AWS today.

  4. The partner files, AWS decides

    If the work qualifies, the partner files the funding request with AWS. AWS reviews it and decides. The amount depends on the workload.

  5. You pay nothing

    CloudRoute is free for startups. Partners pay CloudRoute a monthly membership plus 10% of AWS-approved funding.

AWS Activate credits are separate, and you apply for them yourself. Use Activate Founders if no investor backs you. Use Activate Portfolio with the Org ID or invite from your VC, accelerator, incubator or angel group if it is an Activate Provider. A consulting partner cannot apply for Activate on your behalf.

faq

Common questions

What is the difference between RAG and fine-tuning on AWS?
RAG retrieves your data at query time and gives it to the model as context, so you update knowledge by editing documents, get citations and can enforce per-user access. Fine-tuning changes the model's weights; it suits a format, tone or narrow skill, but it is costly to update and gives no citations. Use RAG for facts; many systems add light fine-tuning for behavior.
Should I use Amazon Bedrock Knowledge Bases or build my own RAG pipeline?
Start with Bedrock Knowledge Bases. It handles ingestion, chunking, embedding, storage, retrieval and re-ranking, and RetrieveAndGenerate returns cited answers. Build your own pipeline only for a concrete need: document-aware chunking, hybrid search with your own score fusion, strict multi-tenant or row-level access, an existing vector store, or tight cost tuning.
Which vector store should I use for RAG on AWS?
OpenSearch Serverless is the common default inside Bedrock Knowledge Bases and does hybrid search natively, though its baseline cost is noticeable on small corpora. Aurora PostgreSQL with pgvector is the least new infrastructure if you run Postgres. S3 Vectors suits large, less-queried vector sets. Pinecone, Redis Enterprise Cloud and MongoDB Atlas are also supported by Knowledge Bases. Check the Bedrock user guide for the current list.
Which embedding model is better: Amazon Titan or Cohere?
Both run on Bedrock. Titan Text Embeddings V2 is low cost and lets you pick output dimensions. Cohere Embed is a common choice for multilingual corpora. Benchmark on your own questions, embed queries and documents with the same model, and treat the choice as semi-permanent, because switching means re-embedding the corpus.
How do I stop a RAG system from hallucinating?
Debug retrieval first: is the right chunk in the index, does it come back as a candidate, does it survive re-ranking? Then tell the model to answer only from context and to say it does not know when the context lacks the answer, pass only re-ranked chunks, return citations, attach a Guardrail, and track faithfulness on a fixed question set.
How do I make sure users only see documents they are allowed to see?
Enforce access in retrieval, never as a filter on the finished answer. Tag every chunk with user, group or tenant metadata at index time and apply a metadata filter on every query. Bedrock Knowledge Bases and the common vector stores all support this. For multi-tenant SaaS, filter by tenant at least, or use separate indexes.
What does RAG on AWS cost?
Five lines: embedding the corpus, the vector store baseline, query embeddings, re-ranking and generation, which is usually the largest. Cut generation with a smaller model for easy questions, fewer re-ranked chunks, prompt caching and batch for offline work. Size the vector store to your corpus. Check current rates on the AWS pricing pages.
Who files AWS funding for a RAG build?
If the build qualifies, your matched AWS partner files POC funding for a test, or incremental workload (IW) funding for new work on AWS. For startups this is typically $50K to $150K. Depends on the workload; AWS approves. You apply for AWS Activate credits yourself; a consulting partner cannot file them. CloudRoute matches you with a partner for free.

Build your RAG on AWS with a partner who can file the funding.

CloudRoute matches you with one vetted AWS partner that builds RAG on Bedrock: Knowledge Bases or a custom pipeline, the vector store, re-ranking, access control and evaluation. If the build qualifies, the partner files POC or incremental workload (IW) funding, typically $50K to $150K for startups. Depends on the workload; AWS approves. CloudRoute is free for startups.

partner-filed funding, if AWS approves$50K to $150K
routes a partner can fileMAP · POC · IW
CloudRoute fee for startups$0