Generative AI is no longer a buzzword. It has become an integral part of our everyday conversations. Typically, new technologies spark excitement within the technical circle; however, Generative AI transcended that boundary and quickly became mainstream. Enterprises are also exploring its practical applications from a business perspective. You can love it or hate it, but one thing is clear - you can't ignore it. So I decided to try it myself. This blog post is about my experimentation with Amazon Bedrock's capabilities.
Let's use the example of building a RewardBot to illustrate the process, and if you're interested in learning how to build a chatbot using AWS services then this blog post is perfect for you.
Retail Rewards Inc., a fictitious retail company, is taking generative AI to its customers. The functionalities of the first version of RewardBot for customers are to become loyalty card members, check their loyalty card balance, and help them fully understand the benefits of the loyalty program. Our goal is to create a pilot that we can iterate and improve over time.
Key Features of RewardBot:
Membership Enrollment: Guide users through the process of becoming loyalty card members.
Balance Inquiry: Allow users to check their loyalty card balance in real-time.
FAQs and Support: Provide answers to common questions and support for loyalty program issues.
Membership Enrollment feature will be launched in next version.
Now that we’ve set the stage, it’s time to dive deeper into the technical details of our Generative AI Assistant. First, let's look at few important concepts-
Retrieval-Augmented Generation (RAG)
Imagine you're asking a large language model a question. Generally, it would just give you an answer based on what it's learned from its training data. However, it won't know anything about your customer data, or about your business policies around loyalty reward programs. That's where Retrieval-Augmented Generation (RAG) comes in. It is a technique to leverage your enterprise-specific data to enhance the responses of large language models (LLMs) without retraining a model.
Knowledge Bases for Amazon Bedrock
Amazon Bedrock Knowledge Bases are centralized repositories for structured and unstructured data, allowing AI models to access up-to-date information. They enhance the accuracy of AI responses without needing frequent retraining.
In a retail company's Loyalty Reward System, an FAQ document stored in Amazon S3 can be part of the knowledge base. When a customer asks the AI assistant a policy question, it retrieves the relevant information from this document to provide an accurate answer.
Agents for Amazon Bedrock
Agents for Amazon Bedrock plan and execute multistep tasks and help orchestrate interactions between foundation models, knowledge bases, and Lambda functions to securely execute APIs. An agent analyzes the user request and automatically calls the necessary APIs and data sources to fulfill the request. Thus, agents reduce significant development efforts for developers and speed up generative AI application deployments.
System Architecture:
Select Agents under "Builder tools" on the left and click "Create Agent".
Create a new or choose existing agent IAM role. Select model and provide agent instructions.
Test agents with prompts
You can click on 'show trace' to understand the trace of the agent's actions.
Step2. Create a Knowledge Base
The Knowledge Base is a repository of information that the Bedrock agent will use to respond to user queries. This can include FAQs, documentation, and other relevant data.
Steps to Create a Knowledge Base:
- Knowledge base in this case would be used to host the Loyalty Program FAQ file. So, first create an S3 bucket and upload the FAQ document to it. I'll provide the Git repo for all the files and code used in this tutorial.
Vector Database:
Step3: Associate Knowledge Base with the agent
Associate the Knowledge Base with the agent to enable the agent to leverage its contents for more accurate and context-aware interactions.
If you noticed, both queries are answered based on the knowledge base. Therefore, the response to the second query is general information from the FAQ document and not tailored to the customer's account.
Step4: Create an action group
Bedrock Action Group defines specific tasks an agent can perform to help users, like managing loyalty points or answering account questions.
Steps to Create an action group:
- Click "Edit in Agent Builder" and go to the action group section.
1.3 Lambda function which agent will invoke through an action group. This is a function (action-grp-business-function) where business logic is written to pull loyalty points balance for a user based on UserID.
I'll provide Git repository for OpenAPI specification file and the Lambda code.
One important consideration is, the resource permission for the agent and Bedrock service to invoke this lambda function.
On Lambda function console page -
OK, Let's get back to Action group creation with OpenAPI specification file and Lambda function ready for us.
Also ensure, Lambda Execution role has access to DynamoDB table. I have given full access to DynamoDB to simplify (AmazonDynamoDBFullAccess).
Optionally, you can go back to agent page and create an Alias.
An alias points to a specific version of your Agent.
Let's check our prompts again -
API Gateway
API: REST API GenAIService with Lambda Integration
Resource: getloyaltypoints (path /)
Method: GET.
The most of the settings used are default except below changes -
Method request
{
"prompt":"$input.params('prompt')",
"session_id":"$input.params('session_id')"
}
Using postman to invoke API /getloyaltypoints.
SOCIAL SHARE CARD GENERATOR