You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/docs/marketplace/genai/reference-guide/genai-commons.md
+73-5Lines changed: 73 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,12 +41,20 @@ Although GenAI Commons technically defines additional capabilities typically fou
41
41
42
42
### Token Usage
43
43
44
-
GenAI Commons can help store usage data which allows admins to understand the token usage. Usage data is only persisted if the constant `StoreUsageMetrics` is set to `true`and the GenAI connector of choice has implemented the operation to store token usage. In general, this is only supported for chat completions and embedding operations.
44
+
GenAI Commons can help store usage data which allows admins to understand the token usage. Usage data is only persisted if the constant `StoreUsageMetrics` is set to `true`(exception: if [StoreTraces](#traceability) is set to `true`, Usages data is stored as well). In general, this is only supported for chat completions and embedding operations.
45
45
46
46
To clean up usage data in a deployed app, you can enable the daily scheduled event `ScE_Usage_Cleanup` in the Mendix Cloud Portal. Use the `Usage_CleanUpAfterDays` constant to control for how long token usage data should be persisted.
47
47
48
48
Lastly, the [Conversational UI module](/appstore/modules/genai/conversational-ui/) provides pages, snippets, and logic to display and export token usage information. For this to work, the module roles `UsageMonitoring` from both Conversational UI as well as GenAI Commons need to be assigned to the applicable project roles.
49
49
50
+
### Traceability {#traceability}
51
+
52
+
The chat completions operations of GenAI Commons store data for traceability reasons in your application's database by default. This can be used to understand the usage of GenAI in your app and why the model behaved in certain ways, for example by reviewing the usage of tools. Trace data is only persisted if the constant `StoreTraces` is set to `true`. As traces may contain sensitive and personally-identifiable information, it should be decided per use case if storing such data is compliant.
53
+
54
+
To clean up traces data in a deployed app, you can enable the daily scheduled event `ScE_Trace_Cleanup` in the Mendix Cloud Portal. Use the `Trace_CleanUpAfterDays` constant to control for how long trace data should be persisted.
55
+
56
+
There are currently no out of the box UI snippets or building blocks available. In a future release those will be covered. To enable read-access to a user (typically an admin user), the module role `TraceMonitoring` needs to be granted to the applicable project roles.
57
+
50
58
## Technical Reference {#technical-reference}
51
59
52
60
The technical purpose of the GenAI Commons module is to define a common domain model for generative AI use cases in Mendix applications. To help you work with the **GenAI Commons** module, the following sections list the available [entities](#domain-model), [enumerations](#enumerations), and [microflows](#microflows) to use in your application.
@@ -55,7 +63,7 @@ The technical purpose of the GenAI Commons module is to define a common domain m
55
63
56
64
The domain model in Mendix is a data model that describes the information in your application domain in an abstract way. For more general information, see the [Data in the Domain Model](/refguide/domain-model/) documentation. To learn about where the entities from the domain model are used and relevant during implementation, see the [Microflows](#microflows) section below.
@@ -101,7 +109,7 @@ Accepted input modality of the associated deployed model.
101
109
102
110
This entity represents usage statistics of a call to an LLM. It refers to a complete LLM interaction; in case there are several iterations (e.g. recursive processing of function calls), everything should be aggregated into one Usage record.
103
111
104
-
Following the principles of GenAI Commons, it must be stored based on the response for every successful call to a system of an LLM provider. This is only applicable to text & file operations and embedding operations. It is the responsibility of connector developers implementing the GenAI principles in their GenAI operations to include the right microflows to ensure the storage of Usage details after successful calls.
112
+
Following the principles of GenAI Commons, it must be stored based on the response for every successful call to a system of an LLM provider. This is only applicable to text & file operations and embedding operations.
105
113
106
114
The data stored in this entity is to be used later on for token consumption monitoring.
107
115
@@ -115,21 +123,79 @@ The data stored in this entity is to be used later on for token consumption moni
115
123
|`DurationMilliseconds`| The duration in milliseconds of the technical part of the call to the system of the LLM provider. This excludes custom pre and postprocessing but corresponds to a complete LLM interaction. |
116
124
|`_DeploymentIdentifier`| Internal object used to identify the DeployedModel used. |
117
125
118
-
#### `Connection` {#connection}
126
+
#### `Trace` {#trace}
127
+
128
+
A trace represents the whole LLM interaction from the first user message until the final assistant's response was returned, including tool calls.
129
+
The data stored in this entity is to be used later on for traceability use cases.
130
+
131
+
| Attribute | Description |
132
+
| --- | --- |
133
+
|`TraceId`| The trace id is set internally to identify a trace. |
134
+
|`StartTime`| The start time of the initial model invocation. |
135
+
|`EndTime`| The end time after the final model invocation is completed. |
136
+
|`DurationMilliseconds`| The duration between start and end of the whole model invocation. |
137
+
|`Input`| The initial input of the model invocation (usually a user prompt). |
138
+
|`Output`| The response of the final message sent by the model (usually an assistant message). |
139
+
|`_AgentVersionId`| The id of the agent version (if applicable) as sent via the request. |
140
+
|`_ConversationId`| The id of the conversation (if applicable) as sent via the request. This usually is created by the model provider. |
141
+
142
+
#### `Span` {#span}
143
+
144
+
A span is created for each interaction between Mendix and the LLM (chat completions, tool calling, ...). The generalized object is usually not used, but only it's specializations.
145
+
146
+
| Attribute | Description |
147
+
| --- | --- |
148
+
|`SpanId`| The span id is set internally to identify a span. |
149
+
|`StartTime`| The start time of the model invocation. |
150
+
|`EndTime`| The end time after the model invocation is completed. |
151
+
|`DurationMilliseconds`| The duration between start and end of the whole model invocation. |
152
+
|`Output`| The output of the span. |
153
+
154
+
#### `ModelSpan` {#model-span}
119
155
120
-
The Connection entity was previously used as an input parameter for Chat completions, Embeddings, and Image Generation operations, but it has been replaced by the `DeployedModel` entity. It was also used as a general connection entity for Knowledge Base interactions, which is now replaced with the `DeployedKnowledgeBase` entity.
156
+
A model span is created for each interaction between Mendix and the LLM where content is generated (sent as the assistant's message). In addition to the [Span's](#span) attributes, it also contains the following:
157
+
158
+
| Attribute | Description |
159
+
| --- | --- |
160
+
|`InputTokens`| Number of tokens in the request. |
161
+
|`OutputTokens`| Number of tokens in the generated response. |
162
+
|`_DeploymentIdentifier`| Internal object used to identify the DeployedModel that was used. |
163
+
164
+
#### `ToolSpan` {#tool-span}
165
+
166
+
A tool span is created for each tool call that the LLM requested. The tool call is processed in GenAI Commons and the result is sent back to the model. In addition to the [Span's](#span) attributes, it also contains the following:
167
+
168
+
| Attribute | Description |
169
+
| --- | --- |
170
+
|`ToolName`| The name of the tool that was called. |
171
+
|`_ToolCallId`| The id of the tool call used by the model to map an assistant message containing a tool call with the output of the tool call (tool message). |
172
+
|`Input`| The input of the tool call as passed by the LLM. |
173
+
|`IsError`| Indicates if the tool call failed. If so, the span's output will contain the error message that was also logged and sent to the LLM as tool result. |
174
+
175
+
#### `KnowledgeBaseSpan` {#knowledge-base-span}
176
+
177
+
A knowledge base span is created for each knowledge base retrieval tool call that the LLM requested. The tool call is processed in GenAI Commons and the result is sent back to the model. It does not contain any additional attributes compared to [ToolSpan](#tool-span)
178
+
179
+
| Attribute | Description |
180
+
| --- | --- |
181
+
|`ToolName`| The name of the tool that was called. |
182
+
|`_ToolCallId`| The id of the tool call used by the model to map an assistant message containing a tool call with the output of the tool call (tool message). |
183
+
|`Input`| The input of the tool call as passed by the LLM. |
184
+
|`IsError`| Indicates if the tool call failed. If so, the span's output will contain the error message that was also logged and sent to the LLM as tool result. |
121
185
122
186
#### `Request` {#request}
123
187
124
188
The `Request` is an input object for the chat completions operations defined in the platform-supported GenAI-connectors and contains all content-related input needed for an LLM to generate a response for the given chat conversation.
125
189
126
190
| Attribute | Description |
127
191
| --- | --- |
192
+
|`_Id`| The Id attribute describes the unique identifier of the session. Reuse the same value to continue the same session. |
128
193
|`SystemPrompt`| A `SystemPrompt` provides the model with context, instructions, or guidelines. |
129
194
|`MaxTokens`| Maximum number of tokens per request. |
130
195
|`Temperature`|`Temperature` controls the randomness of the model response. Low values generate a more predictable output, while higher values allow creativity and diversity. It is recommended to steer either the temperature or `TopP`, but not both. |
131
196
|`TopP`|`TopP` is an alternative to temperature for controlling the randomness of the model response. `TopP` defines a probability threshold so that only words with probabilities greater than or equal to the threshold will be included in the response. It is recommended to steer either the temperature or `TopP`, but not both. |
132
197
|`ToolChoice`| Controls which (if any) tool is called by the model. For more information, see the [ENUM_ToolChoice](#enum-toolchoice) section containing a description of the possible values. |
198
+
|`_AgentVersionId`| The AgentVersionId is set if the execution of the request was called from an Agent. |
133
199
134
200
#### `Message` {#message}
135
201
@@ -223,6 +289,7 @@ The response returned by the model contains usage metrics and a response message
223
289
224
290
| Attribute | Description |
225
291
| --- | --- |
292
+
|`_ID_`| The ID attribute describes the unique identifier of the session. Reuse the same value to continue the same session. If no ID was set by the LLM connector, an internal ID is created. |
226
293
|`RequestTokens`| Number of tokens in the request. |
227
294
|`ResponseTokens`| Number of tokens in the generated response. |
228
295
|`TotalTokens`| Total number of tokens (request + response). |
@@ -259,6 +326,7 @@ An optional reference for a response message.
259
326
|`Content`| The content of the reference. |
260
327
|`Source`| The source of the reference, e.g. a URL. |
261
328
|`SourceType`| The type of the source. For more information, see [ENUM_SourceType](#enum-sourcetype). |
329
+
|`Index`| Used to make references identifiable and sortable.|
0 commit comments