DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Low-Code Development: Leverage low and no code to streamline your workflow so that you can focus on higher priorities.

DZone Security Research: Tell us your top security strategies in 2024, influence our research, and enter for a chance to win $!

Launch your software development career: Dive head first into the SDLC and learn how to build high-quality software and teams.

Open Source Migration Practices and Patterns: Explore key traits of migrating open-source software and its impact on software development.

Related

  • How To Build an AI Knowledge Base With RAG
  • A Framework for Building Semantic Search Applications With Generative AI
  • Unlocking the Power of Search: Keywords, Similarity, and Semantics Explained
  • Pure Storage Empowers Developers and Data Scientists With Agile, High-Performance Storage for AI and Modern Applications

Trending

  • The Rise of Kubernetes: Reshaping the Future of Application Development
  • The Cutting Edge of Web Application Development: What To Expect in 2024
  • AWS CDK: Infrastructure as Abstract Data Types
  • Implementing Real-Time Credit Card Fraud Detection With Apache Flink on AWS
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. Add Flexibility to Your RAG Applications in Amazon Bedrock

Add Flexibility to Your RAG Applications in Amazon Bedrock

Knowledge Bases for Amazon Bedrock is a fully managed capability that helps you implement the entire RAG workflow from ingestion to retrieval and prompt augmentation.

By 
Abhishek Gupta user avatar
Abhishek Gupta
DZone Core CORE ·
Jun. 05, 24 · Tutorial
Like (1)
Save
Tweet
Share
2.5K Views

Join the DZone community and get the full member experience.

Join For Free

Knowledge Bases for Amazon Bedrock is a fully managed capability that helps you implement the entire RAG workflow from ingestion to retrieval and prompt augmentation without having to build custom integrations to data sources and manage data flows.

There are several configurations you can tweak to customize retrieval and response generation. This is done via query configuration parameters which can be applied via the console, API, or the SDK.

Let's walk through them one by one.

knowledge bases for amazon bedrock

Maximum Number of Retrieved Results

Semantic search (the retrieval in RAG) are usually Top-K searches i.e. "Give me the best K search results in response to my query." By default, Amazon Bedrock returns up to five results in the response. But you can modify this:

maximum number of retrieved results

Search Type

You can actually decide to combine semantic search with the "good old" text-based search. Choose the Hybrid search type if that's the case. Combines searching vector embeddings (semantic search) with searching through the raw text.

search type

Opting for the Semantic option only searches through the vector embeddings.

Note: At the time of writing Hybrid search is currently only supported for Amazon OpenSearch Serverless vector stores that contain a filterable text field. Amazon Bedrock falls back to using semantic search if you configure a different vector store or your Amazon OpenSearch Serverless vector store doesn't contain a filterable text field.

Prompt Template

The "A" (Augmented) in RAG is when the search results are combined with the prompt. Amazon Bedrock uses a default prompt template. But you can do further prompt engineering using prompt placeholders (such as $query$, $search_results$, etc.).

Prompt templates differ based on the chosen model. For example, here is the one for Amazon Titan Text Premier:

prompt example

... and here is the one for Claude Haiku:

Claude Haiku

Note: This is only use with RetrieveAndGenerate API.

Inference Parameters

These are values that you can adjust in order to influence the model response. This includes temperature, topP, topK, stop sequences, etc.

You can set these with Knowledge Base RAG queries as well.

Inference Parameters

Note: This is only use with RetrieveAndGenerate API.

Guardrails

With Guardrails in Amazon Bedrock, you can implement safeguards for your generative AI applications based on your use cases and responsible AI policies. A guardrail consists of multiple policies to avoid content that falls into undesirable or harmful categories.

Once you create a Guardrail, simply associate it with the knowledge base:

Guardrails

Note: This is only use with RetrieveAndGenerate API.

Metadata Files

Retrieval does not have to be just limited based on the semantic search results. You can further tune queries by including additional metadata files with your source documents. It can contain attributes as key-value pairs that you define for a source document.

You can use filter (equals, greater than, etc.) and logical (and, or) search operators along with metadata-based filters.

filters

For details, you can refer to Add metadata to your files to allow for filtering.

Bonus: Chunking and Delete Policy

Strictly speaking, these are not query configurations, but definitely worth knowing.

  • Chunking: During data ingestion (from source to the chosen vector database), then each file is split into chunks using one of the following strategies - no chunking (each file = a chunk), default (each chunk = ~300 tokens), fixed size (you define the size)
  • Data deletion policy: The default policy is DELETE, which means that the underlying vector will be deleted along with the knowledge base. To change prevent the vector store deletion, change the policy to RETAIN.

Conclusion

I showed examples for the AWS console, but like I mentioned earlier, these are applicable to the SDK and API as well. For example, here is how the RetrieveAndGenerate API uses these configuration parameters.

Read more in Query Configurations. Happy building!

AI Knowledge base Semantic search Amazon Web Services

Published at DZone with permission of Abhishek Gupta, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How To Build an AI Knowledge Base With RAG
  • A Framework for Building Semantic Search Applications With Generative AI
  • Unlocking the Power of Search: Keywords, Similarity, and Semantics Explained
  • Pure Storage Empowers Developers and Data Scientists With Agile, High-Performance Storage for AI and Modern Applications

Partner Resources


Comments

ABOUT US

  • About DZone
  • Send feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: