With Amazon Bedrock Evaluations, you possibly can consider basis fashions (FMs) and Retrieval Augmented Era (RAG) methods, whether or not hosted on Amazon Bedrock or one other mannequin or RAG system hosted elsewhere, together with Amazon Bedrock Information Bases or multi-cloud and on-premises deployments. We lately introduced the overall availability of the massive language mannequin (LLM)-as-a-judge approach in mannequin analysis and the brand new RAG analysis device, additionally powered by an LLM-as-a-judge behind the scenes. These instruments are already empowering organizations to systematically consider FMs and RAG methods with enterprise-grade instruments. We additionally talked about that these analysis instruments don’t should be restricted to fashions or RAG methods hosted on Amazon Bedrock; with the convey your personal inference (BYOI) responses characteristic, you possibly can consider fashions or purposes if you happen to use the enter formatting necessities for both providing.
The LLM-as-a-judge approach powering these evaluations allows automated, human-like analysis high quality at scale, utilizing FMs to evaluate high quality and accountable AI dimensions with out guide intervention. With built-in metrics like correctness (factual accuracy), completeness (response thoroughness), faithfulness (hallucination detection), and accountable AI metrics corresponding to harmfulness and reply refusal, you and your staff can consider fashions hosted on Amazon Bedrock and information bases natively, or utilizing BYOI responses out of your custom-built methods.
Amazon Bedrock Evaluations affords an in depth listing of built-in metrics for each analysis instruments, however there are occasions once you would possibly need to outline these analysis metrics otherwise, or make utterly new metrics which can be related to your use case. For instance, you would possibly need to outline a metric that evaluates an utility response’s adherence to your particular model voice, or need to classify responses in line with a {custom} categorical rubric. You would possibly need to use numerical scoring or categorical scoring for numerous functions. For these causes, you want a means to make use of {custom} metrics in your evaluations.
Now with Amazon Bedrock, you possibly can develop {custom} analysis metrics for each mannequin and RAG evaluations. This functionality extends the LLM-as-a-judge framework that drives Amazon Bedrock Evaluations.
On this put up, we exhibit how you can use {custom} metrics in Amazon Bedrock Evaluations to measure and enhance the efficiency of your generative AI purposes in line with your particular enterprise necessities and analysis standards.
Overview
Customized metrics in Amazon Bedrock Evaluations provide the next options:
- Simplified getting began expertise – Pre-built starter templates can be found on the AWS Administration Console based mostly on our industry-tested built-in metrics, with choices to create from scratch for particular analysis standards.
- Versatile scoring methods – Assist is offered for each quantitative (numerical) and qualitative (categorical) scoring to create ordinal metrics, nominal metrics, and even use analysis instruments for classification duties.
- Streamlined workflow administration – It can save you {custom} metrics for reuse throughout a number of analysis jobs or import beforehand outlined metrics from JSON recordsdata.
- Dynamic content material integration – With built-in template variables (for instance,
{{immediate}},{{prediction}}, and{{context}}), you possibly can seamlessly inject dataset content material and mannequin outputs into analysis prompts. - Customizable output management – You should utilize our advisable output schema for constant outcomes, with superior choices to outline {custom} output codecs for specialised use circumstances.
Customized metrics offer you unprecedented management over the way you measure AI system efficiency, so you possibly can align evaluations together with your particular enterprise necessities and use circumstances. Whether or not assessing factuality, coherence, helpfulness, or domain-specific standards, {custom} metrics in Amazon Bedrock allow extra significant and actionable analysis insights.
Within the following sections, we stroll by the steps to create a job with mannequin analysis and {custom} metrics utilizing each the Amazon Bedrock console and the Python SDK and APIs.
Supported knowledge codecs
On this part, we evaluation some essential knowledge codecs.
Decide immediate importing
To add your beforehand saved {custom} metrics into an analysis job, observe the JSON format within the following examples.
The next code illustrates a definition with numerical scale:
The next code illustrates a definition with string scale:
The next code illustrates a definition with no scale:
For extra data on defining a decide immediate with no scale, see the perfect practices part later on this put up.
Mannequin analysis dataset format
When utilizing LLM-as-a-judge, just one mannequin may be evaluated per analysis job. Consequently, you should present a single entry within the modelResponses listing for every analysis, although you possibly can run a number of analysis jobs to check totally different fashions. The modelResponses subject is required for BYOI jobs, however not wanted for non-BYOI jobs. The next is the enter JSONL format for LLM-as-a-judge in mannequin analysis. Fields marked with ? are optionally available.
RAG analysis dataset format
We up to date the analysis job enter dataset format to be much more versatile for RAG analysis. Now, you possibly can convey referenceContexts, that are anticipated retrieved passages, so you possibly can examine your precise retrieved contexts to your anticipated retrieved contexts. You will discover the brand new referenceContexts subject within the up to date JSONL schema for RAG analysis:
Variables for knowledge injection into decide prompts
To make it possible for your knowledge is injected into the decide prompts in the correct place, use the variables from the next desk. We have now additionally included a information to point out you the place the analysis device will pull knowledge out of your enter file, if relevant. There are circumstances the place if you happen to convey your personal inference responses to the analysis job, we’ll use that knowledge out of your enter file; if you happen to don’t use convey your personal inference responses, then we’ll name the Amazon Bedrock mannequin or information base and put together the responses for you.
The next desk summarizes the variables for mannequin analysis.
| Plain Title | Variable | Enter Dataset JSONL Key | Necessary or Optionally available |
| Immediate | {{immediate}} |
immediate | Optionally available |
| Response | {{prediction}} |
For a BYOI job:
If you happen to don’t convey your personal inference responses, the analysis job will name the mannequin and put together this knowledge for you. |
Necessary |
| Floor fact response | {{ground_truth}} |
referenceResponse |
Optionally available |
The next desk summarizes the variables for RAG analysis (retrieve solely).
| Plain Title | Variable | Enter Dataset JSONL Key | Necessary or Optionally available |
| Immediate | {{immediate}} |
immediate |
Optionally available |
| Floor fact response | {{ground_truth}} |
For a BYOI job:
If you happen to don’t convey your personal inference responses, the analysis job will name the Amazon Bedrock information base and put together this knowledge for you. |
Optionally available |
| Retrieved passage | {{context}} |
For a BYOI job:
If you happen to don’t convey your personal inference responses, the analysis job will name the Amazon Bedrock information base and put together this knowledge for you. |
Necessary |
| Floor fact retrieved passage | {{reference_contexts}} |
referenceContexts |
Optionally available |
The next desk summarizes the variables for RAG analysis (retrieve and generate).
| Plain Title | Variable | Enter dataset JSONL key | Necessary or optionally available |
| Immediate | {{immediate}} |
immediate |
Optionally available |
| Response | {{prediction}} |
For a BYOI job:
If you happen to don’t convey your personal inference responses, the analysis job will name the Amazon Bedrock information base and put together this knowledge for you. |
Necessary |
| Floor fact response | {{ground_truth}} |
referenceResponses |
Optionally available |
| Retrieved passage | {{context}} |
For a BYOI job:
If you happen to don’t convey your personal inference responses, the analysis job will name the Amazon Bedrock information base and put together this knowledge for you. |
Optionally available |
| Floor fact retrieved passage | {{reference_contexts}} |
referenceContexts |
Optionally available |
Stipulations
To make use of the LLM-as-a-judge mannequin analysis and RAG analysis options with BYOI, you should have the next stipulations:
Create a mannequin analysis job with {custom} metrics utilizing Amazon Bedrock Evaluations
Full the next steps to create a job with mannequin analysis and {custom} metrics utilizing Amazon Bedrock Evaluations:
- On the Amazon Bedrock console, select Evaluations within the navigation pane and select the Fashions
- Within the Mannequin analysis part, on the Create dropdown menu, select Automated: mannequin as a decide.
- For the Mannequin analysis particulars, enter an analysis identify and optionally available description.

