Grounding Your Large Language Model in Data – Mendix Cloud GenAI
Introduction
This document explains how to add data to your smart app to integrate with a Large Language Model (LLM). To do this, you can use your existing app or follow the Build a Smart App from a Blank GenAI App guide to start from scratch.
In this document, you will:
- Learn how to ground your LLM in data within your Mendix application using the Mendix Cloud GenAI Resource Packs.
- Discover how to integrate GenAI capabilities with a knowledge base to effectively address specific business requirements.
Prerequisites
Before implementing this capability into your app, make sure you meet the following requirements:
-
Start from scratch: to simplify your first use case, start building from a preconfigured setup Blank GenAI Starter App. For more information, see Build a Chatbot from Scratch Using the Blank GenAI App.
-
Install the GenAI For Mendix bundle (version 2.2.0 and above) from the Mendix Marketplace. If you start with the Blank GenAI App, you can skip this installation.
-
Set up a Knowledge Base resource within the Mendix Cloud GenAI Resource Packs.
-
Set up data to add to your LLM. In this example, a modified and streamlined version of the demo data is used. This data is available in the GenAI Showcase App and located in the ExampleMicroflows module > Ground in data - Mendix Cloud > Example data set. If you need to create the demo data yourself, a basic understanding of import mappings and JSON structures is required.
-
Intermediate understanding of GenAI concepts: See the Enrich Your Mendix App with GenAI Capabilities page for foundational knowledge and familiarize yourself with the concepts.
-
Basic understanding of Prompt Engineering.
Grounding Your LLM in a Data Use Case

