{"id":540,"date":"2024-06-26T13:39:51","date_gmt":"2024-06-26T20:39:51","guid":{"rendered":"http:\/\/184.72.63.26\/?p=540"},"modified":"2024-10-23T20:05:22","modified_gmt":"2024-10-24T03:05:22","slug":"implement-rag-with-aws-bedrock-and-mongodb-atlas","status":"publish","type":"post","link":"https:\/\/www.wallacel.com\/index.php\/2024\/06\/26\/implement-rag-with-aws-bedrock-and-mongodb-atlas\/","title":{"rendered":"Implement RAG with AWS Bedrock and MongoDB Atlas"},"content":{"rendered":"\n<p>While exploring AI use cases, I discovered <strong>Retrieval-Augmented Generation (RAG)<\/strong>. This technique in natural language processing merges information retrieval with text generation. By doing so, it boosts the abilities of language models to generate responses not just from their pre-trained knowledge but also by sourcing information from contextually relevant documents, leading to more accurate, precise, and timely replies.  <\/p>\n\n\n\n<p>In this article, I will experiment with building a generative AI agent using AWS Bedrock to help me in comparing different models of plug-in hybrid SUV available in the market . I already short-listed a few car makers&#8217; models and I want the agent to tailor its responses from these models only. To do so, I will build a knowledge base and populate it with information like catalogues and brochures of these SUVs, in hope that the agent can help me to make a better buying decision.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How RAG works<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"779\" height=\"663\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/rag-4.png\" alt=\"\" class=\"wp-image-548\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/rag-4.png 779w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/rag-4-300x255.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/rag-4-768x654.png 768w\" sizes=\"auto, (max-width: 779px) 100vw, 779px\" \/><\/figure>\n\n\n\n<p>Large Language Model (LLM) are trained on vast volumes of data and use billions of parameters to generate output for tasks like answering questions. RAG optimizes LLM output by referencing a knowledge base outside of its training data source before generating a response.<\/p>\n\n\n\n<p><strong>Data Ingestion:<\/strong> With AWS Bedrock, you build a knowledge base by populating it with external data (e.g. documents uploaded to a S3 bucket). These documents are split into chunks, converted to embeddings, and stored within a vector database (e.g. Mongodb Atlas).<\/p>\n\n\n\n<p><strong>Information Retrieval:<\/strong>  When user asks a question, the embedded foundation model in AWS Bedrock utilizes the vector index in the database to find the most relevant documents that match the query. The model then uses these information with its training data to generate a more relevant and up-to-date response for the user.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Foundation Models<\/h2>\n\n\n\n<p>AWS Bedrock supports a range of foundation <a href=\"https:\/\/docs.aws.amazon.com\/bedrock\/latest\/userguide\/models-supported.html?icmpid=docs_bedrock_help_panel_providers\">models<\/a> from Amazon&#8217;s own Titan models to other AI companies and in this setup I will try with both the <strong>Titan Embeddings G1 &#8211; Text<\/strong> and <strong>Claude 3 by Anthropic. <\/strong>They are both ideal for open-ended text generation and conversation chat, and supporting RAG. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1007\" height=\"569\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-78.png\" alt=\"\" class=\"wp-image-550\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-78.png 1007w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-78-300x170.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-78-768x434.png 768w\" sizes=\"auto, (max-width: 1007px) 100vw, 1007px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1005\" height=\"393\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/titan.png\" alt=\"\" class=\"wp-image-559\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/titan.png 1005w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/titan-300x117.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/titan-768x300.png 768w\" sizes=\"auto, (max-width: 1005px) 100vw, 1005px\" \/><\/figure>\n\n\n\n<p>To request access for models, go to AWS Bedrock console and choose Model access, and select the models you want to try.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"998\" height=\"802\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/models.png\" alt=\"\" class=\"wp-image-560\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/models.png 998w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/models-300x241.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/models-768x617.png 768w\" sizes=\"auto, (max-width: 998px) 100vw, 998px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Data Source for Knowledge Base<\/h2>\n\n\n\n<p>To prepare the data,  I download brochures and catalogues of different car makers&#8217; PHEV SUVs that are available in the market with similar price range, and upload them to a S3 bucket. AWS Bedrock knowledge base supports the following document file formats:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"401\" height=\"354\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/fileformat.png\" alt=\"\" class=\"wp-image-553\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/fileformat.png 401w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/fileformat-300x265.png 300w\" sizes=\"auto, (max-width: 401px) 100vw, 401px\" \/><\/figure>\n\n\n\n<p>I create a new S3 bucket for storing my documents.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"830\" height=\"630\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-80.png\" alt=\"\" class=\"wp-image-554\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-80.png 830w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-80-300x228.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-80-768x583.png 768w\" sizes=\"auto, (max-width: 830px) 100vw, 830px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1017\" height=\"774\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/s3-1.png\" alt=\"\" class=\"wp-image-555\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/s3-1.png 1017w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/s3-1-300x228.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/s3-1-768x584.png 768w\" sizes=\"auto, (max-width: 1017px) 100vw, 1017px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Create a AWS Bedrock Knowledge Base<\/h2>\n\n\n\n<p>To create a knowledge base, go to AWS Bedrock console and choose Knowledge base<br>(Note: You must not sign in as root as it cannot create a knowledge base)<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"890\" height=\"720\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-81.png\" alt=\"\" class=\"wp-image-556\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-81.png 890w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-81-300x243.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-81-768x621.png 768w\" sizes=\"auto, (max-width: 890px) 100vw, 890px\" \/><\/figure>\n\n\n\n<p>Use the S3 bucket just created as the data source<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"873\" height=\"348\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-82.png\" alt=\"\" class=\"wp-image-557\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-82.png 873w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-82-300x120.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-82-768x306.png 768w\" sizes=\"auto, (max-width: 873px) 100vw, 873px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"892\" height=\"730\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-83.png\" alt=\"\" class=\"wp-image-558\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-83.png 892w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-83-300x246.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-83-768x629.png 768w\" sizes=\"auto, (max-width: 892px) 100vw, 892px\" \/><\/figure>\n\n\n\n<p>Now choose &#8216;<strong>Titan Embeddings G1 &#8211; Text<\/strong>&#8216; as the embeddings model for converting the documents in S3 into chunks in our vector database. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"668\" height=\"744\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-85.png\" alt=\"\" class=\"wp-image-563\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-85.png 668w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-85-269x300.png 269w\" sizes=\"auto, (max-width: 668px) 100vw, 668px\" \/><\/figure>\n\n\n\n<p>Note: AWS introduced the newer Titan Text Embeddings v2 model in <a href=\"https:\/\/aws.amazon.com\/blogs\/aws\/amazon-titan-text-v2-now-available-in-amazon-bedrock-optimized-for-improving-rag\/#:~:text=Amazon%20Titan%20Text%20Embeddings%20V2%20overview&amp;text=We%20measured%20that%20vectors%20with,97%20percent%20of%20the%20accuracy\">April 2024<\/a> and states that it is optimized for RAG, however when I tried to use this model, it failed to create the vector store with using MongoDB Atlas.<\/p>\n\n\n\n<p>AWS Bedrock supports a wide range of vector databases including its own Amazon OpenSearch, but in this setup I will use MongoDB Atlas for its quick, easy deployment and optimized performance.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"694\" height=\"759\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-86.png\" alt=\"\" class=\"wp-image-564\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-86.png 694w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-86-274x300.png 274w\" sizes=\"auto, (max-width: 694px) 100vw, 694px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Sign Up for MongoDB Atlas<\/h2>\n\n\n\n<p><a href=\"https:\/\/account.mongodb.com\/account\/register\">Login or Signup<\/a> an account to MongoDB Atlas for an account. Create a MongoDB Atlas cluster with a <strong>M10<\/strong> configuration (M0 free cluster will not work) and setup user and network access.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"717\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/cluster-1024x717.png\" alt=\"\" class=\"wp-image-567\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/cluster-1024x717.png 1024w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/cluster-300x210.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/cluster-768x538.png 768w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/cluster.png 1090w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Under Database Access, add a database user with read and write access to the database.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"853\" height=\"715\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-92.png\" alt=\"\" class=\"wp-image-573\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-92.png 853w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-92-300x251.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-92-768x644.png 768w\" sizes=\"auto, (max-width: 853px) 100vw, 853px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"485\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/useraccess-1024x485.png\" alt=\"\" class=\"wp-image-570\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/useraccess-1024x485.png 1024w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/useraccess-300x142.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/useraccess-768x363.png 768w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/useraccess.png 1105w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Under Network Access, add an entry to allow access from anywhere.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"507\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/networkaccess-1024x507.png\" alt=\"\" class=\"wp-image-569\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/networkaccess-1024x507.png 1024w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/networkaccess-300x149.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/networkaccess-768x381.png 768w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/networkaccess.png 1108w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Create a database and collection in MongoDB Atlas cluster<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"567\" height=\"361\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-91.png\" alt=\"\" class=\"wp-image-572\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-91.png 567w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-91-300x191.png 300w\" sizes=\"auto, (max-width: 567px) 100vw, 567px\" \/><\/figure>\n\n\n\n<p>Under Atlas Search, create a vector search index and select Altas Vector Search<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"980\" height=\"665\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-95.png\" alt=\"\" class=\"wp-image-576\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-95.png 980w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-95-300x204.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-95-768x521.png 768w\" sizes=\"auto, (max-width: 980px) 100vw, 980px\" \/><\/figure>\n\n\n\n<p>Select the database and collection where the embeddings are stored, then enter the following JSON in the index definition. These fields will need to match the fields in the AWS Bedrock knowledge base configuration.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"json\" class=\"language-json\">{\n  \"fields\": [\n    {\n      \"numDimensions\": 1536,\n      \"path\": \"bedrock_embedding\",\n      \"similarity\": \"cosine\",\n      \"type\": \"vector\"\n    },\n    {\n      \"path\": \"bedrock_metadata\",\n      \"type\": \"filter\"\n    },\n    {\n      \"path\": \"bedrock_text_chunk\",\n      \"type\": \"filter\"\n    }\n  ]\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"972\" height=\"628\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-96.png\" alt=\"\" class=\"wp-image-577\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-96.png 972w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-96-300x194.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-96-768x496.png 768w\" sizes=\"auto, (max-width: 972px) 100vw, 972px\" \/><\/figure>\n\n\n\n<p>Now that our vector database is created, we want to store our MongoDB database username and password to AWS Secrets Manager for enhanced security. Go to Secrets Manager console and choose &#8216;Store a new secret&#8217;.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"815\" height=\"602\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-93.png\" alt=\"\" class=\"wp-image-574\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-93.png 815w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-93-300x222.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-93-768x567.png 768w\" sizes=\"auto, (max-width: 815px) 100vw, 815px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"627\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-94-1024x627.png\" alt=\"\" class=\"wp-image-575\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-94-1024x627.png 1024w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-94-300x184.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-94-768x470.png 768w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-94.png 1103w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Let&#8217;s go back to AWS Bedrock console and continue the MongoDb configuration setup. <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Hostname: <em>&lt;mongodb cluster hostname&gt;<\/em><\/li>\n\n\n\n<li>Database name:  <strong>bedrock_db<\/strong><\/li>\n\n\n\n<li>Collection name: <strong>bedrock<\/strong><\/li>\n\n\n\n<li>Credentials secret ARN: <em>Use the ARN from database credentials in AWS Secrets Manager<\/em><\/li>\n\n\n\n<li>Vector search index name: <strong>vector_index<\/strong><\/li>\n\n\n\n<li>Vector embedding field path: <strong>bedrock_embedding<\/strong><\/li>\n\n\n\n<li>Text field path: <strong>bedrock_text_chunk<\/strong><\/li>\n\n\n\n<li>Metadata field path: <strong>bedrock_metadata<\/strong><\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"663\" height=\"474\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-97.png\" alt=\"\" class=\"wp-image-578\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-97.png 663w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-97-300x214.png 300w\" sizes=\"auto, (max-width: 663px) 100vw, 663px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1005\" height=\"495\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-101.png\" alt=\"\" class=\"wp-image-582\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-101.png 1005w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-101-300x148.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-101-768x378.png 768w\" sizes=\"auto, (max-width: 1005px) 100vw, 1005px\" \/><\/figure>\n\n\n\n<p><strong>Hostname<\/strong> can be obtained from the connection string in MongoDB Atlas&#8217;s Cluster Overview-&gt;Connect-&gt;Shell<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"298\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-98-1024x298.png\" alt=\"\" class=\"wp-image-579\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-98-1024x298.png 1024w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-98-300x87.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-98-768x224.png 768w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-98.png 1112w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"761\" height=\"702\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-99.png\" alt=\"\" class=\"wp-image-580\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-99.png 761w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-99-300x277.png 300w\" sizes=\"auto, (max-width: 761px) 100vw, 761px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"770\" height=\"549\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/hoststring-2.png\" alt=\"\" class=\"wp-image-604\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/hoststring-2.png 770w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/hoststring-2-300x214.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/hoststring-2-768x548.png 768w\" sizes=\"auto, (max-width: 770px) 100vw, 770px\" \/><\/figure>\n\n\n\n<p>It takes a few minutes to create the knowledge base. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"998\" height=\"352\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-102.png\" alt=\"\" class=\"wp-image-584\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-102.png 998w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-102-300x106.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-102-768x271.png 768w\" sizes=\"auto, (max-width: 998px) 100vw, 998px\" \/><\/figure>\n\n\n\n<p>To ensure our data source remains current, we need to synchronize it either periodically or each time new documents are uploaded to the S3 bucket.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"235\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/sync-datasource-1024x235.png\" alt=\"\" class=\"wp-image-586\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/sync-datasource-1024x235.png 1024w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/sync-datasource-300x69.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/sync-datasource-768x177.png 768w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/sync-datasource.png 1131w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Create a AWS Bedrock Agent<\/h2>\n\n\n\n<p>In order to query the knowledge base, we need to create a Bedrock Agent. Go to AWS Bedrock console, choose Agents and select Create Agent. I want the agent to answer my questions like an expert in the automotive industry and help me choose the best SUV model.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Select model: <strong>Anthropic Claude 3 Haiku<\/strong><\/li>\n\n\n\n<li>Instructions for agent: <strong>You are an automotive expert. Your role is to help customers to understand and choose the best plug in hybrid model auto in the market<\/strong><\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"873\" height=\"724\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-107.png\" alt=\"\" class=\"wp-image-590\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-107.png 873w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-107-300x249.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-107-768x637.png 768w\" sizes=\"auto, (max-width: 873px) 100vw, 873px\" \/><\/figure>\n\n\n\n<p>Add the knowledge base containing the catalogues and brochures to the agent.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"704\" height=\"444\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/image-108.png\" alt=\"\" class=\"wp-image-591\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-108.png 704w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/image-108-300x189.png 300w\" sizes=\"auto, (max-width: 704px) 100vw, 704px\" \/><\/figure>\n\n\n\n<p>Now I can ask the agent questions like &#8216;<em><strong>Which model has the fastest charging time?<\/strong><\/em>&#8216; or &#8216;<em><strong>Which suv has the longest ev driving range?<\/strong><\/em>&#8216;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"873\" height=\"785\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/agent-1.png\" alt=\"\" class=\"wp-image-594\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/agent-1.png 873w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/agent-1-300x270.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/agent-1-768x691.png 768w\" sizes=\"auto, (max-width: 873px) 100vw, 873px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Building a RAG Chatbot<\/h2>\n\n\n\n<p>With Amazon Bedrock API, I can make a chatbot and embed it to a website and interact with my knowledge base. This can be useful for a variety of use cases like providing customer service with product specific help to customers, or legal advice by retrieving relevant case laws, statutes, and legal documents. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"707\" height=\"883\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/chatbotV2.gif\" alt=\"\" class=\"wp-image-653\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Clean Up<\/h2>\n\n\n\n<p>When we are done experimenting with RAG, we can either pause the MongoDB Atlas cluster to save some running cost, or terminate it completely.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"528\" height=\"454\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/pause.png\" alt=\"\" class=\"wp-image-605\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/pause.png 528w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/pause-300x258.png 300w\" sizes=\"auto, (max-width: 528px) 100vw, 528px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"571\" height=\"472\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/06\/terminate.png\" alt=\"\" class=\"wp-image-606\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/terminate.png 571w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/06\/terminate-300x248.png 300w\" sizes=\"auto, (max-width: 571px) 100vw, 571px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>This article demonstrates how to easily access AI models like Amazon Titan and Antropic Claude 3 using AWS Bedrock and MongoDB Atlas. Thank you for reading, and I hope you found it helpful.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While exploring AI use cases, I discovered Retrieval-Augmented Generation (RAG). This technique in natural language processing merges information retrieval with text generation. By doing so, it boosts the abilities of language models to generate responses not just from their pre-trained knowledge but also by sourcing information from contextually relevant documents, leading to more accurate, precise, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":611,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[35,38,36,37,34],"class_list":["post-540","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aws","tag-bedrock","tag-claude-3","tag-generative-ai","tag-mongodb-atlas","tag-rag"],"_links":{"self":[{"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/posts\/540","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/comments?post=540"}],"version-history":[{"count":27,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/posts\/540\/revisions"}],"predecessor-version":[{"id":1019,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/posts\/540\/revisions\/1019"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/media\/611"}],"wp:attachment":[{"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/media?parent=540"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/categories?post=540"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/tags?post=540"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}