Skip to content

Rodiel-Lezcano/aws-bedrock-genai-workshop

Repository files navigation

🧠 Amazon Bedrock GenAI Workshop

No-Code RAG Pipeline & AI Agent with Code Interpreter

AWS Bedrock OpenSearch S3 Claude GenAI


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


πŸ“‘ Table of Contents


πŸ—οΈ Architecture

  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚                       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)      β”‚ β”‚
  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“‹ Prerequisites

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

🎯 What You'll Build

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

πŸš€ Section 1.1 β€” Create a Vector Store with OpenSearch Serverless

🧱 Step 1: Create an OpenSearch Vector Collection

πŸ“Έ Expand for detailed steps
  1. Navigate to Amazon OpenSearch Service in the AWS Console
  2. On the left menu, go to Serverless β†’ Click Dashboard
  3. Click Get Started
  4. Enter the following:
Setting Value
Collection Name bedrock-sample-rag
Collection Type Vector Search
Deployment Type βœ… Enable Redundancy
Security βœ… Easy Create
  1. Click Next, then Submit to create the collection

🧲 Step 2: Create the Vector Index

πŸ“Έ Expand for detailed steps
  1. After the collection is created, go to the Indexes section
  2. Click Create Vector Index
  3. Choose JSON mode
  4. 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"
      }
    }
  }
}
  1. Name your index: bedrock-sample-rag-index
  2. Click Create

🧾 Important Metadata to Save

Property Value
Index Name bedrock-sample-rag-index
Vector Field Name vector
Metadata Fields text, text-metadata
Collection ARN Save this from Console

πŸ“‚ Section 1.2 β€” Upload Source Documents to Amazon S3

πŸ“Έ Expand for detailed steps
  1. Source documents (included in this repo):

    • AMZN-2019-Shareholder-Letter.pdf
    • AMZN-2020-Shareholder-Letter.pdf
    • AMZN-2021-Shareholder-Letter.pdf
    • AMZN-2022-Shareholder-Letter.pdf
  2. 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

🧠 Section 1.3 β€” Create a Bedrock Knowledge Base

πŸ“Έ Expand for detailed steps

Create the Knowledge Base

  1. Go to the Amazon Bedrock Console
  2. In the left panel, click Builder Tools β†’ Knowledge Bases
  3. Click Create β†’ choose Knowledge base with vector store
  4. IAM: Select Create and use a new service role

Configure Data Source

Setting Value
Source Amazon S3
S3 Bucket Select bucket from Section 1.2
Chunking Strategy Fixed-size chunking
Max Tokens 512

🧬 Embeddings Model

  1. Click Select Model.
  2. Choose: Amazon Titan Text Embeddings V2.
  3. Click Apply.

🧲 Vector Database Configuration

  • 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.

βœ… Finalize

  • 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.

πŸ§ͺ Section 1.4 β€” Test the Knowledge Base

πŸ“Έ Expand for detailed steps
  1. Go to your Knowledge Base in the Bedrock Console
  2. Click Test Knowledge Base
  3. Click Select Model β†’ Choose Anthropic Claude 3.5 Haiku β†’ Click Apply

Sample Query

What is Amazon doing in the field of generative AI?
  1. Click Run and review the response
  2. Click Show Details to inspect:
    • Extracted data chunks
    • Source metadata used for generation

πŸ”„ Section 1.5 β€” Build a RAG Flow with Bedrock Flows Visual Builder

Build a visual flow that connects your Knowledge Base to a prompt template for dynamic question answering.

πŸ“Έ Expand for detailed steps

Create the Flow

  1. Go to the Amazon Bedrock Console β†’ Click Flows.
  2. Click Create Flow.
  3. Enter Flow Name: langchain-kb-retriever
  4. Under Service role name, select Create and use a new service role.
  5. Click Create Flow.

🎯 Configure the Flow Builder

You'll now see 3 nodes: Flow input, Prompt, Flow output.

Add a Knowledge Base node from the menu.

Configure the Prompt Node

  1. Click the Prompt Node β†’ Select Model: Amazon Titan Nova Micro
  2. 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:
  1. Under Prompt Settings β†’ Change context input type to Array

Configure the Knowledge Base Node

  1. Select the Knowledge Base from Section 1.3
  2. Enable: βœ… Return retrieved results

Connect the Nodes

Flow input  ──▢  Prompt ({{question}})
Flow input  ──▢  Knowledge Base (retrieval query)
Knowledge Base  ──▢  Prompt ({{context}})
Prompt output  ──▢  Flow output

Click Save once connected.

Test the Flow

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.


πŸ€– Section 2 β€” Create a Bedrock Agent with Code Interpreter

Build an AI agent that can write, execute, and debug Python code to analyze data and generate visualizations.

Setup

πŸ“Έ Expand for detailed steps

1. Create the Agent

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

2. Agent Instructions

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.

3. Enable Code Interpreter

  • Expand Additional Settings
  • Toggle βœ… Code Interpreter
  • Ensure User Input is enabled

4. Save & Prepare

  • Click Save β†’ Click Prepare to activate the agent

Test 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

Additional Test Prompts

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

βœ… Workshop Complete

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

πŸ“š Resources

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

LinkedIn GitHub

About

No-code GenAI RAG project using Amazon Bedrock, OpenSearch, and S3 for retrieval-augmented question answering.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors