Reactive Machines

Improving RAG-based application using Amazon Aurora with Amazon Kendra

Ai productive AI models and llMs) transform various store-holders to improve customer information, traditionally will take years to improve. Every organization has data stored in the data stores, either in the premises or cloud suppliers.

You can find a AI of AI and improve customer experience by converting your existing data into the indicator where appropriate. When you ask a question at an open expander LLM, you get publicly available information as an answer. Although this is helpful, AI production can help you understand your data and additional context from the LLMS. This is found by generation of limited refund (RAG).

The RAG returns data from the Pretexisting information (your data), including the LLM information, and issued answers in the same language. However, in order to order enhailing AI to understand your data, a certain amount of data preparation is required, including a major learning curve.

Amazon Aurora is MySQL's Database and Postgreesql compatible for a cloud. Aurora includes the functioning and availability of the simplified age of the age and operation of open source information.

In this sentence, we visualize your Aurora data without needing amazon Kendra data to make your data and llm information to produce accurate answers.

Looking for everything

In this setting, use your existing data as a data resource (Aurora), create a wise search services through the link and sync data for AMAZON KENDRA, using the RAG Directrames for your data and information for -LLM. In this post, we use anthropic's Claude in Amazon Bedrock as our LLL.

The following high-quality steps:

The following drawing shows the formation of a solution.

Requirements

Following this post, the following requirements are required:

Create a collection of Aurora Postgresql

Run the following AWS instructions to create Aurora Postgresql Servale V2 Cluster:

aws rds create-db-cluster 
--engine aurora-postgresql 
--engine-version 15.4 
--db-cluster-identifier genai-kendra-ragdb 
--master-username postgres 
--master-user-password XXXXX 
--db-subnet-group-name dbsubnet 
--vpc-security-group-ids "sg-XXXXX" 
--serverless-v2-scaling-configuration "MinCapacity=2,MaxCapacity=64" 
--enable-http-endpoint 
--region us-east-2

aws rds create-db-instance 
--db-cluster-identifier genai-kendra-ragdb 
--db-instance-identifier genai-kendra-ragdb-instance 
--db-instance-class db.serverless 
--engine aurora-postgresql

The following icon shows the created example.

Ml-16454-Aurora_instance

Ingest data in Aurora Postgresql – Compatible

Connect to the Aurora for example using a PGADMIN tool. See link to the DB state that uses Postgreql database engine for more information. To introduce your data, complete the following steps:

  1. Run the following postgresql statements in PGAdmin to create a database, schema and table:
    CREATE DATABASE genai;
    CREATE SCHEMA 'employees';
    
    CREATE DATABASE genai;
    SET SCHEMA 'employees';
    
    CREATE TABLE employees.amazon_review(
    pk int GENERATED ALWAYS AS IDENTITY NOT NULL,
    id varchar(50) NOT NULL,
    name varchar(300) NULL,
    asins Text NULL,
    brand Text NULL,
    categories Text NULL,
    keys Text NULL,
    manufacturer Text NULL,
    reviews_date Text NULL,
    reviews_dateAdded Text NULL,
    reviews_dateSeen Text NULL,
    reviews_didPurchase Text NULL,
    reviews_doRecommend varchar(100) NULL,
    reviews_id varchar(150) NULL,
    reviews_numHelpful varchar(150) NULL,
    reviews_rating varchar(150) NULL,
    reviews_sourceURLs Text NULL,
    reviews_text Text NULL,
    reviews_title Text NULL,
    reviews_userCity varchar(100) NULL,
    reviews_userProvince varchar(100) NULL,
    reviews_username Text NULL,
    PRIMARY KEY
    (
    pk
    )
    ) ;

  2. In your PGADMIN ARORRA POSTGRESQL, Nun Colors, kind, Query, staff, Tables.
  3. Choose (right-click) Tables and select The PSQL Tool Opening a PSQL client connection.
    Ml-16454_ppsql_tool
  4. Enter the CSV file under your PGADMIN location and run the following command:
    copy employees.amazon_review (id, name, asins, brand, categories, keys, manufacturer, reviews_date, reviews_dateadded, reviews_dateseen, reviews_didpurchase, reviews_dorecommend, reviews_id, reviews_numhelpful, reviews_rating, reviews_sour
    ceurls, reviews_text, reviews_title, reviews_usercity, reviews_userprovince, reviews_username) FROM 'C:Program FilespgAdmin 4runtimeamazon_review.csv' DELIMITER ',' CSV HEADER ENCODING 'utf8';

  5. Run the next PSQL question to confirm the number of records copied:
    Select count (*) from employees.amazon_review;

