{"id":19760,"date":"2024-12-24T15:39:52","date_gmt":"2024-12-24T10:09:52","guid":{"rendered":"https:\/\/opstree.com\/blog\/?p=19760"},"modified":"2025-08-14T23:04:25","modified_gmt":"2025-08-14T17:34:25","slug":"end-to-end-rag-solution-with-aws-bedrock-and-langchai","status":"publish","type":"post","link":"https:\/\/opstree.com\/blog\/2024\/12\/24\/end-to-end-rag-solution-with-aws-bedrock-and-langchai\/","title":{"rendered":"End-to-End RAG Solution with AWS Bedrock and LangChain"},"content":{"rendered":"<div class=\"react-pdf__Page css-195\" data-page-number=\"1\">\n<div class=\"react-pdf__Page__textContent textLayer\" data-main-rotation=\"0\">\n<h2><b>Introduction<\/b><\/h2>\n<p><span data-contrast=\"none\">In this blog, we\u2019ll explore the powerful concept of Retrieval-Augmented Generation (RAG) and how it enhances the capabilities of large language models by integrating real-time, external knowledge sources. You&#8217;ll also learn how to build an end-to-end application that leverages this approach for practical use.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:0,&quot;335559739&quot;:0}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">We\u2019ll begin by understanding what RAG is, how it works, and why it&#8217;s gaining popularity for building more accurate and context-aware <a href=\"https:\/\/opstree.com\/services\/generative-ai-solutions\/\"><strong>AI solutions<\/strong><\/a>. RAG combines the strengths of information retrieval and text generation, enabling language models to reference external, up-to-date knowledge bases beyond their original training data, making outputs more reliable and factually accurate.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:0,&quot;335559739&quot;:0}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">As a practical demonstration, we\u2019ll walk through building a custom RAG application that can intelligently query information from your own PDF documents. To achieve this, we&#8217;ll use the AWS Bedrock Llama 3 8B Instruct model, along with the LangChain framework and Streamlit for a user-friendly interface.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:0,&quot;335559739&quot;:0}\">\u00a0<\/span><\/p>\n<\/div>\n<h2 class=\"react-pdf__Page__textContent textLayer\" data-main-rotation=\"0\">Key Technologies For End-to-End RAG Solution<\/h2>\n<div class=\"react-pdf__Page__textContent textLayer\" data-main-rotation=\"0\">\n<p><span id=\"p3R_mc6\" class=\"markedContent\"><strong><span dir=\"ltr\" role=\"presentation\">1.<\/span><\/strong><\/span><strong><span id=\"p3R_mc7\" class=\"markedContent\"> <span dir=\"ltr\" role=\"presentation\">Streamlit<\/span><span dir=\"ltr\" role=\"presentation\">:<\/span><\/span><\/strong><span id=\"p3R_mc8\" class=\"markedContent\"><br role=\"presentation\" \/><span dir=\"ltr\" role=\"presentation\">a.<\/span><\/span><span id=\"p3R_mc9\" class=\"markedContent\"> <span dir=\"ltr\" role=\"presentation\">Interactive front<\/span><span dir=\"ltr\" role=\"presentation\">&#8211;<\/span><span dir=\"ltr\" role=\"presentation\">end for the application.<\/span><\/span><span id=\"p3R_mc10\" class=\"markedContent\"><br role=\"presentation\" \/><span dir=\"ltr\" role=\"presentation\">b.<\/span><\/span><span id=\"p3R_mc11\" class=\"markedContent\"> <span dir=\"ltr\" role=\"presentation\">Simple yet<\/span> <span dir=\"ltr\" role=\"presentation\">powerful framework for building Python web<\/span><br role=\"presentation\" \/><span dir=\"ltr\" role=\"presentation\">apps.<\/span><\/span><span id=\"p3R_mc12\" class=\"markedContent\"><br role=\"presentation\" \/><strong><span dir=\"ltr\" role=\"presentation\">2.<\/span><\/strong><\/span><strong><span id=\"p3R_mc13\" class=\"markedContent\"> <span dir=\"ltr\" role=\"presentation\">LangChain<\/span><span dir=\"ltr\" role=\"presentation\">:<\/span><\/span><\/strong><span id=\"p3R_mc14\" class=\"markedContent\"><br role=\"presentation\" \/><span dir=\"ltr\" role=\"presentation\">a.<\/span><\/span><span id=\"p3R_mc15\" class=\"markedContent\"> <span dir=\"ltr\" role=\"presentation\">Framework for creating LLM<\/span><span dir=\"ltr\" role=\"presentation\">&#8211;<\/span><span dir=\"ltr\" role=\"presentation\">powered workflows.<\/span><\/span><span id=\"p3R_mc16\" class=\"markedContent\"><br role=\"presentation\" \/><span dir=\"ltr\" role=\"presentation\">b.<\/span><\/span><span id=\"p3R_mc17\" class=\"markedContent\"> <span dir=\"ltr\" role=\"presentation\">Provides seamless integration with <a href=\"https:\/\/opstree.com\/blog\/2024\/06\/10\/how-amazon-bedrock-helps-you-leverage-generative-ai\/\"><strong>AWS Bedrock<\/strong><\/a>.<\/span><\/span><span id=\"p3R_mc18\" class=\"markedContent\"><br role=\"presentation\" \/><strong><span dir=\"ltr\" role=\"presentation\">3.<\/span><\/strong><\/span><strong><span id=\"p3R_mc19\" class=\"markedContent\"> <span dir=\"ltr\" role=\"presentation\">AWS Bedrock<\/span><span dir=\"ltr\" role=\"presentation\">:<\/span><\/span><\/strong><span id=\"p3R_mc20\" class=\"markedContent\"><br role=\"presentation\" \/><span dir=\"ltr\" role=\"presentation\">a.<\/span><\/span><span id=\"p3R_mc21\" class=\"markedContent\"> <span dir=\"ltr\" role=\"presentation\">State<\/span><span dir=\"ltr\" role=\"presentation\">&#8211;<\/span><span dir=\"ltr\" role=\"presentation\">of<\/span><span dir=\"ltr\" role=\"presentation\">&#8211;<\/span><span dir=\"ltr\" role=\"presentation\">the<\/span><span dir=\"ltr\" role=\"presentation\">&#8211;<\/span><span dir=\"ltr\" role=\"presentation\">art LLM platform.<\/span><\/span><span id=\"p3R_mc22\" class=\"markedContent\"><br role=\"presentation\" \/><span dir=\"ltr\" role=\"presentation\">b.<\/span><\/span><span id=\"p3R_mc23\" class=\"markedContent\"> <span dir=\"ltr\" role=\"presentation\">Powered by the highly efficient Llama 3 8B<\/span> <span dir=\"ltr\" role=\"presentation\">Instruct model.<\/span><\/span><\/p>\n<div class=\"endOfContent\"><\/div>\n<\/div>\n<div class=\"react-pdf__Page__annotations annotationLayer\" data-main-rotation=\"0\">Let\u2019s get started! Implementing this application involves three key components, each designed to streamline setup and ensure best practices. With the right <a href=\"https:\/\/opstree.com\/aws-consulting-services\/\"><strong>AWS consulting service<\/strong><\/a>, you can efficiently plan, deploy, and optimize each component for a secure and scalable solution.&#8221;<\/div>\n<\/div>\n<p><!--more--><\/p>\n<div class=\"react-pdf__Page css-195\" data-page-number=\"2\">\n<h3 data-main-rotation=\"0\"><span id=\"p25R_mc3\" class=\"markedContent\"><span dir=\"ltr\" role=\"presentation\">1. Create a vector store<\/span><\/span><\/h3>\n<div class=\"react-pdf__Page__textContent textLayer\" data-main-rotation=\"0\"><span id=\"p25R_mc3\" class=\"markedContent\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-19761 alignnone\" src=\"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-150700-300x87.png\" alt=\"\" width=\"552\" height=\"160\" srcset=\"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-150700-300x87.png 300w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-150700-768x223.png 768w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-150700.png 776w\" sizes=\"(max-width: 552px) 85vw, 552px\" \/><br role=\"presentation\" \/><\/span><span id=\"p25R_mc6\" class=\"markedContent\"><br role=\"presentation\" \/><span dir=\"ltr\" role=\"presentation\">Load<\/span><span dir=\"ltr\" role=\"presentation\">&#8211;<\/span><span dir=\"ltr\" role=\"presentation\">&gt;Transform<\/span><span dir=\"ltr\" role=\"presentation\">&#8211;<\/span><span dir=\"ltr\" role=\"presentation\">&gt;Embed.<\/span><\/span><span id=\"p25R_mc7\" class=\"markedContent\"><br role=\"presentation\" \/><span dir=\"ltr\" role=\"presentation\">We will use the FAISS vector database,<\/span> <span dir=\"ltr\" role=\"presentation\">t<\/span><span dir=\"ltr\" role=\"presentation\">o<\/span> <span dir=\"ltr\" role=\"presentation\">efficiently handle queries,<\/span><br role=\"presentation\" \/><span dir=\"ltr\" role=\"presentation\">the text is tokenized and embedded into a vector store using FAISS<\/span><br role=\"presentation\" \/><span dir=\"ltr\" role=\"presentation\">(Facebook AI Similarity Search).<\/span><\/span><\/div>\n<\/div>\n<div data-main-rotation=\"0\"><\/div>\n<div data-main-rotation=\"0\"><strong>[ Find More About: <a href=\"https:\/\/opstree.com\/application-modernization-with-aws\/\">Modernizing Legacy Systems on AWS<\/a>]<\/strong><\/div>\n<div class=\"react-pdf__Page css-195\" data-page-number=\"2\">\n<h3 class=\"react-pdf__Page__textContent textLayer\" data-main-rotation=\"0\"><span id=\"p25R_mc8\" class=\"markedContent\"><br role=\"presentation\" \/><span dir=\"ltr\" role=\"presentation\">2. Query vector store \u201cRetrieve most similar\u201d<\/span><\/span><span id=\"p25R_mc10\" class=\"markedContent\"><br role=\"presentation\" \/><\/span><\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19762\" src=\"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-150937-300x85.png\" alt=\"\" width=\"812\" height=\"230\" srcset=\"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-150937-300x85.png 300w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-150937-1024x291.png 1024w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-150937-768x218.png 768w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-150937.png 1169w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<div class=\"react-pdf__Page__textContent textLayer\" data-main-rotation=\"0\"><span id=\"p25R_mc10\" class=\"markedContent\"><span dir=\"ltr\" role=\"presentation\">The way to handle this at query time, embed the unstructured<\/span><br role=\"presentation\" \/><span dir=\"ltr\" role=\"presentation\">query and retrieve the embedding vector that is most similar to <\/span><\/span>the embedded query. A vector stores embed data and performs a<\/div>\n<\/div>\n<div class=\"react-pdf__Page css-195\" data-page-number=\"3\">\n<div class=\"react-pdf__Page__textContent textLayer\" data-main-rotation=\"0\"><span id=\"p36R_mc0\" class=\"markedContent\"><span dir=\"ltr\" role=\"presentation\">vector search for you.<\/span><\/span><\/div>\n<h3 class=\"react-pdf__Page__textContent textLayer\" data-main-rotation=\"0\"><span id=\"p36R_mc1\" class=\"markedContent\"><\/span><span id=\"p36R_mc2\" class=\"markedContent\"><span dir=\"ltr\" role=\"presentation\">3.<\/span> <span dir=\"ltr\" role=\"presentation\">Response generation using LLM:<\/span><\/span><\/h3>\n<p>&nbsp;<\/p>\n<div class=\"endOfContent\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19763\" src=\"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-151043-300x200.png\" alt=\"\" width=\"582\" height=\"388\" srcset=\"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-151043-300x200.png 300w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-151043-768x513.png 768w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-151043.png 962w\" sizes=\"(max-width: 582px) 85vw, 582px\" \/><\/div>\n<h3><span class=\"TextRun SCXW261247952 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW261247952 BCX8\" data-ccp-parastyle=\"heading 3\">Imports and Setup<\/span><\/span><span class=\"EOP SCXW261247952 BCX8\" data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;335551550&quot;:1,&quot;335551620&quot;:1,&quot;335559738&quot;:281,&quot;335559739&quot;:281}\">\u00a0<\/span><\/h3>\n<div class=\"react-pdf__Page__annotations annotationLayer\" data-main-rotation=\"0\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19764\" src=\"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-151129-300x144.png\" alt=\"\" width=\"973\" height=\"467\" srcset=\"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-151129-300x144.png 300w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-151129-1024x492.png 1024w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-151129-768x369.png 768w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-151129-1200x577.png 1200w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-151129.png 1202w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/div>\n<div data-main-rotation=\"0\"><\/div>\n<\/div>\n<div class=\"react-pdf__Page css-195\" data-page-number=\"4\">\n<ol>\n<li><span id=\"p39R_mc3\" class=\"markedContent\"><strong><span dir=\"ltr\" role=\"presentation\">os<\/span><\/strong><span dir=\"ltr\" role=\"presentation\"><strong>:<\/strong> Used for handling file paths and checking if files exist on disk.<\/span><\/span><span id=\"p39R_mc4\" class=\"markedContent\"><br role=\"presentation\" \/><\/span><\/li>\n<li><span id=\"p39R_mc5\" class=\"markedContent\"><strong><span dir=\"ltr\" role=\"presentation\">pickle<\/span><\/strong><span dir=\"ltr\" role=\"presentation\"><strong>:<\/strong> A Python library for serializing and deserializing Python objects to <\/span><span dir=\"ltr\" role=\"presentation\">store\/retrieve embeddings.<\/span><\/span><span id=\"p39R_mc6\" class=\"markedContent\"><br role=\"presentation\" \/><\/span><\/li>\n<li><span id=\"p39R_mc7\" class=\"markedContent\"><strong><span dir=\"ltr\" role=\"presentation\">boto3<\/span><\/strong><span dir=\"ltr\" role=\"presentation\"><strong>:<\/strong> AWS SDK for Python; used to interact with Amazon Bedrock services.<\/span><\/span><span id=\"p39R_mc8\" class=\"markedContent\"><br role=\"presentation\" \/><\/span><\/li>\n<li><span id=\"p39R_mc9\" class=\"markedContent\"><strong><span dir=\"ltr\" role=\"presentation\">streamlit<\/span><\/strong><span dir=\"ltr\" role=\"presentation\"><strong>:<\/strong> A library for creating web apps for data science and machine learning <\/span><span dir=\"ltr\" role=\"presentation\">projects.<\/span><\/span><span id=\"p39R_mc10\" class=\"markedContent\"><br role=\"presentation\" \/><\/span><\/li>\n<li><span id=\"p39R_mc11\" class=\"markedContent\"><strong><span dir=\"ltr\" role=\"presentation\">Bedrock<\/span><\/strong><span dir=\"ltr\" role=\"presentation\"><strong>:<\/strong> Used to interact with Amazon Bedrock for deploying <a href=\"https:\/\/opstree.com\/blog\/2025\/08\/06\/llm-powered-etl-genai-data-transformation\/\">large language <\/a><\/span><span dir=\"ltr\" role=\"presentation\">models (LLMs).<\/span><\/span><span id=\"p39R_mc12\" class=\"markedContent\"><br role=\"presentation\" \/><\/span><\/li>\n<li><span id=\"p39R_mc13\" class=\"markedContent\"><strong><span dir=\"ltr\" role=\"presentation\">Bedrock Embeddings<\/span><\/strong><span dir=\"ltr\" role=\"presentation\"><strong>:<\/strong> To generate embeddings using Bedrock models.<\/span><\/span><span id=\"p39R_mc14\" class=\"markedContent\"><br role=\"presentation\" \/><\/span><\/li>\n<li><span id=\"p39R_mc15\" class=\"markedContent\"><strong><span dir=\"ltr\" role=\"presentation\">FAISS<\/span><\/strong><span dir=\"ltr\" role=\"presentation\"><strong>:<\/strong> A library for efficient similarity search and clustering of dense vectors.<\/span><\/span><span id=\"p39R_mc16\" class=\"markedContent\"><br role=\"presentation\" \/><\/span><\/li>\n<li><span id=\"p39R_mc17\" class=\"markedContent\"><strong><span dir=\"ltr\" role=\"presentation\">Recursive Character Text Splitter<\/span><\/strong><span dir=\"ltr\" role=\"presentation\"><strong>:<\/strong> Splits large text into manageable chunks for <\/span><span dir=\"ltr\" role=\"presentation\">embedding generation.<\/span><\/span><span id=\"p39R_mc18\" class=\"markedContent\"><br role=\"presentation\" \/><\/span><\/li>\n<li><span id=\"p39R_mc19\" class=\"markedContent\"><strong><span dir=\"ltr\" role=\"presentation\">Pdf Reader<\/span><\/strong><span dir=\"ltr\" role=\"presentation\"><strong>:<\/strong> From PyPDF2, used to extract text from PDF files.<\/span><\/span><span id=\"p39R_mc20\" class=\"markedContent\"><br role=\"presentation\" \/><\/span><\/li>\n<li><span id=\"p39R_mc21\" class=\"markedContent\"><strong><span dir=\"ltr\" role=\"presentation\">Prompt Template<\/span><\/strong><span dir=\"ltr\" role=\"presentation\"><strong>:<\/strong> Defines the structure of the prompt for the LLM.<\/span><\/span><span id=\"p39R_mc22\" class=\"markedContent\"><br role=\"presentation\" \/><\/span><\/li>\n<li><span id=\"p39R_mc23\" class=\"markedContent\"><strong><span dir=\"ltr\" role=\"presentation\">Retrieval QA<\/span><\/strong><span dir=\"ltr\" role=\"presentation\"><strong>:<\/strong> Combines a retriever and a chain to create a question<\/span><span dir=\"ltr\" role=\"presentation\">&#8211;<\/span><span dir=\"ltr\" role=\"presentation\">answering <\/span><span dir=\"ltr\" role=\"presentation\">system.<\/span><\/span><span id=\"p39R_mc24\" class=\"markedContent\"><br role=\"presentation\" \/><\/span><\/li>\n<li><span id=\"p39R_mc25\" class=\"markedContent\"><strong><span dir=\"ltr\" role=\"presentation\">Stuff Documents Chain<\/span><\/strong><span dir=\"ltr\" role=\"presentation\"><strong>:<\/strong> Combines multiple documents into a single context for <\/span><span dir=\"ltr\" role=\"presentation\">answering questions.<\/span><\/span><span id=\"p39R_mc26\" class=\"markedContent\"><br role=\"presentation\" \/><\/span><\/li>\n<li><span id=\"p39R_mc27\" class=\"markedContent\"><strong><span dir=\"ltr\" role=\"presentation\">LLM Chain<\/span><\/strong><span dir=\"ltr\" role=\"presentation\"><strong>:<\/strong> A chain that interacts with a language model using a defined prompt.<\/span><\/span><\/li>\n<li><strong><strong>Initialize Bedrock and Embedding Models<\/strong><\/strong><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19775\" src=\"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-154136-300x58.png\" alt=\"\" width=\"621\" height=\"120\" srcset=\"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-154136-300x58.png 300w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-154136-1024x199.png 1024w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-154136-768x150.png 768w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-154136.png 1037w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/li>\n<li><span id=\"p42R_mc3\" class=\"markedContent\"><span dir=\"ltr\" role=\"presentation\">Initializes an <a href=\"https:\/\/opstree.com\/blog\/2024\/06\/10\/how-amazon-bedrock-helps-you-leverage-generative-ai\/\">Amazon Bedrock<\/a> client using boto3 to interact with Bedrock services.<\/span><\/span><\/li>\n<li><span id=\"p42R_mc5\" class=\"markedContent\"> <span dir=\"ltr\" role=\"presentation\">Initializes the bedrock titan embedding model <\/span><span dir=\"ltr\" role=\"presentation\">amazon.titan<\/span><span dir=\"ltr\" role=\"presentation\">&#8211;<\/span><span dir=\"ltr\" role=\"presentation\">embed<\/span><span dir=\"ltr\" role=\"presentation\">&#8211;<\/span><span dir=\"ltr\" role=\"presentation\">text<\/span><span dir=\"ltr\" role=\"presentation\">&#8211;<\/span><span dir=\"ltr\" role=\"presentation\">v1<\/span> <span dir=\"ltr\" role=\"presentation\">for <\/span><span dir=\"ltr\" role=\"presentation\">generating vector embeddings of text.<br \/>\n<\/span><\/span><span id=\"p42R_mc5\" class=\"markedContent\"><span dir=\"ltr\" role=\"presentation\"><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19783\" src=\"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-183220-300x183.png\" alt=\"\" width=\"698\" height=\"426\" srcset=\"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-183220-300x183.png 300w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-183220-1024x625.png 1024w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-183220-768x469.png 768w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-183220.png 1089w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/span><\/span><\/li>\n<\/ol>\n<\/div>\n<div class=\"react-pdf__Page css-195\" data-page-number=\"5\">\n<h2 class=\"react-pdf__Page__textContent textLayer\" data-main-rotation=\"0\"><span id=\"p42R_mc10\" class=\"markedContent\"><span dir=\"ltr\" role=\"presentation\">Define Bedrock LLM and Prompt<\/span> <span dir=\"ltr\" role=\"presentation\">template<\/span><\/span><\/h2>\n<div class=\"react-pdf__Page__textContent textLayer\" data-main-rotation=\"0\">\n<p><span data-contrast=\"none\">The application begins by initializing the <\/span><a href=\"https:\/\/opstree.com\/blog\/2024\/12\/24\/end-to-end-rag-solution-with-aws-bedrock-and-langchai\/\"><b><span data-contrast=\"none\">Amazon Bedrock Large Language Model (LLM)<\/span><\/b><\/a><span data-contrast=\"none\"> using a specified <\/span><span data-contrast=\"none\">model_id<\/span><span data-contrast=\"none\">. A <\/span><b><span data-contrast=\"none\">custom prompt template<\/span><\/b><span data-contrast=\"none\"> is also defined to guide the AI assistant on how to generate responses effectively.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">This template outlines specific formatting instructions, such as:<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<ul>\n<li><span data-contrast=\"none\">Providing answers in a clear and concise manner<\/span> <span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:220,&quot;335559739&quot;:220}\">\u00a0<\/span><\/li>\n<li><span data-contrast=\"none\">Using bullet points for lists<\/span><\/li>\n<li><span data-contrast=\"none\">Maintaining a respectful and informative tone<\/span><\/li>\n<\/ul>\n<p><span data-contrast=\"none\">Additionally, it includes fallback guidelines for cases where context is limited or when responses must adhere to a defined word count. This structured approach ensures the output is both accurate and user-friendly.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:false,&quot;335559738&quot;:240,&quot;335559739&quot;:240}\">\u00a0<\/span><\/p>\n<\/div>\n<\/div>\n<div class=\"react-pdf__Page css-195\" data-page-number=\"6\">\n<h2 class=\"react-pdf__Page__textContent textLayer\" data-main-rotation=\"0\"><span id=\"p48R_mc4\" class=\"markedContent\"><span dir=\"ltr\" role=\"presentation\">Now, let\u2019s setup Amazon Bedrock.<\/span><\/span><span id=\"p48R_mc7\" class=\"markedContent\"><br role=\"presentation\" \/><\/span><\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19766\" src=\"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-151930-300x115.png\" alt=\"\" width=\"798\" height=\"306\" srcset=\"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-151930-300x115.png 300w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-151930-768x294.png 768w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-151930.png 962w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<\/div>\n<p><span dir=\"ltr\" role=\"presentation\">Click on<\/span> <span dir=\"ltr\" role=\"presentation\">Model Access<\/span> <span dir=\"ltr\" role=\"presentation\">on the left navigation menu. It will show the list of <\/span>models available with Bedrock, as of today.<\/p>\n<div class=\"react-pdf__Page css-195\" data-page-number=\"6\">\n<div class=\"react-pdf__Page__textContent textLayer\" data-main-rotation=\"0\">\n<div class=\"endOfContent\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19767\" src=\"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-152013-300x145.png\" alt=\"\" width=\"759\" height=\"367\" srcset=\"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-152013-300x145.png 300w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-152013-1024x494.png 1024w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-152013-768x370.png 768w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-152013.png 1037w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/div>\n<div><\/div>\n<\/div>\n<\/div>\n<div class=\"react-pdf__Page css-195\" data-page-number=\"6\">\n<div class=\"react-pdf__Page__annotations annotationLayer\" data-main-rotation=\"0\">Once, the models are granted access, you will use using model id<\/div>\n<div data-main-rotation=\"0\"><\/div>\n<\/div>\n<div class=\"react-pdf__Page css-195\" data-page-number=\"7\">\n<div class=\"react-pdf__Page__textContent textLayer\" data-main-rotation=\"0\">\n<div class=\"endOfContent\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19768\" src=\"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-152043-300x144.png\" alt=\"\" width=\"650\" height=\"312\" srcset=\"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-152043-300x144.png 300w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-152043-1024x492.png 1024w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-152043-768x369.png 768w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-152043.png 1041w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/div>\n<div><\/div>\n<\/div>\n<\/div>\n<div class=\"react-pdf__Page css-195\" data-page-number=\"7\">\n<div><\/div>\n<div><span id=\"p58R_mc5\" class=\"markedContent\"><span dir=\"ltr\" role=\"presentation\">This is how the <a href=\"https:\/\/opstree.com\/case-study\/achieving-300-productivity-boost-for-an-edtech-leader-with-genai-using-amazon-bedrock\/\"><strong>GenAI application<\/strong><\/a> will look.<\/span><\/span><\/div>\n<div><\/div>\n<div><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19769\" src=\"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-152554-300x163.png\" alt=\"\" width=\"714\" height=\"388\" srcset=\"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-152554-300x163.png 300w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-152554-1024x557.png 1024w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-152554-768x418.png 768w, https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/Screenshot-2024-12-24-152554.png 1043w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/div>\n<div><\/div>\n<\/div>\n<div class=\"react-pdf__Page css-195\" data-page-number=\"7\">\n<div class=\"react-pdf__Page__annotations annotationLayer\" data-main-rotation=\"0\"><span id=\"p62R_mc1\" class=\"markedContent\"><span dir=\"ltr\" role=\"presentation\">The complete code will be available on my<\/span> <a href=\"https:\/\/github.com\/RajneeshOps\/End-to-End-RAG-Solution.git\" target=\"_blank\" rel=\"noopener\"><span dir=\"ltr\" role=\"presentation\">G<\/span><span dir=\"ltr\" role=\"presentation\">itHub<\/span><\/a><\/span><\/div>\n<div data-main-rotation=\"0\"><\/div>\n<div class=\"react-pdf__Page__annotations annotationLayer\" data-main-rotation=\"0\"><span style=\"font-size: 28px; font-weight: 900;\">Conclusion<\/span><\/div>\n<\/div>\n<div class=\"react-pdf__Page css-195\" data-page-number=\"8\">\n<div class=\"react-pdf__Page__textContent textLayer\" data-main-rotation=\"0\">\n<p><span data-contrast=\"none\">This blog demonstrates the potential of integrating AWS Bedrock, LangChain, and Streamlit to develop a smart, user-friendly <a href=\"https:\/\/opstree.com\/aws-consulting-services\/\"><strong>Retrieval-Augmented Generation (RAG) solution<\/strong><\/a>. Whether you&#8217;re a developer, data scientist, or AI enthusiast, this tech stack provides a solid foundation for building next-generation, context-aware AI applications.<\/span><\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In this blog, we\u2019ll explore the powerful concept of Retrieval-Augmented Generation (RAG) and how it enhances the capabilities of large language models by integrating real-time, external knowledge sources. You&#8217;ll also learn how to build an end-to-end application that leverages this approach for practical use.\u00a0 We\u2019ll begin by understanding what RAG is, how it works, &hellip; <a href=\"https:\/\/opstree.com\/blog\/2024\/12\/24\/end-to-end-rag-solution-with-aws-bedrock-and-langchai\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;End-to-End RAG Solution with AWS Bedrock and LangChain&#8221;<\/span><\/a><\/p>\n","protected":false},"author":244582690,"featured_media":19793,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","jetpack_post_was_ever_published":true,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[36349927],"tags":[768739294,768739423,768739424,768739425,343865],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2024\/12\/End-to-End-RAG-Solution-with-AWS-Bedrock-and-LangChai.jpg","jetpack_likes_enabled":false,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pfDBOm-58I","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/19760"}],"collection":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/users\/244582690"}],"replies":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/comments?post=19760"}],"version-history":[{"count":23,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/19760\/revisions"}],"predecessor-version":[{"id":29511,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/19760\/revisions\/29511"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/media\/19793"}],"wp:attachment":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/media?parent=19760"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/categories?post=19760"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/tags?post=19760"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}