aws-samples / amazon-bedrock-rag

Fully managed RAG solution implemented using Knowledge Bases for Amazon Bedrock
MIT No Attribution
36 stars 10 forks source link
apigateway bedrock genai lambda opensearch-serverless rag s3 waf

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.

Deploy solution

Prerequisite

Backend

When the deployment completes,

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

Cleanup

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

Security checks

Credit