Skip to content

Llama2-7B/13B/70B and Falcon-7B/40B/180B LLM with Amazon Opensearch Serverless as a Vector DB

License

Notifications You must be signed in to change notification settings

reena-cs/serverless-rag-demo

 
 

Repository files navigation

Llama2/Falcon with Serverless RAG on Amazon Opensearch Serverless vector db

Overview

A new wave of widespread AI adoption is on the way with generative AI,having the potential to reinvent every aspect of customer experiences and applications. Generative AI is powered by very large machine learning models that are pre-trained on vast amounts of data, commonly referred to as foundation models (FMs). Large Language Models are a subset of Foundation Models(FMs) which are trained on trillions of words and they learn the patterns in the language, allowing them to generate human-like responses to any query we give them. Additionally, foundation models are trained on very general domain corpora, making them less effective for domain-specific tasks. There lies the importance of RAG. You can use Retrieval Augmented Generation (RAG) to retrieve data from outside a foundation model and augment your prompts by adding the relevant retrieved data in context.

Text generation using RAG with LLMs enables you to generate domain-specific text outputs by supplying specific external data as part of the context fed to LLMs. With RAG, the external data used to augment your prompts can come from multiple data sources, such as a document repositories, databases, or APIs. The first step is to convert your documents and any user queries into a compatible format to perform relevancy search. To make the formats compatible, a document collection, or knowledge library, and user-submitted queries are converted to numerical representations using embedding language models. Embedding is the process by which text is given numerical representation in a vector space. RAG model architectures compare the embeddings of user queries within the vector of the knowledge library. The original user prompt is then appended with relevant context from similar documents within the knowledge library. This augmented prompt is then sent to the foundation model. You can update knowledge libraries and their relevant embeddings asynchronously.

Amazon Opensearch Serverless offers vector engine to store embeddings for faster similarity searches. The vector engine provides a simple, scalable, and high-performing similarity search capability in Amazon OpenSearch Serverless that makes it easy for you to build generative artificial intelligence (AI) applications without having to manage the underlying vector database infrastructure.

(14-Sept-2023): Support for new LLM's

  • Llama2-7B (Existing G5.2xlarge)
  • Llama2-13B (G5.12xlarge)
  • Llama2-70B (G5.48xlarge)
  • Falcon-7B (G5.2xlarge)
  • Falcon-40B (G5.12xlarge)
  • Falcon-180B (p4de.24xlarge)

New UX/UI (13-Sept-2023): Index Sample Data across different domains. Support multiple-assistant behaviours (Normal/Pirate/Jarvis Assistant modes)

Sample_Indexes QueryBehaviour

Video Demo

ImprovedVectorDB.mov

This solution demonstrates building a RAG (Retrieval Augmented Solution) with Amazon Opensearch Serverless Vector DB and Llama2 LLM, Falcon LLM

Prerequisites

For this walkthrough, you should have the following prerequisites:

An AWS account

Familiarity with below Services.

AWS IAM.

AWS Lambda

Amazon API Gateway

Amazon opensearch serverless

Amazon Sagemaker

GPU Instance of type ml.g5.2xlarge for endpoint usage

Supported Llama2 regions (us-east-1 , us-east-2 , us-west 2 , eu-west-1 , and ap-southeast-1)

Architecture

Architecture drawio (2)

Deploying the Solution to your account with AWS Cloudshell

Section1 - Create an IAM user with Administrator permissions.

  1. Search for the service IAM on the AWS Console and go the IAM Dashboard and click on “Users“ tab under ”Access Management” and Click on “Create User”

image

  1. Give a name to the IAM user and click “Next“

image

  1. Now Click on Attach Policies directly and Choose "AdminsitratorAccess" and click "Next"

image

  1. Now review the details and click on "Create User"

image

  1. Now we need to create credentials for this IAM. Go to "Users" tab again and you will see your new user listed over there. Now click on the username.

image

  1. Go to Security Credentials Tab and under "Access Keys" click on "Create Access key"
LLMAdminSecurityCredentials2
  1. In the window that appears choose the first option "Command line Interface" and click the checkbox at the bottom and click Next

image

8.Now the Tag is optional and you can leave this empty and click on Create Access Key

image

  1. Now click on Download .csv file to download the credentials and click on "Done". Now lets proceed to section 2

image

Section 2 - Deploy a RAG based Solution (The below commands should be executed in the region of deployment)

  1. Search for AWS Cloudshell. Configure your aws cli environment with the access/secret keys of the new admin user using the below command on AWS Cloudshell
       aws configure
    
LLMAdminConfigureCloudShell
  1. Git Clone the serverless-rag-demo repository from aws-samples

     git clone https://github.com/aws-samples/serverless-rag-demo.git
    
  2. Go to the directory where we have the downloaded files.

      cd serverless-rag-demo
    
  3. Fire the bash script that creates the RAG based solution. Pass the environment and region for deployment. environment can be dev,qa,sandbox. Region can be any of those supported by Amazon Opensearch Serverless refer

      sh creator.sh dev us-east-1
    
  4. Select the LLM you want to deploy (sh creator.sh dev us-east-1)

    Screenshot 2023-09-14 at 8 48 50 PM
  5. Total deployment takes around 40 minutes. Once the deployment is complete head to API Gateway. Search for API with name rag-llm-api-{env_name}. Get the invoke URL for the API

ApiGw1
  1. Invoke the Api Gateway URL that loads an html page for testing the RAG based solution as api-gateway-url/rag

    • Do not forget to append "rag" at the end of the API-GW url

    eg: https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/rag

    Screenshot 2023-09-14 at 8 52 09 PM

About

Llama2-7B/13B/70B and Falcon-7B/40B/180B LLM with Amazon Opensearch Serverless as a Vector DB

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 57.0%
  • HTML 24.6%
  • Shell 16.9%
  • Other 1.5%