Serverless RAG solution using Amazon Bedrock Knowledge Base
In one of my earlier posts, we explored how to create a Retrieval Augmented Generation (RAG) solution by integrating Amazon Bedrock and Amazon OpenSearch Serverless, utilizing Langchain as the framework. At the re:Invent 2023 event, AWS introduced Knowledge Bases for Amazon Bedrock, now generally available. This offering seamlessly integrates various components necessary for a RAG solution, providing a low-code/no-code approach.
With Knowledge Bases for Amazon Bedrock, developers can store their documents in an Amazon S3 bucket and specify it as the source. Bedrock manages the entire ingestion workflow, including fetching documents, chunking them, creating embeddings, and storing them in a vector database. It also handles runtime orchestration, generating embeddings for user queries, retrieving relevant chunks from the vector database, and passing them to a foundation model. Customers have the flexibility to choose from various vector databases, such as the vector engine for Amazon OpenSearch Serverless, Pinecone, Amazon Aurora, and Redis Enterprise Cloud.
In this post we will explore how to set up your own RAG solution using Knowledge Bases for Amazon Bedrock in under 10 minutes!! Let’s get started!
This post assumes you have an understanding of how to use the AWS console. If you do not have a AWS account, please create one here
- Login to AWS and navigate to Amazon S3
2. Next step will be to create a S3 bucket to store the data soure. Click on ‘Create bucket’
3. Provide the bucket name for the Amazon S3 bucket and leave all other configurations as default. Use a unique bucket name for your bucket. S3 requires bucket names to be globally unique. Click the ‘Create bucket’ button at the bottom of the screen.
4. Navigate to the bucket and upload your knowledge base file to the S3 bucket. I exported a couple of my previous posts into PDFs and uploaded them to the S3 bucket as a source for the knowledge base.
5. Now let’s navigate to Amazon Bedrock
6. From the left panel, navigate to ‘Knowledge base’
7. Click on ‘Create knowlegde base’ to get started
8. The first step prompts you for details on the knowledge base, IAM permissions and Tags. We will provide a user friendly name to the knowledge base and leave the rest of the configuration as default. Click the ‘Next’ button at the bottom of the page
9. On the second step, we will set up the data source. Provide the data source name and the URI to the S3 bucket we created. Click the ‘Next’ button at the bottom of the page
10. The third page is to select the embedding model and vector database. For this post we are using ‘Titan Embeddings G1 — Text’ for embeddings and will use ‘Quick create a new vector store’ for the Vector database. If you already have a Vector database you want to reuse, that can be done as well. For the purpose of this post we will stick to creating a new vector store, leaving all other configurations default. Click the ‘Next’ button at the bottom of the page
11. The last step is to review the details and click ‘Create knowledge base’ at the bottom of the page. It takes a few minutes to create the vector database in Amazon OpenSearch Serverless. You should see a banner on top indicating that the vector database is being prepared
12. Once the database is ready you should see a green banner indicating its readiness and will be automatically directed to a test page in a few seconds.
13. In case you are not automatically directed to the test base, navigate to the knowledge base page from step 6. You should see the list of knowledge bases
14. Click on the knowledge base you just created and you should see a page like the one shown below
15. The next step is to sync the data source. Under the data source section. Click the ‘Sync’ button. The sync process will take a few minutes depending on the size of the documents. Once it is synced. It will show ready in the status column.
16. On the right side of the page, you will see the ‘Test knowledge base’ option. Under that panel, click on the ‘Select model’ button
17. Select the Claude Instant 1.2 model and hit ‘Apply’ at the bottom of the dialog box
18. Now let’s test it out. Input your message / question and hit the ‘Run’ button. Your message will be sent to the knowledge base you created and Amazon Bedrock runs the RAG model behind the scenes and creates a response for you. Screenshot below shows a sample question and response based on the source I uploaded.
19. You can also view the details of what documentation Bedrock used as the source for the answer by clicking on ‘Show source details’
20. Congratulations! You now have a RAG solution ready using Knowledge Bases for Amazon Bedrock.
In my next post, I will talk about how to use knowledge bases for Amazon Bedrock in production.
The opinions expressed in this article are the author’s own and do not reflect the views of AWS.