Reference · How-to · ~10 min

How to sketch RAG on AWS Bedrock

Last updated

Combine Bedrock embeddings, a vector store, and `InvokeModel` for a private-cloud RAG loop.

Combine Bedrock embeddings, a vector store, and `InvokeModel` for a private-cloud RAG loop.

#Steps

1. **Enable models** — Titan Embeddings + Claude or Llama chat model in Bedrock console

2. **Embed chunks** — `bedrock-runtime` `InvokeModel` with Titan embedding payload

3. **Store vectors** — OpenSearch Serverless, pgvector, or Pinecone in your VPC

4. **Retrieve** — similarity search on query embedding, top-k with metadata filters

5. **Generate** — `InvokeModel` on Claude with retrieved context in the user message

6. **Cite sources** — include chunk IDs or filenames in the prompt template

7. **Log** — request ID, model ID, retrieved chunk hashes for audit

#Sketch

import boto3
br = boto3.client("bedrock-runtime", region_name="us-east-1")
response = br.invoke_model(
    modelId="anthropic.claude-3-5-sonnet-20241022-v2:0",
    body=json.dumps({"messages": [{"role": "user", "content": prompt_with_chunks}]}),
)

#Watch out

IAM policies, region, and model access differ per account — test in a sandbox before production traffic.

**Try the lessons:** `build-mini-rag` · [API: Bedrock invoke](/reference/api/bedrock-invoke)