iTranslated by AI
re:Invent 2024: Best Practices for Generative AI Observability from AWS
Introduction
By transcribing various overseas lectures into Japanese articles, we aim to make hidden, high-quality information more accessible. This project explores the following presentation!
📖 AWS re:Invent 2024 - Best practices for generative AI observability (COP404)
In this video, Denis V. Batalov, AI/ML Tech Leader at AWS, and Greg Eppel from the CloudOps field explain observability in Generative AI. They discuss monitoring Generative AI using CloudWatch across four layers, specifically showcasing an implementation example of a RAG architecture that combines Bedrock and LangChain. They share abundant practical insights, such as the fact that CloudWatch is a large-scale system processing 40 quadrillion metrics per month, how to collect user feedback using the Embedded Metric Format, and how to control inappropriate outputs using Guardrails. A unique aspect is how they clearly explain the challenges and solutions of modern Generative AI while referencing articles from BYTE magazine in the 90s.
- This article was automatically generated from the video. Please watch the original video for accurate information, as there may be typos, omissions, or incorrect content.
- Clicking on the image will take you to the corresponding scene in the video.
For transcript articles related to re:Invent 2024, please check this Spreadsheet where we have summarized the information!
Main Content
Introduction to the lecture on Generative AI Observability
My name is Denis V. Batalov. I serve as the Worldwide Tech Leader for AI/ML, and I am responsible for coordinating the work of over 1,000 solution architects and customer-facing experts who support the adoption of AI/ML technologies at AWS. Today, I am joined by my colleague Greg Eppel from the CloudOps field. We would like to talk about the important topic of Observability in Generative AI. Generative AI has created a whirlwind of innovation for all of us, but at the same time, we have also experienced various trials and errors.
Today, we will first discuss why it is sometimes difficult to transition POCs to production environments. We will touch on the difficulties of implementing Generative AI correctly, and of course, since understanding why applications behave or malfunction in certain ways is clearly related to observability, we will cover that as well. Next, we will talk about the components of a Generative AI platform. Many customers are starting to build platforms of this nature, and we will look at the various elements of these platforms and concerns regarding observability. Afterward, Greg will explain the most important part: how to practice Generative AI observability. We also plan to discuss CloudWatch and its various features.
History of AI and Current Challenges with Generative AI
While preparing for this talk, I thought it would be interesting to look back at the past. In the 90s, I still had a collection of BYTE magazines. You might remember that it was a very popular magazine among software engineers and IT professionals. I used to collect clippings from articles and organize them into small notebooks. I thought it would be interesting to use a few clippings from the early to mid-80s to explain a few aspects. To prove that this is real, here is a job advertisement for a business person from that time—what we might call an Observability Engineer today. Also, please take a look at the Microsoft logo on the right. Is anyone here from Microsoft? This is quite interesting; it's a design with an 'O' inside a hatched circle, which I believe was called 'blit' internally. People at the time actually loved this logo. This is from the mid-80s.
This is another clipping from April 1985. It's really interesting when you look back at it. If you read it carefully, it says, "This auxiliary brain lobe answers questions with information beyond the range of your own memory, suggests plausible courses of action, and helps you ask questions to draw out relevant facts." Doesn't this remind you of the RAG (Retrieval Augmented Generation) architectures or perhaps agent systems in today's Generative AI? It's interesting that people were already thinking about things like this back then. And of course, the classic image of a brain being replaced by a circuit board is also there. It seems this was as popular an image then as it is now.
Interestingly, in the same issue featuring AI, there is a picture of an alien-like slug saying, "I've come to debug your code." As you can see, coding assistants were being thought about back then as well. Last year, 2023, was truly the year of the POC. Everyone tried to build POCs with Generative AI. I believe this year is the year to move those POCs into production, but obviously, not all POCs have made it to production. In fact, according to some studies, three-quarters of POCs get stuck without ever being moved to production or seeing the light of day.
Quality and Challenges of Generative AI Systems
There are several reasons for this. In traditional Machine Learning, accuracy has long been considered the most important characteristic. However, in Generative AI, it has become a bit more complex. In particular, we need to think about the quality of the system as a whole. This sometimes manifests as presenting relevant and useful information, but we have all heard about hallucinations—the incorrect outputs. Therefore, factual accuracy is crucial. Factual accuracy needs to be firmly rooted in context gained from the internet or proprietary Knowledge Bases.
Also, these systems need to be robust. In other words, you need to ensure that the output does not change drastically even if the input is slightly modified. With state-of-the-art technology, achieving this is not really easy. Because these models are probabilistic and non-deterministic, you need to understand their behavioral characteristics well.
This has caused quite a stir when people have used it inappropriately. For example, when lawyers look for case law, they might look at tools with generative properties; if they have seen that case law enough times in the training dataset, it will generate an accurate answer, but often it generates an inaccurate one. This does not seem to be a one-off event, but rather a pattern. This is another completely different case that happened in Canada. Furthermore, there are issues with other information that Chatbots present. This is not necessarily related to hallucinations, but rather the question of whether the advice provided is truly accurate according to policy.
Recently, there was news that hallucinations were occurring in AI medical transcription systems. While some of these transcription errors are easy for doctors to spot when reading them, others could potentially change the meaning significantly without anyone noticing. This becomes a truly critical issue when medical teams review these past transcription records. Such mistakes are undoubtedly costly.
Regarding performance, we are well familiar with IT performance metrics. We have become accustomed to very high rates—latency in microseconds and millions of transactions per second—approaching the limits of the laws of physics and signal transmission. However, with Generative AI, it feels like we have regressed. Now, we are talking about transactions per minute and latency in the order of seconds. Interestingly, in the 80s, 15 seconds was the gold standard. That is, if a computer responded within 15 seconds, it was great; any longer, and people would start to get frustrated and feel dissatisfied. It is interesting that these metrics are frequently mentioned, and we face a similar situation today in Generative AI, where response times in the order of seconds are required.
This ultimately leads to cost considerations. We want to ensure we have ways to observe the costs of our systems—both making estimations beforehand and seeing the actual costs in production are important. This relates to running models on single or multiple instances, or consuming instance time where fixed costs are incurred per hour. When using Software-as-a-Service like Amazon Bedrock, costs are measured by input and output tokens. The underlying IT characteristics remain very important.
Generative AI Platform Components
Today, I will discuss the observable aspects related to these three main concerns, and why it is difficult to correctly implement these Generative AI systems in production. Let’s look at what the current Generative AI platform looks like and its key components. Many companies start by tackling a Foundation Model hub—a way to enable access to various models. Market competition is constant, and new models are emerging one after another, so it is important to have choices and flexibility to access them. It may also be important not to rely solely on the knowledge built into the models.
Of course, you might want to incorporate your own data, or corporate proprietary data. Here, patterns such as Retrieval Augmented Generation (RAG) are naturally introduced as additional components. While that might suffice for some models, in other cases, model customization or adaptation may be necessary. You should also consider this important component of Gen AI architecture.
When you start higher-level application orchestration, further components that may include agent architecture are added. A mature Gen AI platform must support Ops. Ops has several important concerns: for example, prompt management, tracking version changes, upgrading Foundation Model versions, and updating Vector Databases with the latest documents held by the company.
Governance and the observable control plane are two important aspects that exist. In this talk, we will focus on the latter. Finally, we must not forget the underlying IT infrastructure. This is an overview of the considerations and components of a typical Gen AI platform.
Practicing Observability with CloudWatch
We will not cover all of this in today's talk. We will focus on three components of the platform, their associated observability challenges, and how to build observability on AWS. Looking closer at this Foundation Model Hub, it is often implemented in the form of an LLM Gateway, FM Gateway, or AI Gateway. There are various options, including open-source, custom, and proprietary solutions. Here, you need to establish model access control, some form of registry, cost logs, throttling, and failover mechanisms.
From an observability perspective, you will be dealing with API interfaces to these models, so you should focus on the number of base model calls, latency, tokens consumed, and various model inference parameters related to specific inferences. One common way to leverage this Foundation Model is the Retrieval Augmented Generation (RAG) pattern. Since it is a very common pattern, let's focus on this.
This is a general high-level diagram. You might be accessing large amounts of data locked in various SaaS platforms like Salesforce, or others. You might also have ETL jobs that generate documentation related to applications or unstructured document formats like logs that you want to extract information from. As a general mechanism for RAG, we index individual document chunks from these document sources. You need to consider chunking strategies and where to set chunk boundaries, as these decisions will affect the quality of your results.
We pass these document chunks through an embedding model. While this model is shown outside the diagram, it might already be available through the Model Hub. The role of embedding is to transform these chunks into vectors. These vectors are stored in a Vector Database, for which there are also many options. Ultimately, when running this application in a production environment, indexing is done as a preprocessing step, and additional indexing might occur continuously online whenever new documents are added.
Orchestrating this continuous indexing process can be a challenge. In production, we typically map queries into vector space through the same embedding model, search for similar vectors based on cosine similarity through the Vector Database, and extract all chunks to construct context. Many advanced systems combine traditional information retrieval techniques like keyword search in addition to embedding-based search. Especially when dealing with policy documents that have hierarchical structures, you can incorporate hierarchical representations of data to make it more complex, navigating that structure when constructing context for specific queries.
I'll introduce how to build this RAG system yourself. You can achieve a managed solution for this architecture using Amazon Bedrock. Because Amazon Bedrock Knowledge Bases handle indexing and chunking for you. Several customization options are also available for this process. Furthermore, you can now apply Amazon Bedrock Guardrails, which has become available as a standalone API. These Guardrails are not limited to Bedrock; they can be applied to any model, whether on AWS or off AWS. With Guardrails, you can filter prompts and completions based on standard characteristics related to language, such as hate speech, sexual content, insults, and potential prompt attacks. You can also set blocked topics or out-of-scope conversations by describing topics like investment advice or politics in natural language, and Guardrails will automatically classify prompts and completions into those topics to block such conversations.
Implementation of Observability with CloudWatch
One recently added feature is the ability to add contextual grounding and relevance checks. You have a way to verify the retrieved context and the prompt's response to see if the response is based on context and relevant to the question. In such orchestration models, you might be interested in observability from various perspectives. Let's explain this hierarchical approach. At the top level, there are component-level metrics such as call counts, errors, latency, and resource utilization. Next, we move to the orchestration layer, including Retrieve Augmented Generation, agent systems, and chain traces. At the third level, we can look at more advanced metrics and analytics, such as when these Guardrails were triggered, interventions made on the Guardrail side, and embedding drift, where we examine the vector space embeddings of conversation topics to recognize if their centroids are shifting. Finally, there is a way to directly collect feedback from end-users and incorporate it into the system.
Here, I would like to welcome my colleague Greg to the stage to talk about the aspects of observability. I will use the remaining time to explain these four layers. I have prepared a 2-3 minute demo for each layer, so let's start by looking at the first layer. Before that, I want to explain the three pillars of observability we think about at AWS. Those are metrics, logs, and traces, and CloudWatch supports all of them.
As you may know, CloudWatch has a long history. It's not the first service, but it is one of the earliest services, and it's a massive observability system. Our VP of Observability was introducing the latest metrics in his innovation talk, and currently, we observe 20 quadrillion metrics every month. We ingest over 13 exabytes of logs every month and store about half a trillion traces within CloudWatch. This is a very large-scale system, and many people don't understand how large-scale CloudWatch is actually operated.
Metrics, logs, traces—none of these is more important than the others. I've spoken to hundreds of customers about observability over the past few years, and many say, "We no longer need logs or metrics; traces are enough." However, I think of this like a three-legged stool—you need all three. You need to correlate these three different observability signals. Logs tell you what the input prompts to the Foundational Model were and what the output responses to users were. Metrics help you understand the increase in prompt latency when using those Foundational Models. And traces are truly helpful for understanding all the distributed components within a RAG architecture.
Implementing Tracing with OpenTelemetry
I won't go into detail on this entire slide. I just want to say—if you know CloudWatch, it's completely different from what it used to be. We've added many features in the last two or three years, and more are scheduled to be announced this week. If you haven't looked at CloudWatch in a while, I highly recommend checking it out again. Many sessions are planned this week, but CloudWatch really has a rich set of features.
Now, let's look at the first layer in more detail. As Dennis mentioned, many services send metrics, and sometimes logs or traces, directly to CloudWatch. Usually, these metrics are sent automatically, and there is no additional cost to the customer. This means as soon as you start using services like Amazon Bedrock, Amazon OpenSearch, or Amazon S3, those service teams automatically start sending metrics to your account, so you can understand the performance of those services.
I highly recommend bookmarking or taking a screenshot of this. There is a page where you can list all the services that send metrics to CloudWatch. I've provided three QR codes—one is a link to this page, and the other two are links to the Bedrock and SageMaker pages. When you start using new services, especially Generative AI-related services, I recommend visiting this page to understand the metrics we are sending to your account.
What is important but often overlooked is understanding the dimensions of the metrics we send. The screenshot on the right is an example of latency metrics and token counts from Bedrock. You might not have noticed, but we are applying dimensions here. Not only can you get the total input/output token counts for all models you are using, but you can also get more detailed information. You can actually compare Claude 2 and Claude Instant v1. All Bedrock models provide these metrics and allow for comparative analysis. This is very useful and relates to the point Dennis mentioned—these models each have different costs. Some models might be fast, and others might be slow. This information is helpful for understanding usage and can also be used for cost estimation.
Another aspect is that many people use these metrics for alarms. I talk to many people about alarm fatigue, and it is a really difficult problem. We have been providing a feature called Composite Alarms for a few years, but many people don't seem to know about its existence. This is the idea of creating a hierarchical or tree structure for alarms. For events that impact customers, usually not just one alarm, but a series of alarms occur. By correlating these alarms when similar events happen next time, you can create smarter alarms. Here, I have taken two latency alarms set for Model A and Model B of an LLM as an example. It's a simple example, but you can build complex boolean expressions combining up to 100 different alarms. The great thing is that you don't have 50-60 alarms going off at once. While maintaining 50-60 alarms, you can consolidate them into a single Composite Alarm and send notifications to the SRE team from there.
Another thing to be careful about is model invocation logging within Bedrock. Dennis touched on this a bit as well, but you need to enable it. In Bedrock, while metrics are sent automatically, you need to configure logging within Bedrock itself. The configuration is very simple and takes only a minute or two to complete. Once configured, logs for all model invocations across the four APIs shown on the left will begin to be recorded.
The final part, which I'll show in more detail in the demo, is this log pattern analysis. We are using machine learning in the backend, and we released this last year. As you collect invocation logs, for example, if you had 10,000 logs in the last hour, you might want to understand where they came from and the patterns within those logs. This is a new operator for CloudWatch Logs Insights that helps with that understanding.
Let's move on to the first demo. I'll switch to my laptop. Yes. I need to go back to another screen to explain the setup of the demo. After that, we'll move to the video. All four of my demos are based on the chatbot app I created. This is a Python application using Streamlit. Streamlit is a Python framework designed primarily for data engineers that makes it easy to build web apps. To communicate with Amazon Bedrock, I am not calling the Bedrock API directly but am using LangChain. I am using OpenTelemetry for instrumentation. OpenTelemetry sends trace data, metrics, and logs to the CloudWatch agent. The CloudWatch agent supports OpenTelemetry, acting as an endpoint to send that data to CloudWatch.
This is the architecture for the entire set of four demos that I'm about to show you. I'll explain the code on the slides, and then we'll move to the demo. For setting up Bedrock and LangChain, this is all that is required. Basically, you instantiate a ChatBedrock object, pass in the runtime from Bedrock, and specify the model ID. And there are a few arguments for Streamlit. If you've never used Streamlit, this is the app I'm about to show you—it essentially only takes about 30 lines of code to build a fully functional app. It's a great way to do a proof of concept in a presentation like this.
Now, let's move to the demo. I'll hit the play button here. This is about two minutes long. This is the actual Streamlit application set up with LangChain and OpenTelemetry. Let's ask a few questions. Write a paragraph about Amazon CloudWatch—and it returns text about CloudWatch. Next, let's ask it to write information about Amazon Bedrock. Let's wait for the response.
What just happened is that Bedrock automatically sends metrics to CloudWatch—no special configuration required. The Bedrock team, i.e., the service team, sends those metrics directly to your account. You can go in there and actually see individual metrics. I was using Claude Haiku, and let's look at the invocation latency and invocation count for what we just did in the application.
What you see here is a single small point. This is because we only sent two prompts. So, you don't get a clean line graph, but there are basically two points showing two calls, and it shows the average latency over time. I also ran another application that continuously sends information to Bedrock and receives responses. This is a better example, showing how the latency for different models changes over time. Having this dimensionality in metrics is very useful, and it allows you to compare and contrast different models.
Let's move on to the logs. We'll check the latency changes over time and then look at the logs. Since I have already configured invocation logging in Bedrock, let's navigate to CloudWatch logs. There is a bedrock/invocations log group. Running the query should give us about four results. Then these log entries appear. When you interact with the chatbot built with Python using LangChain, Bedrock sends logs directly to CloudWatch. You can check the information sent in the output response.
It is very easy to set up and use. It is extremely powerful because you get all the information regarding the actual user interactions with the LLM. And this is another example of an application that sent many messages (about 600-700) to Bedrock.
Let me show you how log summarization works using machine learning. Applying the pattern operator to the field categorizes the 600-700 messages into about 23 different patterns. You can see that one of the top patterns accounts for about 45%. By tokenizing the different elements in the logs, you can effectively summarize users' Bedrock usage and quickly analyze a large volume of logs.
Amazon Bedrock Guardrails for Advanced Metrics and Analysis
Let's return to the deck and move on to layer 2. In layer 2, we cover agents and chain tracing, diving deeper into the tracing aspect. For those new to how tracing works, I'll provide a brief overview using a typical example where Amazon API Gateway communicates with AWS Lambda to place something in Amazon S3. These are all HTTP requests. Ideally, you want traces to flow from component to component. This works through a series of spans, where a span is a part of a trace, and a collection of spans constitutes one complete trace. In general, X-Ray or CloudWatch uses a trace ID, which is a longer string. Each of these spans also has an ID, and these two elements combined form the trace context.
Often, it's difficult to grasp a complete view or the big picture of the entire system. This usually happens because the trace context is lost from boundary to boundary. In this example, it's very simple because all of these components natively support X-Ray. The trace context from API Gateway is passed to Lambda. Lambda recognizes this as trace context and passes it further downstream, so it works smoothly without extra work. Now, let's see how this actually works with the application we demoed earlier. In this case, we have a chatbot app that is a Python application using Streamlit and LangChain. These components, at least for now, do not inherently understand tracing, but they collaborate with services like Amazon Bedrock and Amazon OpenSearch. The solution here is OpenTelemetry, which requires some instrumentation within the code.
Let me show you how to set it up in your application. In this demo, I show an example of about 20 lines of code needed to set up the Knowledge Bases feature in Amazon Bedrock for a RAG architecture. You create a Chat Bedrock instance, execute the chain, and later invoke it for instrumentation. When using the OpenTelemetry Python SDK, the amount of code required to instrument your application is essentially this much. You need to set up the trace provider, configure the exporter, establish a span processor, and implement additional instrumentation for the AWS SDK and HTTP requests.
Now, let's go into more technical detail. There are various ways to set up spans. You can tie spans to functions, where each function called in your Python app creates a new segment or sub-segment. What I'm doing here is creating a chain of nested spans. There is a parent span for the ChatBot app and child spans for LangChain within it. I will show you how this looks in CloudWatch in the demo. Here, I'm explicitly setting spans and child spans within the application. You can add various attributes to these spans. For example, you can include the model ID you are using or the prompt the user sent.
For this demo, let's switch to the demo laptop. This will be a two-minute demo. What I am going to show you is how to set up such a RAG architecture in Amazon Bedrock, which is very simple. When you go to Bedrock and set up a knowledge base, an Amazon OpenSearch Serverless cluster is created as the vector database. A knowledge base is configured here. Previously, I set up a new data source. Multiple data source options are available, but this time I simply created an Amazon S3 bucket. Let's look at that S3 bucket. It contains a single PDF. Do you know what this P17 PDF is? It is Publication 17, the IRS personal tax code.
This is the 2023 version, which is about 120 pages of text, so I placed this in S3. Since I configured the knowledge base in Amazon Bedrock, I will start the interaction. Let's return to the application, run it, and start asking about the standard deduction. For those outside the US, the IRS allows you to choose between the standard deduction or itemizing your deductions for the year, so I will ask about that amount.
Let's pull information from the 100-page IRS PDF and ask about the standard deduction amount. The standard deduction changes depending on whether you are married or single, and also by year, so I will ask about those amounts. After getting that response, I will ask "What is CloudWatch?" as a question unrelated to taxes. Then, a response will be returned stating that it cannot answer because it is outside the scope of that knowledge base.
Since I have already incorporated OpenTelemetry, let's take a closer look. Let's go to traces and execute a query. Let's view and check the traces. With just the few lines of code I showed you earlier, you get traces like this. You can see two calls: a call to the Bedrock runtime and a call to the Bedrock agent runtime from the chatbot application.
You can see different operations like retrieve and invoke model. When you scroll down, the segments and the sub-segments under them are displayed. There is a part of the code for LangChain invoke that I added with OpenTelemetry, where the two pieces of metadata I set (model ID and prompt) are displayed. This is an excellent way to understand distributed systems, and the RAG architecture is a good example of this. It helps in understanding where time is being spent in the interactions between different components.
Now, let's move on to layer 3. Before that, I want to talk about open source OpenTelemetry projects that you might be familiar with, such as OpenLLMetry and OpenLIT. These projects aim to provide further detailed visibility into LLMs. I won't do another demo, but I have prepared a screenshot showing that I actually used OpenLLMetry. This is an example of how these projects, which you can find on GitHub, provide further detailed visibility into how LangChain is used and how models are called in LLMs.
Let's proceed to advanced metrics and analytics in layer 3. Here, we will focus on Guardrails. Due to time constraints, I cannot explain embedding drift in detail, but I will briefly explain this slide. As Dennis already explained, Guardrails are a way to apply safety measures to foundational models and detect harmful content or content undesirable for chatbots. These are the metrics I mentioned earlier. These are metrics obtained from Amazon Bedrock Guardrails, which include invocation latency, throttling, and the number of calls intervened by Guardrails.
This is another example. Let's move on to the demo. Let's set up a Guardrail and see how it appears in CloudWatch for my application. Here is a Guardrail, and I will create a new one. Let's try to explore how to avoid taxes and see what happens. I'll name it COP404-guardrail and proceed to the next step. There are many configuration options, but I will focus specifically on misconduct. There are options for insults, hate, violence, etc., but I will focus only on misconduct.
I will set the intensity high. Let's create this Guardrail. Now, I will test it directly in the console. Let's try to explore how to avoid taxes by looking for tax mitigation or offshore tax schemes. I will input the prompt: "Tell me how to set up offshore tax schemes to avoid taxes." As you can see, the system intervened and blocked it. The reason is that it detected misconduct with high intensity and high confidence. This Guardrail seems effective. I will create version 1. As for the code changes, I will pause briefly, but I just added a new property called Guardrails in the LangChain code.
By simply pasting this unique identifier and referencing the Guardrail, it is automatically applied to the Chatbot. Once I enter the ID, let's run the application again. Just like before, if I ask about how to avoid taxes using offshore schemes, the same response should be returned. Then, I will check the metrics that Amazon Bedrock Guardrails is sending directly to CloudWatch. As expected, a response was returned stating that it cannot assist with such actions. That's great - the Guardrail is working.
Let's go back to CloudWatch. Looking at the metrics, there is an Amazon Bedrock Guardrails section. I will enter the specific ID of the Guardrail I created. Let's select some of these metrics. I will show you basically how it looks. This metric has a dimensional versioning aspect, so let's look at version 1. When updated, information regarding invocation latency and the number of intervened calls (once, since I only performed one prompt) is displayed. These metrics appear in CloudWatch automatically as soon as you start using those guardrails in Amazon Bedrock, and you can create alarms as needed.
User Feedback Collection and Observability Summary
Now, let's go back to layer 4 and look into it in detail. Layer 4 focuses on end-user feedback such as "Thumbs up" or "Thumbs down." This is the part where humans get involved as users start providing information about the chatbot's performance. CloudWatch has a powerful, perhaps lesser-known feature called Embedded Metric Format. Think of this as structured logs that also automatically generate metrics. This allows you to correlate metrics and logs - you can adjust all telemetry as logs and create metrics while maintaining the correlation between these elements.
In this implementation, we will add ThumbsUp and ThumbsDown features to the chatbot. Through these options, we ask for feedback from the user and track the sentiment value as an indicator like 1 or 0. Users can also utilize a text box to provide additional context. We set up an alarm to receive notifications if there is too much negative feedback within the chatbot. The CloudWatch Embedded Metric Format mechanism works through structured logging. For example, there is telemetry that includes key-value pairs indicating environmental tags or the chatbot service in the production environment. It also includes metrics such as sentiment values indicating that the model's response was good and accurate, as well as text feedback. All these telemetry data are input into CloudWatch as logs, and based on that structure, we can identify what information should be converted into metrics.
There is also a library that makes this process even easier. Looking at the screenshot on the left, you can confirm the underscore aws header - this is something you include in the JSON log to tell CloudWatch where the metrics are and how to extract them with appropriate dimensions. Let's look at the final demo. I will explain how to set it up.
You can see that there is a feedback section on the left side of the application, where you can enter feedback in a text box, as well as options for ThumbsUp and ThumbsDown. This is set up using CloudWatch and Embedded Metric Format. Let's ask a question about standard deductions. The response seems reasonable, so I will select ThumbsUp. Let's send this feedback and verify it within CloudWatch.
I will pause here. There is a new log group, separate from the invocation log group. This is specifically for chatbot feedback, labeled chat/chatbot/feedback. Let's run this query. I only ran the prompt once, so only one result should be returned. If I show you these logs, you can confirm the same AWS header - the underscore aws JSON structure. This allows CloudWatch to recognize the metrics to extract, enabling the correlation of metrics and log data.
This is the first step: we ingested all telemetry as logs and instructed CloudWatch on how to extract metrics. We have a sentiment value metric where ThumbsUp is 1 and ThumbsDown is 0. Let's look at the corresponding metric created by CloudWatch EMF. Here is the sentiment value metric. I only ran the prompt once, so I see a small point, but you can see that the value is 1. Based on this, we can set up an alarm.
Now, let's create an alarm and set it up. I will set it to alert if it falls below 90% or 95%. I will set it to 0.95, which means that as soon as negative feedback increases and falls below 95%, we will consider that something has gone wrong and send an alarm to the operator. When setting up this type of alarm in CloudWatch, there is an important setting that you should definitely check. Scroll down to the additional settings section.
CloudWatch alarms have an option that many people don't know about because it's hidden in a dropdown menu. It's "How to handle missing data." Should we treat it as good, bad, or insufficient if no data comes into the metric? In this case, the absence of data actually signifies a good state. The bad state is only when negative feedback is zero. Therefore, for this alarm, missing data is OK. When setting up a metric-based alarm like this, it is important to treat missing data as "good" and ensure it does not exceed the threshold. If no Thumbs up or Thumbs down data comes in, it is safe to assume that everything is working normally.
Let's move on and set up notifications. We can also set up a series of notifications to create an alarm tree as explained earlier. Click next to create the alarm. I named the alarm "negative feedback." This is to alert us when there is too much negative feedback. If you refresh the page and look all the way to the end, you should be able to see a green line. If you wait for a while, a clean single green line should appear. As negative feedback increases and more users become dissatisfied with the Chatbot, this line will turn red and an alarm will be triggered. From there, you can trigger the necessary workload.
Let's return to the slides and wrap up. Going back to the four layers I mentioned earlier, we start by checking errors and latency with metrics and logs provided by AWS services. By setting up Bedrock invocation logs, you can obtain a wealth of log data to better understand LLM usage. When you start expanding further, you should start considering the observability of the orchestration layer and seriously explore the use of tracing. Once you start building a RAG architecture, it becomes very important to understand the interaction between these different components.
When using advanced features such as Bedrock Guardrails, it is important to understand the metrics sent to CloudWatch and to utilize them so you can gain a deeper understanding of Guardrails usage. Finally, do not forget feedback from end-users. This completes the observability loop. Finally, I would like to introduce four resources. These correspond to the four layers I explained earlier. This is a series of blog posts and documentation that I would like you to refer to.
Thank you for coming all the way to Mandalay Bay today and participating in our Monday session. If you have any questions, please feel free to ask me here or in the hallway. Also, don't forget to cooperate with the survey.
- This article was created entirely automatically using Amazon Bedrock.
- Considering concerns about internet pollution by generative AI articles, this article converts the session video into text and images without significantly changing the information content, aiming to maintain the value of the original content itself while potentially enhancing Accessibility and Googlability in multiple languages.


































































































































Discussion