- For Evaluator mannequin, select the mannequin you need to use for automated analysis.
- For Inference supply, choose the supply and select the mannequin you need to consider.
For this instance, we selected Claude 3.5 Sonnet because the evaluator mannequin, Bedrock fashions as our inference supply, and Claude 3.5 Haiku as our mannequin to guage.

- The console will show the default metrics for the evaluator mannequin you selected. You possibly can choose different metrics as wanted.

- Within the Customized Metrics part, we create a brand new metric referred to as “Comprehensiveness.” Use the template supplied and modify based mostly in your metrics. You should utilize the next variables to outline the metric, the place solely
{{prediction}}is necessary:immediatepredictionground_truth
The next is the metric we outlined in full:

- Create the output schema and extra metrics. Right here, we outline a scale that gives most factors (10) if the response could be very complete, and 1 if the response shouldn’t be complete in any respect.

- For Datasets, enter your enter and output areas in Amazon S3.
- For Amazon Bedrock IAM function – Permissions, choose Use an present service function and select a job.

- Select Create and watch for the job to finish.

Concerns and finest practices
When utilizing the output schema of the {custom} metrics, notice the next:
- If you happen to use the built-in output schema (advisable), don’t add your grading scale into the principle decide immediate. The analysis service will routinely concatenate your decide immediate directions together with your outlined output schema score scale and a few structured output directions (distinctive to every decide mannequin) behind the scenes. That is so the analysis service can parse the decide mannequin’s outcomes and show them on the console in graphs and calculate common values of numerical scores.
- The totally concatenated decide prompts are seen within the Preview window in case you are utilizing the Amazon Bedrock console to assemble your {custom} metrics. As a result of decide LLMs are inherently stochastic, there may be some responses we will’t parse and show on the console and use in your common rating calculations. Nevertheless, the uncooked decide responses are at all times loaded into your S3 output file, even when the analysis service can’t parse the response rating from the decide mannequin.
- If you happen to don’t use the built-in output schema characteristic (we suggest you employ it as a substitute of ignoring it), then you’re chargeable for offering your score scale within the decide immediate directions physique. Nevertheless, the analysis service won’t add structured output directions and won’t parse the outcomes to point out graphs; you will note the total decide output plaintext outcomes on the console with out graphs and the uncooked knowledge will nonetheless be in your S3 bucket.
Create a mannequin analysis job with {custom} metrics utilizing the Python SDK and APIs
To make use of the Python SDK to create a mannequin analysis job with {custom} metrics, observe these steps (or discuss with our example notebook):
- Arrange the required configurations, which ought to embrace your mannequin identifier for the default metrics and {custom} metrics evaluator, IAM function with applicable permissions, Amazon S3 paths for enter knowledge containing your inference responses, and output location for outcomes:
- To outline a {custom} metric for mannequin analysis, create a JSON construction with a
customMetricDefinitionEmbody your metric’s identify, write detailed analysis directions incorporating template variables (corresponding to{{immediate}}and{{prediction}}), and outline yourratingScalearray with evaluation values utilizing both numerical scores (floatValue) or categorical labels (stringValue). This correctly formatted JSON schema allows Amazon Bedrock to guage mannequin outputs persistently in line with your particular standards. - To create a mannequin analysis job with {custom} metrics, use the
create_evaluation_jobAPI and embrace your {custom} metric within thecustomMetricConfigpart, specifying each built-in metrics (corresponding toBuiltin.Correctness) and your {custom} metric within themetricNamesarray. Configure the job together with your generator mannequin, evaluator mannequin, and correct Amazon S3 paths for enter dataset and output outcomes. - After submitting the analysis job, monitor its standing with
get_evaluation_joband entry outcomes at your specified Amazon S3 location when full, together with the usual and {custom} metric efficiency knowledge.
Create a RAG system analysis with {custom} metrics utilizing Amazon Bedrock Evaluations
On this instance, we stroll by a RAG system analysis with a mixture of built-in metrics and {custom} analysis metrics on the Amazon Bedrock console. Full the next steps:
- On the Amazon Bedrock console, select Evaluations within the navigation pane.
- On the RAG tab, select Create.

