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
Please enter at least three characters to search
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

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Supercharge Your Coding Workflow With Ollama, LangChain, and RAG
  • Mastering AI Agents: How Agentic Design Patterns Make Agents Smarter
  • Retrieval-Augmented Generation (RAG): Enhancing AI-Language Models With Real-World Knowledge
  • Better Search Results Through Intelligent Chunking and Metadata Integration

Trending

  • Implementing Explainable AI in CRM Using Stream Processing
  • Securing the Future: Best Practices for Privacy and Data Governance in LLMOps
  • Memory Leak Due to Time-Taking finalize() Method
  • System Coexistence: Bridging Legacy and Modern Architecture
  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
Likes (1)
Comment
Save
Tweet
Share
3.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

  • Supercharge Your Coding Workflow With Ollama, LangChain, and RAG
  • Mastering AI Agents: How Agentic Design Patterns Make Agents Smarter
  • Retrieval-Augmented Generation (RAG): Enhancing AI-Language Models With Real-World Knowledge
  • Better Search Results Through Intelligent Chunking and Metadata Integration

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and 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:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!