Choosing the Infrastructure
Since this document focuses on the Mendix Cloud GenAI Resource Packs, ensure that you have the Mendix Cloud GenAI Connector, which is part of the GenAI For Mendix bundle on the Marketplace.
Follow the Navigate through the Mendix Cloud GenAI Portal instructions to collect the resources keys.
Creating Domain Model Entity
Since your application needs to store information, you must create attributes for the knowledge you want to save. In this example, based on the demo data mentioned below, a Description
attribute of type String
is created.
Demo Data
You can upload your custom data into the knowledge base. However, for this example, a modified and streamlined version of the demo data from the GenAI Showcase App is used. This demo data includes a Description
attribute that provides information on resolving basic IT support issues. The following details are provided:
- A JSON file containing examples of IT support solutions, such as “If the software crashes every time you try to save your document, first ensure you have the latest updates installed. Try…”
- An Import Mapping that maps the
JsonObject
into the corresponding domain model entity.
Loading Data Into the Knowledge Base
To start, create a microflow that allows you to upload data into your knowledge base.
Loading Microflow
-
Create a new microflow, for example,
ACT_TicketList_LoadAllIntoKnowledgeBase
. -
Add the
Retrieve Objects
action. You can configure it as follows:- Source:
From database
- Entity: Select the entity that contains your knowledge, which in this example would be the
MyFirstModule.Ticket
- Range:
All
- Object name:
TicketList
- Source:
-
Next, add the
Chunks: Initialize ChunkCollection
action. You can keep the Use return variable as Yes and object nameChunkCollection
. -
As shown in the image above, include a loop where the iterator has Loop type
For each (item in the list)
, the Iterate over is the List retrieved in the above step, which in this case is namedTicketList (List of MyFirstModule.Tickets)
. Lastly, you can add a Loop object name asIteratorTicket
. After saving these settings, add aChunks: Add KnowledgeBaseChunk to ChunkCollection
action inside the loop. Here you can configure it as follows:- Chunk collection:
$ChunkCollection
- Input text: edit the expression to use the iterator object from the loop with the desired attribute, which in this case is
$IteratorTicket/Description
- Human readable ID:
empty
(optional) - Mx object: Select the loop’s iterator, such as
$IteratorTicket
- Use return value: No
- Metadata collection:
empty
(optional)
- Chunk collection:
-
After the loop, add a
Retrieve
action to retrieve aMxCloudKnowledgeBase
. In this example, the first entry found in the database is used.- Source:
From database
- Entity:
MxGenAIConnector.MxCloudKnowledgeBase
- Range:
First
- Object name:
MxCloudKnowledgeBase
- Source:
-
Next, add the
Connection: Get
action from theMendix Cloud Knowledge Base
category:To edit the parameter value for
MxCloudKnowledgeBase
, double-click its type, selectVariable
, and assign it the valueMxCloudKnowledgeBase
. Similarly, forCollectionName
, double-click its type, selectExpression
, and assign it the valueTicketSolutions
.You can keep the Use return variable as Yes and the object name
MxKnowledgeBaseConnection
. -
Add the
Embed & Repopulate Collection
action to insert your knowledge into the knowledge base:To edit the parameter value for
Connection
, double-click its type, selectVariable
, and assign it the valueMxKnowledgeBaseConnection
. Similarly, forChunkCollection
, double-click its type, selectVariable
, and assign it the valueGenAICommons.ChunkCollection
.You can keep the Use return variable as Yes and the variable name
IsSuccess
. -
Next (optional), include a decision:
- Caption: for example,
Replace Success
- Decision Type:
Expression
- Expression:
$IsSuccess
If the decision is
true
, anEnd event
action can be added where a microflow return value totrue
. You may add a message to inform the end user that the insertion was successful.If the decision is
false
, anEnd event
action can be added where a microflow return value tofalse
. You may add a message to inform the end user that the insertion failed. - Caption: for example,
You have successfully implemented the knowledge base insertion microflow! If you do not have any data available in your app yet, you need to create a microflow to generate the dataset, as described in the Data Set Microflow section below.
Data Set Microflow
This microflow first checks whether a list of tickets already exists in the database. If not, it imports a JSON
string as described in the demo data section above.
-
Create a new microflow, for example,
Tickets_CreateDataset
. -
Add a
Retrieve
action:- Source:
From database
- Entity: Select the entity that contains your knowledge, which in this example is
MyFirstModule.Ticket
- Range:
First
- Object name:
Ticket
- Source:
-
Include a decision where:
- Caption:
Tickets?
- Decision Type:
Expression
- Expression:
$Ticket = empty
If the decision is
false
, anEnd event
is added, as importing tickets is not required.If the decision is
true
, continue to the next step. - Caption:
-
In the
true
path, add theCreate Variable
action, where theString
value includes the JSON text mentioned in the demo data. UseTicketJSON
as the variable name. -
Next, add the
Import With Mapping
action with the following configurations:- Variable**:
TicketJSON
created in the previous step - Mapping: Use the mapping mentioned in the demo data section
- Range:
All
- Commit:
Yes without events
- Store in variable:
No
(optional, not needed here) - Variable name: (optional) only when stored in a variable
- Variable**:
With both microflows created, they must be combined and added to the homepage to populate the knowledge base.
Joining the Microflows
-
Create a new microflow
ACT_TicketList_CreateData_InsertIntoKnowledgeBase
. -
Add a
Call Microflow
action where you call theMyFirstModule.Tickets_CreateDataset
microflow created above. -
Next, add a
Call Microflow
action where you call theMyFirstModule.ACT_TicketList_LoadAllIntoKnowledgeBase
microflow created above. For the Use return variable, select No.
You have successfully added the logic to insert data into the knowledge base!
Chat Setup
To use the knowledge in a chat interface, create and adjust certain microflows as shown below.
-
Search for the pre-built microflow
ChatContext_ChatWithHistory_ActionMicroflow
in the ConversationalUI > USE_ME > Conversational UI > Action microflow examples folder and copy it into your MyFirstBot module. -
Search for the pre-built microflow
ACT_FullScreenChat_Open
in the ConversationalUI > USE_ME > ConversationalUI > Pages folder. Copy the microflow into your MyFirstBot module. Right-click on the copied microflow and select Include in project. -
In the
ACT_FullScreenChat_Open
microflow, change the parameters of theNew Chat
action:-
Set the Action microflow input parameter as your new
MyFirstBot.ChatContext_ChatWithHistory_ActionMicroflow
from your MyFirstBot module. -
Set the System prompt input parameter as a prompt that fits your use case. For example, You are a helpful assistant supporting the IT department with employee requests. Use the knowledge base and previous support tickets as a database to find a solution to the user’s request without disclosing sensitive details or data from previous tickets.
-
The Provider name input parameter can be modified to a more purpose-specific text, such as
My GenAI Provider Configuration
.
With the
MyFirstBot.ACT_FullScreenChat_Open microflow
configured, theMyFirstBot.ChatContext_ChatWithHistory_ActionMicroflow
can now be adjusted to handle user-submitted messages in the chat interface. -
-
Open your
MyFirstBot.ChatContext_ChatWithHistory_ActionMicroflow
microflow in your MyFirstBot module. -
After the
Request found
decision, add aRetrieve
action. In this example, the first entry found in the database is used, just as in the insertion microflow.- Source:
From database
- Entity:
MxGenAIConnector.MxCloudKnowledgeBase
- Range:
First
- Object name:
MxCloudKnowledgeBase
- Source:
-
Add the
Tools: Add Mendix Cloud Knowledge Base
action with the settings shown in the image below:
The rest of the actions can remain as they are currently set. Now that everything is implemented, you can test the chat with enriched knowledge.
Navigation Setup
For the application to function as expected, ensure that the following microflows can be called from the navigation menu or homepage:
-
Chatbot: Add the
MyFirstModule.ACT_FullScreenChat_Open
microflow which was created in the Chat Setup section. -
Create Demo Data and Populate KB: Add the
MyFirstModule.ACT_TicketList_CreateData_InsertIntoKnowledgeBase
which was created in the Joining the Microflows section. -
Mendix Cloud Configuration: If you started from a Blank GenAI App, the configuration page should already be included. In case you started from your application, add the
MxGenAIConnector.NAV_ConfigurationOverview_Open
microflow. -
Ensure that your admin role has the following module roles assigned: MxGenAIConnector.Administrator, ConversationalUI.User, and MyFirstModule.Administrator.
Testing and Troubleshooting
Before testing, ensure that you have completed the Mendix Cloud GenAI configuration as described in the Build a Chatbot from Scratch Using the Blank GenAI App, particularly the Mendix Cloud GenAI Configuration section.
To test the Chatbot, click on the Create Demo Data and Populate KB option to populate the knowledge base and go to the Chatbot icon to open the chatbot interface. Start interacting with your chatbot by typing in the chat box something related to your knowledge base. For example, My computer crashes every time, what can I do?
Congratulations! You grounded your LLM in data and your chatbot is now ready to use.
If an error occurs, check the Console in Studio Pro for detailed information to assist in resolving the issue.