DEV Community

Budiono Santoso
Budiono Santoso

Posted on

Amazon Bedrock : Knowledge Base and Agent

NOTE : Before try this tutorial, get Pinecone host key to can connect to Amazon Bedrock, then store Pinecone host key to AWS Secret Manager.

I want to create RAG (retrieval augmented generation) financial customer service and data analyst using Amazon Bedrock features such as Amazon Bedrock Knowledge Base and Agent.

First, go to Pinecone then create database index with several steps below.

  1. Create index.
    Create index

  2. Choose text embedding.
    Choose text embedding

  3. Text embedding configuration.
    Text embedding configuration

  4. Choose capacity mode and cloud provider. But for starter plan, can choose serverless and AWS only. Can't choose pods or another cloud provider such as Google Cloud and Azure.
    For starter plan, capacity mode serverless only and AWS as a cloud provider

  5. Also can't choose another region. Click Create index.
    Available region Virginia only then click Create index

My Pinecone database index for Amazon Bedrock Knowledge Base

Second, go to AWS Secret Manager then create Pinecone secret key with several steps below.

  1. Click store a new secret.
    AWS Secret Manager

  2. Choose "Other type of secret". Then fill key/value as a Pinecone API Key (must "apiKey" and your Pinecone API Key (I censored)).
    Pinecone API Key

  3. Create secret name and click Store.
    Secret name

  4. After create store, get secret ARN.
    Secret ARN

Finally, result of Bedrock Knowledge Base for RAG.

Knowledge base.
Knowledge base

Knowledge base overview.
Knowledge base overview

Embedding model using Amazon Titan Embedding and vector database using Pinecone.
Embedding model and vector database

Data source from Amazon S3.
Data source

Data source configuration.
Data source configuration

Sync all knowledge base.
Sync all knowledge base

Copy inference profile ARN. For this tutorial, copy US Nova Micro.
Inference profile ARN

Test knowledge base before deploy to Bedrock Agent.
Test knowledge base

Test knowledge base before deploy to Bedrock Agent.
Test knowledge base

But, if want to sync from another S3 bucket, how to sync? I explain this solution.

Go to IAM then click IAM role for Bedrock Knowledge Base like this. Click S3 policy.
IAM role for Bedrock Knowledge Base

This policy only can sync for "all-in-bedrock" S3 bucket. But if I want to sync another S3 bucket. Example I have S3 bucket name "bedrock-kb", can't sync because this S3 policy can't detect.

S3 policy

S3 policy

Edit S3 policy configuration like this screenshot for can sync all S3 bucket.
After edit S3 policy

Then, result of Bedrock Agent for RAG.

Bedrock Agent overview.
Bedrock Agent overview

Bedrock Agent detail.
Agent detail

Instruction for this agent using Amazon Nova Micro.
Instruction for this agent

Associate agent with knowledge base that already created.
Associate agent with knowledge base

Bedrock Agent version and alias
Image description

Copy inference profile ARN. For this tutorial, copy US Nova Micro.
Inference profile ARN

Test Bedrock Agent with scenario if a question is not related with knowledge base.
Test Bedrock Agent

Test Bedrock Agent with scenario if a question is related with knowledge base.
Test Bedrock Agent

I create all steps using boto3 SDK, you can see my Github for this tutorial.

Thank you,
Budi :)

Top comments (0)