QA with LLM and RAG (Retrieval Augmented Generation)
This project is a Question Answering application with Large Language Models (LLMs) and Amazon Aurora Postgresql using pgvector. An application using the RAG(Retrieval Augmented Generation) approach retrieves information most relevant to the user’s request from the enterprise knowledge base or content, bundles it as context along with the user’s request as a prompt, and then sends it to the LLM to get a GenAI response.
LLMs have limitations around the maximum word count for the input prompt, therefore choosing the right passages among thousands or millions of documents in the enterprise, has a direct impact on the LLM’s accuracy.
In this project, Amazon Aurora Postgresql with pgvector is used for knowledge base.
The overall architecture is like this:
Overall Workflow
- Deploy the cdk stacks (For more information, see here).
- A SageMaker Studio in a private VPC.
- A SageMaker Endpoint for text generation.
- A SageMaker Endpoint for generating embeddings.
- An Amazon Aurora Postgresql cluster for storing embeddings.
- Aurora Postgresql cluster's access credentials (username and password) stored in AWS Secrets Mananger as a name such as
RAGPgVectorStackAuroraPostg-xxxxxxxxxxxx
.
- Open SageMaker Studio and then open a new System terminal.
- Run the following commands on the terminal to clone the code repository for this project:
git clone --depth=1 https://github.com/ksmin23/rag-with-postgresql-pgvector-and-sagemaker.git
- Open
data_ingestion_to_pgvector.ipynb
notebook and Run it. (For more information, see here)
- Run Streamlit application. (For more information, see here)
References
- Leverage pgvector and Amazon Aurora PostgreSQL for Natural Language Processing, Chatbots and Sentiment Analysis (2023-07-13)
- Accelerate HNSW indexing and searching with pgvector on Amazon Aurora PostgreSQL-compatible edition and Amazon RDS for PostgreSQL (2023-11-06)
- Optimize generative AI applications with pgvector indexing: A deep dive into IVFFlat and HNSW techniques (2024-03-15)
- Improve the performance of generative AI workloads on Amazon Aurora with Optimized Reads and pgvector (2024-02-09)
- Building AI-powered search in PostgreSQL using Amazon SageMaker and pgvector (2023-05-03)
- Build Streamlit apps in Amazon SageMaker Studio (2023-04-11)
- Quickly build high-accuracy Generative AI applications on enterprise data using Amazon Kendra, LangChain, and large language models (2023-05-03)
- (github) Amazon Kendra Retriver Samples
- Question answering using Retrieval Augmented Generation with foundation models in Amazon SageMaker JumpStart (2023-05-02)
- Use proprietary foundation models from Amazon SageMaker JumpStart in Amazon SageMaker Studio (2023-06-27)
- LangChain - A framework for developing applications powered by language models.
- Streamlit - A faster way to build and share data apps
- rag-with-amazon-kendra-and-sagemaker - Question Answering application with Large Language Models (LLMs) and Amazon Kendra
- rag-with-amazon-opensearch-and-sagemaker - Question Answering application with Large Language Models (LLMs) and Amazon OpenSearch Service
- rag-with-amazon-opensearch-serverless - Question Answering application with Large Language Models (LLMs) and Amazon OpenSearch Serverless Service
- Pgvector changelog
Increased max dimensions for vector from 1024 to 16000
Increased max dimensions for index from 1024 to 2000