Voiced by Amazon Polly |
Introduction
With Knowledge Bases for Amazon Bedrock, you can securely link foundation models (FMs) to your company’s data for Retrieval Augmented Generation (RAG). This integration enables the model to produce more pertinent, context-specific, and precise responses without the need for FM retraining.
Amazon Bedrock’s Knowledge Bases now offer two exciting new features for the RetrieveAndGenerate API: controlling the maximum number of results and customizing prompts.
Maximum Results Control: Now, you can decide how many search results you want, up to 100. This helps tailor the amount of background info for generating answers, improving accuracy.
Custom Prompts: You can replace the default prompt template with your own, tweak tone format, and even add industry-specific terms or instructions.
Pioneers in Cloud Consulting & Migration Services
- Reduced infrastructural costs
- Accelerated application deployment
Overview and Benefits of the New Features
You can fetch up to 100 results, enhancing the likelihood of relevant context, improving accuracy, and reducing the risk of generating irrelevant responses.
This allows you to personalize the model for generating responses adjusting the tone, output format, and behavior of the FM. This option allows you to refine terminology to align better with your industry or domain, such as healthcare or legal. Additionally, you can include custom instructions and examples tailored to your specific workflows.
Prerequisites
- AWS Account access with permission to access the Amazon Bedrock
- Existing Knowledge Base in Amazon Bedrock
Step-by-Step Guide to Adjust the Maximum Number of Results using the console
Step 1: Navigate to the Knowledge Bases section on the Amazon Bedrock console’s left-hand menu.
Step 2: Pick the knowledge base you’ve established earlier.
Step 3: Opt for “Test knowledge base.”
Step 4: Click on the configuration icon.
Step 5: Select “Sync data source” before commencing testing on your knowledge base.
Step 6: In the Configurations section, choose a search type that aligns with your specific use case.
In this post, we stick with the default search option for simplicity. However, you also have the flexibility to utilize semantic search or hybrid search, depending on your specific use cases. To delve deeper into hybrid search, check out the feature spotlight on Knowledge Bases for Amazon Bedrock supporting hybrid search.
Step 7: Increase the maximum number of source chunks and specify your desired maximum number of results.
Step 8: We utilized Claude v3 Sonnet as the FM to produce the ultimate response by leveraging the contextual information obtained from the knowledge base. Additionally, Claude v2 and Claude 3 Haiku are compatible with generation FMs.
As depicted in the screenshot below, the response generated with this request is displayed.
In this example, we successfully obtain the correct answer based on the number of retrieved results. If you wish to delve deeper into the source attribution contributing to the final output, select “Show source details” to verify the generated answer against the knowledge base.
The ‘numberOfResults’ option within the ‘retrievalConfiguration’ enables you to specify the desired number of results for retrieval. The output of the RetrieveAndGenerate API comprises the generated response, source attribution, and the retrieved text chunks.
To adjust the maximum number of results using the SDK, follow the syntax below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import json import os import boto3 kbId = os.environ.get('KNOWLEDGE_BASE_ID') numberOfResults = 10 model_arn = "arn:aws:bedrock:XXXX::foundation-model/anthropic.claude-3-sonnet-20240229-v1:0" def retrieveAndGenerate(query): bedrock_agent_runtime = boto3.client('bedrock-agent-runtime', region_name="us-east-1") retrieval_results = bedrock_agent_runtime.retrieve_and_generate( input={ 'text': query }, retrieveAndGenerateConfiguration={ 'knowledgeBaseConfiguration': { 'knowledgeBaseId': kbId, 'modelArn': model_arn, 'retrievalConfiguration': { 'vectorSearchConfiguration': { 'numberOfResults': numberOfResults } }, }, 'type': 'KNOWLEDGE_BASE' }, ) return retrieval_results |
Conclusion
In summary, the new custom prompts and result limit configuration features in Amazon Bedrock’s Knowledge Bases significantly enhance user experience and response accuracy. Users can tailor interactions, adjust background information, and customize responses to match their industry needs. These improvements streamline workflows and ensure more relevant, precise answers without requiring FM retraining.
Drop a query if you have any questions regarding Amazon Bedrock and we will get back to you quickly.
Making IT Networks Enterprise-ready – Cloud Management Services
- Accelerated cloud migration
- End-to-end view of the cloud environment
About CloudThat
CloudThat is a leading provider of Cloud Training and Consulting services with a global presence in India, the USA, Asia, Europe, and Africa. Specializing in AWS, Microsoft Azure, GCP, VMware, Databricks, and more, the company serves mid-market and enterprise clients, offering comprehensive expertise in Cloud Migration, Data Platforms, DevOps, IoT, AI/ML, and more.
CloudThat is recognized as a top-tier partner with AWS and Microsoft, including the prestigious ‘Think Big’ partner award from AWS and the Microsoft Superstars FY 2023 award in Asia & India. Having trained 650k+ professionals in 500+ cloud certifications and completed 300+ consulting projects globally, CloudThat is an official AWS Advanced Consulting Partner, Microsoft Gold Partner, AWS Training Partner, AWS Migration Partner, AWS Data and Analytics Partner, AWS DevOps Competency Partner, Amazon QuickSight Service Delivery Partner, Amazon EKS Service Delivery Partner, AWS Microsoft Workload Partners, Amazon EC2 Service Delivery Partner, and many more.
To get started, go through our Consultancy page and Managed Services Package, CloudThat’s offerings.
FAQs
1. What does the maximum number of results option allow me to do?
ANS: – It enables you to decide how many search results you want, up to 100, providing flexibility in tailoring background information for generating answers.
2. Why is it important to have control over the number of retrieved results?
ANS: – Having control over the number of retrieved results helps improve the accuracy of responses by providing relevant context for both simple and complex queries.
3. Can I use different search types in Amazon Bedrock's Knowledge Bases?
ANS: – Yes, you can choose from default search, semantic search, or hybrid search, depending on your specific use case and requirements.
WRITTEN BY Aditya Kumar
Aditya Kumar works as a Research Associate at CloudThat. His expertise lies in Data Analytics. He is learning and gaining practical experience in AWS and Data Analytics. Aditya is also passionate about continuously expanding his skill set and knowledge to learn new skills. He is keen to learn new technology.
Click to Comment