Build an end-to-end Retrieval-Augmented Generation (RAG) pipeline and a code-interpreting AI Agent using Amazon Bedrock β entirely through the AWS Console, no coding required.
π Workshop Source: AWS Bedrock Workshop
- Architecture
- Prerequisites
- What You'll Build
- Section 1 β RAG Knowledge Base Pipeline
- Section 2 β AI Agent with Code Interpreter
- Resources
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Amazon Bedrock β
β β
β βββββββββββββ ββββββββββββββββββ βββββββββββββββ β
β β Amazon S3 ββββββΆβ Knowledge Base ββββββΆβBedrock Flowsβ β
β β(Documents)β β(Titan Embed V2 β β(Visual RAG β β
β β β β + Sync/Ingest) β β Pipeline) β β
β βββββββββββββ βββββββββββ¬βββββββ βββββββββ¬ββββββ β
β β β β
β βΌ βΌ β
β βββββββββββββββββ ββββββββββββββ β
β β OpenSearch β β Foundation β β
β β Serverless β βModels β β
β β (Vector Store)β β(Claude + β β
β βββββββββββββββββ β Titan Nova)β β
β ββββββββββββββ β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Bedrock Agent β Code Interpreter (Python + Viz) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| Requirement | Details |
|---|---|
| AWS Account | With Amazon Bedrock access enabled |
| Model Access | Enable Claude 3.5 Haiku/Sonnet + Titan Text Embeddings V2 + Amazon Nova Micro in Model Access |
| IAM Permissions | Ability to create service roles, S3 buckets, OpenSearch collections |
| Source Documents | Included in this repo β AMZN-*-Shareholder-Letter.pdf |
| Component | AWS Services | Purpose |
|---|---|---|
| Vector Store | OpenSearch Serverless | Store document embeddings for semantic search |
| Knowledge Base | Bedrock + S3 + Titan Embeddings V2 | Ingest, chunk, and embed documents for RAG |
| RAG Pipeline | Bedrock Flows Visual Builder | Chain KB retrieval β prompt β model response |
| AI Agent | Bedrock Agent + Code Interpreter | Analyze data and generate Python visualizations |
πΈ Expand for detailed steps
- Navigate to Amazon OpenSearch Service in the AWS Console
- On the left menu, go to Serverless β Click Dashboard
- Click Get Started
- Enter the following:
| Setting | Value |
|---|---|
| Collection Name | bedrock-sample-rag |
| Collection Type | Vector Search |
| Deployment Type | β Enable Redundancy |
| Security | β Easy Create |
- Click Next, then Submit to create the collection
πΈ Expand for detailed steps
- After the collection is created, go to the Indexes section
- Click Create Vector Index
- Choose JSON mode
- Use the following configuration:
{
"settings": {
"index.knn": "true",
"number_of_shards": 1,
"knn.algo_param.ef_search": 512,
"number_of_replicas": 0
},
"mappings": {
"properties": {
"vector": {
"type": "knn_vector",
"dimension": 1024,
"method": {
"name": "hnsw",
"engine": "faiss",
"space_type": "l2"
}
},
"text": {
"type": "text"
},
"text-metadata": {
"type": "text"
}
}
}
}- Name your index:
bedrock-sample-rag-index - Click Create
| Property | Value |
|---|---|
| Index Name | bedrock-sample-rag-index |
| Vector Field Name | vector |
| Metadata Fields | text, text-metadata |
| Collection ARN | Save this from Console |
πΈ Expand for detailed steps
-
Source documents (included in this repo):
AMZN-2019-Shareholder-Letter.pdfAMZN-2020-Shareholder-Letter.pdfAMZN-2021-Shareholder-Letter.pdfAMZN-2022-Shareholder-Letter.pdf
-
Create an S3 bucket and upload all 4 documents
| Setting | Recommendation |
|---|---|
| Bucket Name | bedrock-kb-<your-name>-lab (must be globally unique) |
| Region | Same region as your OpenSearch collection |
πΈ Expand for detailed steps
- Go to the Amazon Bedrock Console
- In the left panel, click Builder Tools β Knowledge Bases
- Click Create β choose Knowledge base with vector store
- IAM: Select Create and use a new service role
| Setting | Value |
|---|---|
| Source | Amazon S3 |
| S3 Bucket | Select bucket from Section 1.2 |
| Chunking Strategy | Fixed-size chunking |
| Max Tokens | 512 |
- Click Select Model.
- Choose: Amazon Titan Text Embeddings V2.
- Click Apply.
- Choose the previously created OpenSearch vector store.
- Ensure Vector engine for Amazon OpenSearch is selected.
| Property | Value |
|---|---|
| Collection ARN | (Use ARN from Section 1.1) |
| Vector Index Name | bedrock-sample-rag-index |
| Vector Field Name | vector |
| Text Field Name | text |
| Metadata Field Name | text-metadata |
Click Next to continue.
- In the Review and Create section, click Create Knowledge Base.
- After itβs created, go to the Data Sources tab.
- Select your source and click Sync to ingest documents into the knowledge base.
πΈ Expand for detailed steps
- Go to your Knowledge Base in the Bedrock Console
- Click Test Knowledge Base
- Click Select Model β Choose Anthropic Claude 3.5 Haiku β Click Apply
What is Amazon doing in the field of generative AI?
- Click Run and review the response
- Click Show Details to inspect:
- Extracted data chunks
- Source metadata used for generation
Build a visual flow that connects your Knowledge Base to a prompt template for dynamic question answering.
πΈ Expand for detailed steps
- Go to the Amazon Bedrock Console β Click Flows.
- Click Create Flow.
- Enter Flow Name:
langchain-kb-retriever - Under Service role name, select Create and use a new service role.
- Click Create Flow.
You'll now see 3 nodes: Flow input, Prompt, Flow output.
Add a Knowledge Base node from the menu.
- Click the Prompt Node β Select Model: Amazon Titan Nova Micro
- Paste the following prompt template:
Human: You are a financial advisor AI system, and provide answers to questions using fact-based and statistical information when possible.
Use the following pieces of information to provide a concise answer to the question enclosed in <question> tags.
If you don't know the answer, just say that you don't know; don't try to make up an answer.
<question>
{{question}}
</question>
The response should be specific and use statistics or numbers when possible.
Context: {{context}}
A:
- Under Prompt Settings β Change
contextinput type to Array
- Select the Knowledge Base from Section 1.3
- Enable: β Return retrieved results
Flow input βββΆ Prompt ({{question}})
Flow input βββΆ Knowledge Base (retrieval query)
Knowledge Base βββΆ Prompt ({{context}})
Prompt output βββΆ Flow output
Click Save once connected.
Use the Test Panel with this query:
What is Amazon doing in the field of generative AI?
Review the trace across nodes to confirm each step works correctly.
Build an AI agent that can write, execute, and debug Python code to analyze data and generate visualizations.
πΈ Expand for detailed steps
| Setting | Value |
|---|---|
| Name | DataAnalysisAssistant |
| Description | AI Agent with Code Interpreter enabled for Data analysis |
| Model | Claude 3.5 Sonnet v2 |
| Service Role | Create and use a new service role |
You are an AI assistant specialized in data analysis and visualization.
You can write, run, and debug Python code to help users with their queries.
Always provide clear explanations of your process and results.
- Expand Additional Settings
- Toggle β Code Interpreter
- Ensure User Input is enabled
- Click Save β Click Prepare to activate the agent
In the test panel, paste this prompt:
π Sample prompt with hotel satisfaction data
Using the customer satisfaction data provided below, create a bar graph
showing the average overall rating for each hotel (H001, H002, H003).
The graph should have the hotel IDs on the x-axis and the average overall
rating on the y-axis.
date,hotel_id,overall_rating,room_cleanliness,staff_service,amenities,value_for_money,location
2023-01-05,H001,4.2,4.5,4.0,3.8,4.1,4.5
2023-01-12,H002,3.8,4.0,3.5,3.9,3.7,4.2
2023-01-20,H003,4.5,4.7,4.6,4.3,4.2,4.8
2023-02-03,H001,3.9,4.2,3.7,3.6,3.8,4.4
2023-02-15,H002,4.1,4.3,4.0,4.1,3.9,4.3
2023-02-28,H003,4.3,4.5,4.4,4.2,4.0,4.6
2023-03-10,H001,4.0,4.3,3.8,3.7,3.9,4.5
2023-03-22,H002,3.7,3.9,3.6,3.8,3.5,4.1
2023-04-05,H003,4.4,4.6,4.5,4.1,4.1,4.7
2023-04-18,H001,4.1,4.4,3.9,3.8,4.0,4.6
2023-05-01,H002,3.9,4.1,3.8,4.0,3.6,4.2
2023-05-15,H003,4.6,4.8,4.7,4.4,4.3,4.9
2023-06-02,H001,4.3,4.6,4.1,4.0,4.2,4.7
2023-06-20,H002,4.0,4.2,3.9,4.1,3.8,4.3
2023-06-30,H003,4.5,4.7,4.6,4.3,4.2,4.8
| Prompt | Tests |
|---|---|
| Create a heatmap showing correlation between satisfaction factors and overall rating | Data visualization |
| Calculate average scores for each satisfaction factor across all hotels | Data aggregation |
| Identify the hotel with the highest average rating and show its factor scores | Filtering + analysis |
| Create a line graph showing the trend of overall ratings over time | Time series |
You've built two end-to-end GenAI experiences using Amazon Bedrock, entirely through the console:
| Experience | Components |
|---|---|
| RAG Pipeline | S3 β Titan Embeddings β OpenSearch β Knowledge Base β Flows β Claude/Titan |
| AI Agent | Bedrock Agent + Code Interpreter β Python analysis + visualizations |
| Resource | Link |
|---|---|
| Amazon Bedrock Docs | docs.aws.amazon.com/bedrock |
| OpenSearch Service | docs.aws.amazon.com/opensearch-service |
| Knowledge Bases Guide | Knowledge Base Documentation |
| Bedrock Agents Guide | Agents Documentation |
| Original Workshop | catalog.workshops.aws |
Built by Rodiel Lezcano Β· Solutions Architect