VOOZH about

URL: https://thenewstack.io/build-a-qa-application-with-amazon-bedrock-and-amazon-titan/

⇱ Build a Q&A Application with Amazon Bedrock and Amazon Titan - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2023-12-22 06:00:00
Build a Q&A Application with Amazon Bedrock and Amazon Titan
sponsor-amazon-web-services-aws,sponsored-post,
AI

Build a Q&A Application with Amazon Bedrock and Amazon Titan

This guide focuses on building a question-answering application based on Retrieval Augmented Generation (RAG).
Dec 22nd, 2023 6:00am by Janakiram MSV
👁 Featued image for: Build a Q&A Application with Amazon Bedrock and Amazon Titan
Feature image by Mirko Fabian from Pixabay.
AWS sponsored this post.

In the previous tutorial, we created an Amazon OpenSearch Serverless instance to store and retrieve the text embeddings generated from the Kaggle Academy Awards dataset.

This guide focuses on building a question-answering application based on Retrieval Augmented Generation (RAG). We will continue to use the same environment and the Jupyter Notebook we launched in the previous tutorial.

Step 1 – Build the Context Through Semantic Search

Our goal is to retrieve the top matches based on the prompt and then concatenate the text to create the context.

Let’s start with a prompt that will be asked by the user and convert that into vector embeddings by sending it to the Titan Embeddings models.

prompt='who won the award for best music?'
vector=text_embedding(prompt)

Based on this vector, we will now perform a semantic search.

response=search_index(vector)
response['hits']['hits']

👁 Image

Let’s create the context by concatenating the value of the nominee_text element.

data=response['hits']['hits']
context = ''
for item in data:
 context += item['_source']['nominee_text'] + '\n'
print(context)

👁 Image

Step 2 – Augmenting the Prompt with Context and Invoking the Titan Model

We will now create an augmented prompt from the context that includes the context and the original prompt.

augmented_prompt=f'Context - {context}\nBased on the above context, answer this question - {prompt}'

With the final prompt in place, let’s invoke the model.

config={
 "maxTokenCount": 1000,
 "stopSequences": [],
 "temperature":0.1,
 "topP":1
}

body = json.dumps({'inputText': augmented_prompt,'textGenerationConfig':config})

response = bedrock.invoke_model( 
 modelId='amazon.titan-tg1-large', 
 body=body
)

response_body = json.loads(response.get('body').read())
print(response_body.get('results')[0].get('outputText'))

👁 Image

You can change the prompt and run this to see accurate responses from Titan.

For the prompt, “Which character did Brendan Fraser play in the film The Whale?” you get the below response, which is correct.

👁 Image

This concludes the tutorial on implementing RAG with Amazon Bedrock, Amazon Titan and Amazon OpenSearch Serverless.

Since its inception, Amazon Web Services (AWS) has been the best place for customers to build and run open source software in the cloud. AWS is proud to support open source projects, foundations, and partners.
Learn More
The latest from AWS
Hear more from our sponsor
TRENDING STORIES
Janakiram MSV (Jani) is a practicing architect, research analyst, and advisor to Silicon Valley startups. He focuses on the convergence of modern infrastructure powered by cloud-native technology and machine intelligence driven by generative AI. Before becoming an entrepreneur, he spent...
Read more from Janakiram MSV
AWS sponsored this post.
SHARE THIS STORY
TRENDING STORIES
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.