Create Amazon Kendra Index

Amazon Kendra Index holds contents of your Scriptures and is organized in a way to make documents to slate documents. Having three types of index:

  • Ai Enterprise Edition Index – Provides the highest accuracy of API recruitment and RAG charges (recommended)
  • Enterprise Edition Indion – Enables the Semantic search capacity and provides the most widely available service ready for production tasks
  • Index of Developer Edition – Provides SEMATIC search powers to test your charges

To create Amazon Kendra Index, Fill in the following steps:

  1. On Amazon Kendra Console, Select References to the wavering pane.
  2. Designate Create an indication.
  3. Occupile Describe the Idex information Page, give the following information:
    • A Members The Name of IndexEnter the name (for example, genai-kendra-index).
    • A Members The Role of IAMselect Create a new role (recommended).
    • A Members RoleEnter the IAM passport name (for example, genai-kendra). The name of your passage will be named AmazonKendra-- (For example, AmazonKendra-us-east-2-genai-kendra).
  4. Designate Next.
    Ml-16454-scase-information-information
  5. Occupile Enter additional energy The page, select Developer program (With this demo) and select Next.
    Ml-16454-additional-dose
  6. Occupile Prepare the user's access control Page, give the following information:
    • Behind Settings to control access¸ Select No.
    • Behind The extension of a user groupselect None.
  7. Designate Next.
    ML-16454-COLIGUGER-WERPET-STOL-STOL-CONTUS
  8. Occupile Update and create page, make sure the information and select Cause.
    ML-16454-Review-Building

It may take a real time to create. Check out the list of directions to watch the progress of creating your index. When the state of the index DiligentYour index is ready for use.
Ml-16454-generation-kendra-index

Set Amazon Kendra Aurora Postgresql Connector

Complete these following steps to set your data source connector:

  1. On Amazon Kendra Console, Select Data sources to the wavering pane.
  2. Designate Add Data Source.
  3. Designate Aurora Postgresql Connector as a type of data source.
    ML-16454-Postgresql-connector-connector
  4. Occupile Specify data source information Page, give the following information:
    • A Members Data Source NameEnter the name (for example, data_source_genai_kendra_postgresql).
    • A Members Automatic language¸ Select English (en).
    • Designate Next.
  5. Occupile Define access and security Page, under SourceProvide the following information:
    • A Members WarEnter the postgreesql administration name by example (cvgupdj47zsh.us-east-2.rds.amazonaws.com).
    • A Members HarborEnter the number of Postgreql Directory for example (5432).
    • A Members IndexEnter the Postgresql Stance's data name (genai).
  6. Behind VerificationIf you already have detailed data stored on the AWORT SERVICE MANAGER, select it in another manner, select Create and add new secret.
  7. In Create the Secret AWS Secret Pop-up window, give the following information:
    • A Members The secret nameEnter the name (for example, AmazonKendra-Aurora-PostgreSQL-genai-kendra-secret).
    • A Members Data user nameEnter your data username.
    • A Members Name of approval in a particular area¸ Enter user password.
  8. Designate Add a Secret.
    ML-16454-Create-Create-Create - Secret - The Background
  9. Behind Prepare VPC and Security GroupProvide the following information:
    • A Members A secret cloudChoose your secret cloud (VPC).
    • A Members BasinSelect your subnet.
    • A Members VPC Security GroupsSelect VPC security team to allow access to your data resource.
  10. Behind The Role of IAM¸ If you have an existing role, select In the drop-down menu. Besides, select Create a new role.
    ML-16454-Create_a_New_iam_Role
  11. Occupile Prepare Sync settings Page, under Sync scopeProvide the following information:
    • A Members SQL questionEnter SQL question and column prices as follows: select * from employees.amazon_review.
    • A Members The main keyenter the main column (pk).
    • A Members NameEnter the title column that gives the title title to the document within your data table (reviews_title).
    • A Members TrunkEnter the body column when your Amazon Kendra search will occur (reviews_text).
  12. Behind Synchronizeselect Full sync Convert all table data into a searchable indicator.