- For the RAG analysis particulars, enter an analysis identify and optionally available description.

- For Evaluator mannequin, select the mannequin you need to use for automated analysis. The evaluator mannequin chosen right here can be used to calculate default metrics if chosen. For this instance, we selected Claude 3.5 Sonnet because the evaluator mannequin.
- Embody any optionally available tags.

- For Inference supply, choose the supply. Right here, you may have the choice to pick out between Bedrock Information Bases and Carry your personal inference responses. If you happen to’re utilizing Amazon Bedrock Information Bases, you will have to decide on a beforehand created information base or create a brand new one. For BYOI responses, you possibly can convey the immediate dataset, context, and output from a RAG system. For this instance, we selected Bedrock Information Base as our inference supply.

- Specify the analysis kind, response generator mannequin, and built-in metrics. You possibly can select between a mixed retrieval and response analysis or a retrieval solely analysis, with choices to make use of default metrics, {custom} metrics, or each to your RAG analysis. The response generator mannequin is barely required when utilizing an Amazon Bedrock information base because the inference supply. For the BYOI configuration, you possibly can proceed and not using a response generator. For this instance, we chosen Retrieval and response technology as our analysis kind and selected Nova Lite 1.0 as our response generator mannequin.

- Within the Customized Metrics part, select your evaluator mannequin. We chosen Claude 3.5 Sonnet v1 as our evaluator mannequin for {custom} metrics.
- Select Add {custom} metrics.

- Create your new metric. For this instance, we create a brand new {custom} metric for our RAG analysis referred to as
information_comprehensiveness. This metric evaluates how totally and utterly the response addresses the question through the use of the retrieved data. It measures the extent to which the response extracts and incorporates related data from the retrieved passages to offer a complete reply. - You possibly can select between importing a JSON file, utilizing a preconfigured template, or making a {custom} metric with full configuration management. For instance, you possibly can choose the preconfigured templates for the default metrics and alter the scoring system or rubric. For our
information_comprehensivenessmetric, we choose the {custom} choice, which permits us to enter our evaluator immediate immediately.
- For Directions, enter your immediate. For instance:
- Enter your output schema to outline how the {custom} metric outcomes can be structured, visualized, normalized (if relevant), and defined by the mannequin.
If you happen to use the built-in output schema (advisable), don’t add your score scale into the principle decide immediate. The analysis service will routinely concatenate your decide immediate directions together with your outlined output schema score scale and a few structured output directions (distinctive to every decide mannequin) behind the scenes in order that your decide mannequin outcomes may be parsed. The totally concatenated decide prompts are seen within the Preview window in case you are utilizing the Amazon Bedrock console to assemble your {custom} metrics.

