Generative AI Serverless - RAG using Bedrock Knowledge base, & Single document chat via AWS Console!
Tags: aws, bedrock, anthropic, generativeai
Published: 2024-05-29 21:56:46

Generative AI - Has Generative AI captured your imagination to the extent it has for me?
 
Generative AI is indeed fascinating! The advancements in foundation models have opened up incredible possibilities. Who would have imagined that technology would evolve to the point where you can generate content summaries from transcripts, have chatbots that can answer questions on any subject without requiring any coding on your part, or even create custom images based solely on your imagination by simply providing a prompt to a Generative AI service and foundation model? It's truly remarkable to witness the power and potential of Generative AI unfold.
 
**'Chat with your document' is the latest Generative AI feature added by Amazon to its already feature-rich areas of GenAI, Knowledge Base, and RAG.**
 
RAG, which stands for Retrieval Augmented Generation, is becoming increasingly popular in the world of Generative AI. It allows organizations to overcome the limitations of LLMs and utilize contextual data for their Generative AI solutions.
 
Amazon Bedrock is a fully managed service that offers a choice of many foundation models, such as Anthropic Claude, AI21 Jurassic-2, Stability AI, Amazon Titan, and others.
 
I will use the recently released Anthropic Sonnet foundation model and invoke it via the Amazon Console Bedrock Knowledge Base. As of May 2024, this is the only model supported by AWS for the single document knowledge base or 'Chat with your document' function.
 
There are many use cases where generative AI chat with your document function can help increase productivity. Few examples will be technical support extracting info from user manual for quick resolution of questions from the customers, or HR answering questions based on policy documents or developer using technical documentation to get info about specific function or a call center team addressing inquiries from customers quickly by chatting with product documentation. 
 
**Let's look at our use cases:**
 
•	MyBankGB, a fictitious bank, offers various credit cards to consumers. The document "MyBankGB Credit Card Offerings.pdf" contains detailed information about all the features and details of the credit cards offered by the bank.
 
•	MyBankGB is interested in implementing a Generative AI solution using the "Chat with your document" function of Amazon Bedrock Knowledge Base. This solution will enable the call center team to quickly access information about the card features and efficiently address customer inquiries.
 
•	This is a proof of concept hence API based solution not required, rather access will be provided to selected call center team members via AWS Console for Bedrock knowledge base chat with your document function.
 
Here is the architecture diagram for our use case.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dtu1k5xipl1nip87upxa.png)

Let's see the steps to create a single document knowledge base in Bedrock and start consuming it using AWS Console.
 
**Review AWS Bedrock 'Chat with your document**
 
Chat with document is a new feature.  You can use it via AWS Console or can use SDK to invoke it via Bedrock, Lambda and API.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zax6gzs4l8uhjcz5m6au.png)

For Data, you can upload a file from your computer OR you can provide ARN for the file posted in the S3 bucket.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vcstfml60opzc8syfbp2.png)

Select model. Anthropic Claude 3 Sonnet is the only supported model as of May, 2024.
 
**Request Model Access**
 
Before you can use the model, you must request access to the model. 
 
**Chat with your document using AWS Console**
 
Let’s chat with the document and review responses.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wevq2w17pm462qcan7xv.png)

**Review the response**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cyi6iis26k0vsmhjohje.png)

**Let's review more prompts and responses!**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qnrz1v447p0pbgvtkpql.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z9xd12twruh564l0slzj.png)

As you can see above, all answers are provided in the context of the document uploaded in the S3 bucket. This is where RAG makes the generative AI responses more accurate and reliable, and controls the hallucination. 
 
With these steps, a serverless GenAI solution has been successfully implemented to build a serverless GenAI RAG solution for creating a single-document knowledge base using the Amazon Bedrock Console. Selected call center team members who have access to the AWS Console and the Anthropic Sonnet model can utilize the 'chat with your document' function and then provide feedback on whether an automated solution using APIs should be developed.
 
As GenAI solutions keep improving, they will change how we work and bring real benefits to many industries. This workshop shows how powerful AI can be in solving real-world problems and creating new opportunities for innovation.
 
Thanks for reading!
 
Click here to get to YouTube video for this solution.

 {% embed https://www.youtube.com/watch?v=ErzmSHRY3pY %}

https://www.youtube.com/watch?v=ErzmSHRY3pY
 
𝒢𝒾𝓇𝒾𝓈𝒽 ℬ𝒽𝒶𝓉𝒾𝒶
𝘈𝘞𝘚 𝘊𝘦𝘳𝘵𝘪𝘧𝘪𝘦𝘥 𝘚𝘰𝘭𝘶𝘵𝘪𝘰𝘯 𝘈𝘳𝘤𝘩𝘪𝘵𝘦𝘤𝘵 & 𝘋𝘦𝘷𝘦𝘭𝘰𝘱𝘦𝘳 𝘈𝘴𝘴𝘰𝘤𝘪𝘢𝘵𝘦
𝘊𝘭𝘰𝘶𝘥 𝘛𝘦𝘤𝘩𝘯𝘰𝘭𝘰𝘨𝘺 𝘌𝘯𝘵𝘩𝘶𝘴𝘪𝘢𝘴𝘵