After synchronization successfully completes, Amazon Kendra Index will contain information on the specified Aurora Postgresql table. You can use this monitoring index and RAG requests.

  1. Behind Sync Run Programselect Run with the need.
  2. Designate Next.
  3. Occupile Set Field Mappings page, leave default settings and select Next.
  4. Review your settings and select Add Data Source.

Your data source will appear in Data sources Page after the data source has been successfully performed.

ML-16454-Data-Source - Source-creation-success

Ask the RAG app

Amazon Kendra Index Sync sync can take minutes up to hours according to your data volume. When the synchronization ends without error, you're ready to improve your favorite RAG solution. Complete the following steps:

  1. Prepare your AWS guarantees to allow Boto3 to work with AWS services. You can do this by putting AWS_ACCESS_KEY_ID including AWS_SECRET_ACCESS_KEY environmental variation or through ~/.aws/credentials File:
    import boto3
      pip install langchain
    
    # Create a Boto3 session
    
    session = boto3.Session(
       aws_access_key_id='YOUR_AWS_ACCESS_KEY_ID',
       aws_secret_access_key='YOUR_AWS_SECRET_ACCESS_KEY',
       region_name="YOUR_AWS_REGION"
    )

  2. Import Langchain and the elements required:
    from langchain_community.llms import Bedrock
    from langchain_community.retrievers import AmazonKendraRetriever
    from langchain.chains import RetrievalQA

  3. Create an example of the llm (Anthropic's Clause:
    llm = Bedrock(
    region_name = "bedrock_region_name",
    model_kwargs = {
    "max_tokens_to_sample":300,
    "temperature":1,
    "top_k":250,
    "top_p":0.999,
    "anthropic_version":"bedrock-2023-05-31"
    },
    model_id = "anthropic.claude-v2"
    )

  4. Create your fastest template, giving llm instructions:
    from langchain_core.prompts import PromptTemplate
    
    prompt_template = """
    You are a Product Review Specialist, and you provide detail product review insights.
    You have access to the product reviews in the  XML tags below and nothing else.
    
    
    {context}
    
    
    
    {question}
    
    """
    
    prompt = PromptTemplate(template=prompt_template, input_variables=["context", "question"])

  5. Start KendraRetriever with an Imazon Kendra Index ID by replacing Kendra_index_id All previously performed with the Amazon Kendra Client:
    session = boto3.Session(region_name="Kendra_region_name")
    kendra_client = session.client('kendra')
    # Create an instance of AmazonKendraRetriever
    kendra_retriever = AmazonKendraRetriever(
    kendra_client=kendra_client,
    index_id="Kendra_Index_ID"
    )

  6. Mix the Anthropic's Claude and Amazon Kendra Retriever in Retrievalqa Chain:
    qa = RetrievalQA.from_chain_type(
    llm=llm,
    chain_type="stuff",
    retriever=kendra_retriever,
    return_source_documents=True,
    chain_type_kwargs={"prompt": prompt},
    )

  7. Ask a series of your question:
    query = "What are some products that has bad quality reviews, summarize the reviews"
    result_ = qa.invoke(
    query
    )
    result_

    Ml-16454-Rag-Outpos

Clean

To avoid installing future costs, delete the services you created as part of this post:

  1. Remove Aurora DB Cluster and an example of DB.
  2. Remove Amazon Kendra Index.

Store

In this sentence, we discussed how we can change your existing Aurora data into an Imazon Kendra Indra and use a solution supported by the data support rag. This solution is very limiting the need for amazon Kendra search data. It also increases the speed of an effective AI programs by reducing the learning curve after data preparation.

Try the solution, and if you have any other ideas or questions, you left them in the comments section.


About the authors

Aravind Hariharaputran Data Counselor and Team of Training Traffic for Amazon Web Services. You are interested in data and aition typically with broader infectious experiences. You enjoy spending time with family and playing cricket.

Ivan Cui Is the Data Science leading AWS Professional Services, where they help customers to create and send solutions using ML and AWS productivity AWs. You work with customers in various fields, including software, finance, medicine, health care, io, and entertainment. In his free time, she enjoys reading, spending time with her family, and walking.

Source link

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button