GitXplorerGitXplorer
w

amazon-bedrock-rag

public
4 stars
1 forks
0 issues

Commits

List of commits on branch main.
Verified
49b38f45373fa41be7460eb63ed381894b86d7e7

Update rag1.ipynb

wwindson committed a year ago
Verified
06df62a8fdea61fafa545181b121c105d6062414

Update opensearch.py dim to 1536 as per bedrock embeddings model: amazon.titan-embed-text-v1

wwindson committed a year ago
Verified
a885ecacb344e875b28dba8f008fd7fb9ab445fb

Update to amazon.titan-embed-text-v1

wwindson committed a year ago
Verified
6618856516aa5d35210e64a4325fbc28c45b0eb7

init

wwindson committed a year ago
Unverified
4a9bdee00c3ab32c0203f3ae0aac3d8328b20ed0

init

wwindson committed a year ago
Unverified
15ec03e5eb4f5e3e8575793bcf635127b44107b2

init

wwindson committed a year ago

README

The README file for this repository.

RAG with Amazon Bedrock using Titan Embeddings and Amazon OpenSearch Vector Engine

This code sample demonstrates using RAG (Retrieval Augmented Generation) with Amazon Bedrock's Titan embeddings and a large language model (LLM). It creates text embeddings stored in Amazon OpenSearch with vector engine support. This enables prompt engineering for more accurate LLM responses.

This sample does the following

  • Creates embeddings using Titan embeddings LLM
  • Saves embeddings to Amazon OpenSearch
  • Using LangChain, input Query from you (user) is queried for retrieval from vectorized data from Amazon OpenSearch
  • Retrieval from OpenSearch matching the question is fed to Amazon Titan Text LLM as context
  • Amazon Titan Text augments the response based on the User Query

Prerequisites

  1. This was tested on Python 3.11.4

  2. It is advise to work on a clean environment, use virtualenv or any other virtual environment manager.

    pip install virtualenv
    python -m virtualenv venv
    source ./venv/bin/activate
  3. Run ./download-beta-sdk.sh to download the beta SDK for using Amazon Bedrock

  4. Install requirements pip install -r requirements.txt

  5. Install terraform to create the OpenSearch cluster

    brew tap hashicorp/tap
    brew install hashicorp/tap/terraform

Usage

First, deploy an OpenSearch cluster with Terraform:

cd ./terraform
terraform init
terraform apply -auto-approve

Using Sagemaker jupyter notebook rag1.ipynb and then rag2.ipynb

Cleanup

cd ./terraform 
terraform destroy # Confirm with yes