Perform RAG Action
Sends a prompt to, or adds and removes data from, a RAG space on the AI model server specified by a RAG account.
See also
Options
-
RAG Account Name is a text expression of the RAG account for this script step to use. In the current file, use the Configure RAG Account script step to set up the account and assign it this name any time before this script step runs.
-
Space ID is a text expression that specifies the unique ID of the RAG space to work with in the specified RAG account.
-
Action specifies the type of operation to perform on a RAG space. This option controls the availability of other options in the script step. Choose from:
-
Add Data adds a document (text data or a PDF file) to a RAG space.
-
Send Prompt sends a prompt to query a RAG space and get an AI-generated response.
-
Remove Data removes documents from a RAG space.
-
Options available only when Action is Add Data:
-
RAG Data specifies the document to add to the RAG space:
-
From Text adds text directly via a text expression.
-
From File adds a PDF file given a path, transferred synchronously.
-
From File (Async) adds a PDF file given a path, transferred asynchronously (best for large files).
-
From Container adds a PDF file from a container field, transferred synchronously.
-
From Container (Async) adds a PDF file from a container field, transferred asynchronously (best for large files).
-
-
Input File specifies a list of one or more paths for a PDF file. The script step searches the list and adds the first PDF file it successfully locates. Paths must use one of the
image
path prefixes. See Creating file paths. -
Container Field specifies the container field that stores the PDF file to add.
Options available only when Action is Send Prompt:
-
The value for Send Prompt is a text expression for the natural language user prompt or question.
-
AI Account Name is a text expression for the name of the AI account to use to generate a response. In the current file, use the Configure AI Account script step to set up this account and assign it this name any time before this script step runs.
-
Model is the name of the text generation model to use. Specify the model name as a text expression. For supported models, see FileMaker technical specifications.
-
Stream controls how the response is delivered:
-
On: The response is retrieved and delivered incrementally (word by word or in phrases). This can make the FileMaker client feel more responsive.
-
Off: The entire response is retrieved before it is made available. This may cause the FileMaker client to appear unresponsive while waiting for the complete response.
-
-
Prompt Template Name specifies the name of a custom prompt template configured using the Configure Prompt Template script step. Use this option to design an additional prompt to help achieve an optimal response from an AI model.
-
Response Target specifies the field or variable where the response from the model is to be stored.
-
Parameters is a text expression for a JSON object that consists of key-value pairs for additional parameters that are supported by the model provider. For example:
{"temperature": 0.7, "seed": 42}
. Refer to the model provider's documentation for key names of supported parameters and their valid ranges.The
context_prompt
key is a special parameter that allows you to inject additional instructions or context to the model before the main prompt. For example:{"context_prompt": "Treat 'today' as 08/04/2025"}
.
Options available only when Action is Remove Data:
-
Parameters is a text expression for a JSON object containing an
id
key whose value is an array of the IDs of the documents to be removed from the specified RAG space. For example,{"id" : [2, 3, 5, 7]}
. To get the IDs of all documents in a RAG space, use the GetRAGSpaceInfo function. See Example 3.
Compatibility
Product | Supported |
FileMaker Pro | Yes |
FileMaker Go | Yes |
FileMaker WebDirect | Yes |
FileMaker Server | Yes |
FileMaker Cloud | Yes |
FileMaker Data API | Yes |
Custom Web Publishing | Yes |
Originated in version
22.0
Description
This script step lets you create and manage a knowledge cache of documents (text data and PDF files) on the AI Model Server provided with FileMaker Server. You can then leverage this cache with a technique called retrieval-augmented generation (RAG). Using this technique, the script step sends a prompt or question to an AI model along with the most relevant facts retrieved from your knowledge cache, improving the reliability and accuracy of the response from the model.
The Action option determines what this script step does:
Action | Does this |
---|---|
Add Data |
Adds RAG Data from the specified document: text (as any text expression), a PDF file by path, or a PDF file from a container field in the current or related record. The process follows these steps:
|
Send Prompt |
Sends the user prompt to the AI Model Server to get the most relevant data from the specified RAG space, then sends the user prompt along with the prompt template and RAG content to the AI model. The process follows these steps:
|
Remove Data |
Removes documents from a RAG space. If specified in the Parameters option, only the specified documents are removed; otherwise all documents in the RAG space are removed. Note Removing documents from a RAG space can't be undone. Be sure to retain the original documents elsewhere in case you need to add them again. |
Notes
-
A RAG account must be configured using the Configure RAG Account script step before using this script step.
-
For Send Prompt actions, an AI account must also be configured using the Configure AI Account script step.
-
PDF files with encryption or password protection can't be processed with the Add Data action.
-
RAG spaces are persistent and retain their documents until explicitly removed using the Remove Data action.
-
If you add a PDF file with the same filename as one already in the RAG space, the existing PDF file is removed and the new PDF file is added with a new document ID. This behavior is the same whether adding the PDF file via a path or a container field.
-
If you specify a Prompt Template Name, this script step uses the template set up via the Configure Prompt Template script step. Prompt templates can use the constants like
:question:
(replaced with the Send Prompt value) and:context:
(replaced with thecontext_prompt
parameter in Parameters). -
The quality of AI responses depends on the model and the relevance and quality of the documents added to the RAG space.
-
In FileMaker WebDirect, when this script step uses the Add Data action and RAG Data is From File or From File (Async), the Insert dialog opens for the user to choose a PDF file to upload; the Input File option is ignored.
Example 1 - Add text to a RAG space
Adds text content to a RAG space for a customer knowledge base.
Configure RAG Account [ RAG Account Name: "customer-support-rag-account" ; Endpoint: "https://myserver.example.com/llm/v1/" ; API key: "eyJh..." ; Verify SSL Certificates ]
Perform RAG Action [ RAG Account Name : "customer-support-rag-account" ; Space ID: "knowledge-base" ; Action: Add Data ; RAG Data: From Text ; "Customer support policies and procedures for handling returns and exchanges..." ]
Example 2- Send a prompt to query a RAG space
Sends a prompt to query the same RAG space as in Example 1 and stores the response in a field.
The script sets up both the RAG account and the AI account to use the AI Model Server provided with FileMaker Server. When it sends the prompt, the script sends custom parameters to the model for response generation and streams the response to a field.
Configure RAG Account [ RAG Account Name: "customer-support-rag-account" ; Endpoint: "https://myserver.example.com/llm/v1/" ; API key: Global::RAG_API_Key ; Verify SSL Certificates ]
Configure AI Account [ Account Name: "AI_Model_Server" ; Model Provider: Custom ; Endpoint: "https://myserver.example.com/llm/v1/" ; API key: Global::Text_Gen_API_Key ; Verify SSL Certificates ]
Perform RAG Action [ RAG Account Name: "customer-support-rag" ; Space ID: "knowledge-base" ; Action: Send Prompt ; Send Prompt: "What is the return policy for defective products?" ; AI Account Name: "AI_Model_Server" ; Model: Global::ModelName ; Stream: On ; Response Target: Customer_Support::AI_Response ; Parameters: "{\"temperature\": 0.3, \"max_tokens\": 500}" ]
A possible result in the Customer_Support::AI_Response field begins "The return policy for defective products allows you to return the item within 14 calendar days."
Example 3 - Add and remove a PDF file from a RAG space
Adds a PDF file named Policies.pdf to a RAG space, then removes it.
After configuring the RAG account to use on the AI Model Server, the script adds the Policies.pdf file to the RAG space by specifying its file path.
Before it can remove the file, the script must find the document ID that was assigned when the file was added. First, the script uses the GetRAGSpaceInfo function to get information about the RAG space. Then for the $id variable, it gets the values
array and uses a While loop to find the element whose filename
key is "Policies.pdf", returning the value of that element's id
.
After setting $idArrayToRemove to the required JSON to specify the $id, the script calls Perform RAG Action to remove the data by setting the Parameters option to $idArrayToRemove.
Configure RAG Account [ RAG Account Name: "customer-support-rag-account" ; Endpoint: "https://myserver.example.com/llm/v1/" ; API key: Global::RAG_API_Key ; Verify SSL Certificates ]
Perform RAG Action [ RAG Account Name: "customer-support-rag-account" ; Space ID: "knowledge-base" ; Action: Add Data ; RAG Data: From File ; "Policies.pdf" ]
Set Variable [ $ragSpaceInfo ; Value: GetRAGSpaceInfo ( "customer-support-rag-account" ; "knowledge-base" ) ]
Set Variable [ $id ; Value:
Let ( [
json = $ragSpaceInfo ;
values = JSONGetElement ( json ; "values" ) ;
arrayCount = ValueCount ( JSONListKeys ( values ; "" ) ) ;
search = While (
[ i = 0 ; result = "" ] ;
i < arrayCount and IsEmpty ( result ) ;
[
filename = JSONGetElement ( values ; "[" & i & "].filename" ) ;
result = Case (
filename = "Policies.pdf" ;
JSONGetElement ( values ; "[" & i & "].id" ) ;
""
) ;
i = i + 1
] ;
result
)
] ;
search
)
]
Set Variable [ $idArrayToRemove ; Value: "{\"id\": [" & $id & "]}" ]
Perform RAG Action [ RAG Account Name: "customer-support-rag-account" ; Space ID: "knowledge-base" ; Action: Remove Data ; Parameters: $idArrayToRemove ]