- For Dataset and analysis outcomes S3 location, enter your enter and output areas in Amazon S3.
- For Amazon Bedrock IAM function – Permissions, choose Use an present service function and select your function.

- Select Create and watch for the job to finish.

Begin a RAG analysis job with {custom} metrics utilizing the Python SDK and APIs
To make use of the Python SDK for creating an RAG analysis job with {custom} metrics, observe these steps (or discuss with our example notebook):
- Arrange the required configurations, which ought to embrace your mannequin identifier for the default metrics and {custom} metrics evaluator, IAM function with applicable permissions, information base ID, Amazon S3 paths for enter knowledge containing your inference responses, and output location for outcomes:
- To outline a {custom} metric for RAG analysis, create a JSON construction with a
customMetricDefinitionEmbody your metric’s identify, write detailed analysis directions incorporating template variables (corresponding to{{immediate}},{{context}}, and{{prediction}}), and outline yourratingScalearray with evaluation values utilizing both numerical scores (floatValue) or categorical labels (stringValue). This correctly formatted JSON schema allows Amazon Bedrock to guage responses persistently in line with your particular standards. - To create a RAG analysis job with {custom} metrics, use the
create_evaluation_jobAPI and embrace your {custom} metric within thecustomMetricConfigpart, specifying each built-in metrics (Builtin.Correctness) and your {custom} metric within themetricNamesarray. Configure the job together with your information base ID, generator mannequin, evaluator mannequin, and correct Amazon S3 paths for enter dataset and output outcomes. - After submitting the analysis job, you possibly can test its standing utilizing the
get_evaluation_jobmethodology and retrieve the outcomes when the job is full. The output can be saved on the Amazon S3 location specified within theoutput_pathparameter, containing detailed metrics on how your RAG system carried out throughout the analysis dimensions together with {custom} metrics.
Customized metrics are solely accessible for LLM-as-a-judge. On the time of writing, we don’t settle for {custom} AWS Lambda capabilities or endpoints for code-based {custom} metric evaluators. Human-based mannequin analysis has supported {custom} metric definition since its launch in November 2023.
Clear up
To keep away from incurring future costs, delete the S3 bucket, pocket book situations, and different sources that had been deployed as a part of the put up.
Conclusion
The addition of {custom} metrics to Amazon Bedrock Evaluations empowers organizations to outline their very own analysis standards for generative AI methods. By extending the LLM-as-a-judge framework with {custom} metrics, companies can now measure what issues for his or her particular use circumstances alongside built-in metrics. With assist for each numerical and categorical scoring methods, these {custom} metrics allow constant evaluation aligned with organizational requirements and targets.
As generative AI turns into more and more built-in into enterprise processes, the power to guage outputs in opposition to custom-defined standards is crucial for sustaining high quality and driving steady enchancment. We encourage you to discover these new capabilities by the Amazon Bedrock console and API examples supplied, and uncover how customized analysis frameworks can improve your AI methods’ efficiency and enterprise influence.
Concerning the Authors
Shreyas Subramanian is a Principal Information Scientist and helps clients through the use of generative AI and deep studying to unravel their enterprise challenges utilizing AWS companies. Shreyas has a background in large-scale optimization and ML and in using ML and reinforcement studying for accelerating optimization duties.
Adewale Akinfaderin is a Sr. Information Scientist–Generative AI, Amazon Bedrock, the place he contributes to leading edge improvements in foundational fashions and generative AI purposes at AWS. His experience is in reproducible and end-to-end AI/ML strategies, sensible implementations, and serving to international clients formulate and develop scalable options to interdisciplinary issues. He has two graduate levels in physics and a doctorate in engineering.
Jesse Manders is a Senior Product Supervisor on Amazon Bedrock, the AWS Generative AI developer service. He works on the intersection of AI and human interplay with the aim of making and bettering generative AI services and products to fulfill our wants. Beforehand, Jesse held engineering staff management roles at Apple and Lumileds, and was a senior scientist in a Silicon Valley startup. He has an M.S. and Ph.D. from the College of Florida, and an MBA from the College of California, Berkeley, Haas College of Enterprise.
Ishan Singh is a Sr. Generative AI Information Scientist at Amazon Net Companies, the place he helps clients construct modern and accountable generative AI options and merchandise. With a powerful background in AI/ML, Ishan focuses on constructing Generative AI options that drive enterprise worth. Exterior of labor, he enjoys taking part in volleyball, exploring native bike trails, and spending time along with his spouse and canine, Beau.

