In a digital age inundated with information, website visitors seek instant access to relevant content without the hassle of navigating through extensive web pages. A Q&A bot addresses this need by efficiently retrieving precise information based on natural language queries. This is particularly pertinent for websites with a wealth of data, FAQs, case studies, and other content, streamlining user interaction and information retrieval.
This code provides a solution for website owners seeking to enhance user engagement and streamline information retrieval by presenting a comprehensive guide on building a Natural Language Q&A Bot using Retrieval Augmented Generation (RAG) and Amazon Bedrock Models.
This approach leverages the power of langchain modules (recursive_url) to recurisively get all the contents on a webpage based on the maximum depth we provide, convert the data into embeddings using Amazon Bedrock Titan Embeddings Model, store the embeddings in Aurora PostgresSQL using pgvector extension and retrieve the answer based on the question provided by the user using Amazon Bedrock 3P Models (Antropic Claude v2).
The architecture is as follows:
-
Companies possess a repository of knowledge resources in webpages like FAQ docs. These pages can have links to multiple webpages with more content. We can scrap the data using (recursive_url) module in Langchain.
-
Utilizing the Titan Embedding model from Amazon Bedrock, these resources are transformed into vector representations, ensuring their compatibility for advanced processing.
-
The generated vector embeddings are then stored within Amazon Aurora PostgreSQL, utilizing the specialized pgVector capabilities for efficient storage and retrieval.
-
A user initiates the process by posing a question, for instance, "How can AWS support vector databases?".
-
The user's question is seamlessly translated into its vector embedding, facilitating subsequent computational comparisons.
-
A semantic search operation is executed on the Amazon Aurora PostgreSQL database, employing the vectorized representations to identify knowledge resources with relevant information.
-
The extracted answers from the search are fed into the Antropic Claude v2 model provided by Amazon Bedrock.
-
Leveraging the enhanced context and knowledge derived from the semantic search, the model generates a comprehensive response.
-
The generated response is subsequently delivered back to the user, providing them with a meaningful and informed answer to their initial question.
-
To retain context and support future interactions, the chat history is stored in Amazon DynamoDB, ensuring a seamless continuation of the conversation with the user.
-
Make sure your Amazon Aurora PostgreSQL Database is setup with pgvector extension.
-
Make sure you have access to the Amazon Bedrock models you are trying to use.
-
The EC2 where you are runing the code needs access to the Amazon Aurora PostgreSQL Database, Amazon Bedrock Aws Secrets Manager via IAM Role
-
The code runs on Python3.10. Activate a virtual environment and install all the requirements
python3.10 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt
- Modify the code variables Home.py with the appropriate details according to your environment:
sm_key_name -> AWS Secret Manager key where for storing your Amazon Aurora PostgreSQL details
database -> the database name where embeddings will be created
model_id -> The Bedrock Model which you will be using
- To run the Streamlit application
streamlit run Home.py
-
Web Link: Website you would like to scrape
-
Max Depth: Maximum recursive depths you would like to scrape
-
Exclude: subdirectories if any you would like to exclude
- To store the embeddings in Amazon AuroraPG
- Enter the Question to get the response
See CONTRIBUTING for more information.
This library is licensed under the MIT-0 License. See the LICENSE file.