Skip to main content Skip to complementary content

Using Meta (Amazon Bedrock) connections in visualization expressions

In addition to adding Meta questions and answers to your app's data model using the load script, you can also perform these operations directly in a chart in your app in analysis mode. Data for a single field is sent back and forth between you and Meta.

In many cases, the code used for a load script connection can be re-purposed for use in a chart, with some differences.

If the use case is based on user input, you can use an analytic connection and corresponding server side extension syntax in your chart expression to create interactive charts that visualize data received from the model endpoints.

Considerations for data request volumes

It is recommended to only use Meta (Amazon Bedrock) connections in chart expressions for one or a handful of rows of data. Using chart expressions to send large amounts of data to Meta is not recommended.

It is important to be aware of how many rows you are sending with each request. Errors in configuring the connection in a chart expression can lead to unintentionally large requests (for example, identical rows with the same question due to improper use of the data model in a chart). Before you interact with a third-party platform, make sure you're aware of how the fields used in the chart expression calculation, and their place in the data model, affect your financial agreement and billing arrangements with the third party. Higher usage of the external platform could result in higher costs incurred.

Follow these guidelines to moderate and limit the size of your requests:

  • Only use the connection in a Text & image chart expression. Using the Meta (Amazon Bedrock) connection in a Table object is strongly discouraged, especially if you are adding the expression to a table with one or more dimensions already added.

  • If the chart expression is linked to your app's data model, use an if statement in the expression to only calculate the chart when a single selection is made in the app. This drastically reduces the row count in the requests that your chart will send to Meta.

  • If you are using the Meta (Amazon Bedrock) connection to send large requests, use the connection in your load script instead of in a chart expression, so that the data is pre-loaded into your data model.

Prompt engineering

When writing the requests you are sending to a generative AI model (often known as prompts), follow the guidelines specific to the platform you are interacting with. For information about prompt engineering and some guidelines on how to structure your prompts for Amazon Bedrock connectors, see Prompt engineering guidelines.

You can interact with the Meta (Amazon Bedrock) connector using standard sentence or text formatting. You do not need to prefix or suffix the prompt with any special keywords or strings. See Quick examples.

Creating the chart expression

  1. When editing a visualization, click Expression to enter the expression editor.

  2. In the expression editor, enter an expression in the expression field. The expression must be constructed using the server side extension syntax.

Quick examples

Here you can find sample expressions that can be used when getting started with the Meta (Amazon Bedrock) connector. Consider the following details:

  • Only use the expressions with a Text & image object.

  • Consider adding an if statement to your expressions to control when the chart is re-calculated, and to update depending on user selections in the app.

  • For the expressions to work, you must substitute the connectionname value and any field names to match your own connections and apps.

Chart expression examples for the Meta (Amazon Bedrock) analytics connector

Expression Summary
endpoints.ScriptAggrStr('{"RequestType":"endpoint", "endpoint":{"connectionname":"Meta_(Amazon_Bedrock)","column":"generation"}}', 'Translate this text from english to spanish: The sun was rising over the new tomorrow with a tinge of excitement.')

This statement will return the Meta (Amazon Bedrock) response to a single question, which has been entered into the expression.

Warning note

This expression does not use an if statement, and is not advised to be used if tied to a field in your data model. It is only suitable for use in a standalone expression with a single input cell containing a hard-coded value.

if(vQuestion <> '', endpoints.scriptAggrStr('{"RequestType":"endpoint", "endpoint":{"connectionname":"Meta_(Amazon_Bedrock)","column":"generation"}}',vQuestion))

This is a statement which can be used in a Text & image object linked to a Variable input control. The chart is only calculated when input is entered. When the user types input into the object and presses Enter, the chart displays the model's response to their input.

For a similar walkthrough with a different connector, see Exercise: Creating a text input box using a variable.

if(GetSelectedCount(BusinessTopic)=1, endpoints.ScriptAggrStr('{"RequestType":"endpoint", "endpoint":{"connectionname":"Meta_(Amazon_Bedrock)", "column":"generation"}}', 'What are people saying about ' & 'BusinessTopic'), 'Please select a single value for BusinessTopic.') This is a complex if statement in which the chart is only calculated if the user has selected one value for the field BusinessTopic. The chart only updates if the user has made this selection in the app, and if they have not, the chart will display the following alternate message: Please select a single value for BusinessTopic.
if(count(distinct [IssueCategory]) = 1, endpoints.ScriptAggrStr('{"RequestType":"endpoint", "endpoint":{"connectionname":"Meta_(Amazon_Bedrock)","column":"generation"}}', 'write me a sample response from a technical support department for a customer complaint about ' & [IssueCategory])) In this example, the chart is only calculated if one distinct value has been selected from the field IssueCategory in the app's data model. A prompt is sent to the model requesting a sample response from a technical support department about a general type of issue, a list of which is contained in the IssueCategory field. The chart is updated depending on the value selected by the user.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!