Skip to content

Latest commit

 

History

History
67 lines (52 loc) · 6.09 KB

README.md

File metadata and controls

67 lines (52 loc) · 6.09 KB

Implement a fully managed RAG solution using Knowledge Bases for Amazon Bedrock

Retrieval-Augmented Generation (RAG) is the process of optimizing the output of a large language model, so it references an authoritative knowledge base outside of its training data sources before generating a response. Large Language Models (LLMs) are trained on vast volumes of data and use billions of parameters to generate original output for tasks like answering questions, translating languages, and completing sentences. RAG extends the already powerful capabilities of LLMs to specific domains or an organization's internal knowledge base, all without the need to retrain the model. It is a cost-effective approach to improving LLM output so it remains relevant, accurate, and useful in various contexts. Learn more about RAG here.

Amazon Bedrock is a fully managed service that offers a choice of high-performing foundation models (FMs) from leading AI companies like AI21 Labs, Anthropic, Cohere, Meta, Stability AI, and Amazon via a single API, along with a broad set of capabilities you need to build generative AI applications with security, privacy, and responsible AI. Using Amazon Bedrock, you can easily experiment with and evaluate top FMs for your use case, privately customize them with your data using techniques such as fine-tuning and RAG, and build agents that execute tasks using your enterprise systems and data sources. Since Amazon Bedrock is serverless, you don't have to manage any infrastructure, and you can securely integrate and deploy generative AI capabilities into your applications using the AWS services you are already familiar with.

Knowledge Bases for Amazon Bedrock is a fully managed capability that helps you implement the entire RAG workflow from ingestion to retrieval and prompt augmentation without having to build custom integrations to data sources and manage data flows. Session context management is built in, so your app can readily support multi-turn conversations.

Usecase

Need to find areas where Amazon is increasing investments to support future growth. The questions related to this exploration will be asked in a natural language by humans. The response need to include a reference to the source document.

User Experience

Solution Architecture

The following solution architecture shows a workflow and a combination of AWS services to support the usecase described above.

  • Note that with Amazon OpeSearch Serverless, you will be billed for 4 OCUs at a minimum at all times. Follow instructions in the Cleanup section to avoid charges.

Deploy solution

Prerequisite

Backend

  • Clone this repository to your local computer.
  • From the backend folder, run "npm install" to install all dependencies. Use "npm audit" to check for known vulnerabilites on the dependent packages.
  • Use CDK to deploy the backend to AWS. For example,
cdk deploy --context allowedip="xxx.xxx.xxx.xxx/32"

Provide an client IP address that is allowed to access the API Gateway in CIDR format as part of the 'allowedip' context variable.

When the deployment completes,

  • Make note of the API Gateway URL shown at BackendStack.APIGatewayUrl output.
  • Make note of the S3 bucket name shown at BackendStack.DocsBucketName output.

Amazon Bedrock foundational model

This solution utilizes Anthropic Claude Instant foundation model during the retrieval and generation phase, and Amazon Titan Embeddings G1 - Text model for the knowledge base embedding model. Make sure you have access to these foundation models.

Upload content to S3 bucket

Get a recent publicly available Amazon's annual report and copy it to the S3 bucket name noted previously. For a quick test, you can copy the Amazon's 2022 annual report using the AWS S3 Console.

Frontend

  • From the frontend folder, run "npm install" to install the packages.
  • Optionally, you can run "npm audit --omit=dev" to check on vulnerabilities.
  • Run "npm run start" to launch the frontend application from the browser.
  • Use the user interface shown in the browser.
  • For Step 1, enter the API Gateway endpoint URL noted previously.
  • For Step 2, you can enter a question of the form "Where is Amazon investing to support growth?" and press the enter key to see the generated answer including a citation.

Cleanup

Use "cdk destroy" to delete the stack of cloud resources created in this solution deployment.

Security checks

  • npm audit is used to confirm there are no vulnerabilities.
  • SonarLint is used in VS Code to confirm there are no problems detected in the codebase.
  • Amazon CodeWhisperer security checks are run to confirm there are no issues in the codebase.
  • S3 bucket created in this project is setup to enforce ssl requests only and encrypt data at rest.
  • S3 bucket is setup to block public access.
  • API Gateway is setup with AWS Web Application Firewall to allow requests from a specific IP address only.

Credit