18.8.4.3 Managing AI Configurations and RAG Sources

Create AI Configurations and RAG Sources to enable richer interactions with Generative AI services.

18.8.4.3.1 About AI Configurations and RAG Sources

Learn about AI Configurations and RAG Sources.

An AI Configuration is a shared component that centralizes key Generative AI settings, including the System Prompt, Welcome Message, and Retrieval-Augmented Generation (RAG) sources. Creating an AI Configuration enables the reusability of these settings across multiple AI-enabled components such as Show AI Assistant and Generate Text With AI dynamic actions. You can also use AI Configurations with PL/SQL APIs available in the APEX_AI package.

About AI Configurations

An AI Configuration contains the following:

  • Name - Identifies the AI Configuration in the App Builder UI.
  • Static ID - Use this ID to reference the AI Configuration in the APIs in the APEX_AI package.
  • Service - Refers to the AI Service to be used by the AI Configuration. By default, the Application Default is used.
  • System Prompt - Initial instructions or context for the AI Service.
  • Welcome Message - The first message shown by the AI Assistant. Note that only components with a UI, such as Show AI Assistant, can utilize this setting.
  • Temperature - Sets the level of randomness or predictability of the generated content.
  • RAG Sources - Additional data to be sent to the AI Service.

See Also:

APEX_AI in Oracle APEX API Reference

About RAG Sources

Each AI Configuration can contain zero or more RAG Sources which help enrich the AI conversation with data specific to the application. A RAG Source can be a SQL Query, a Function Body Returning CLOB, or simply Static text. RAG Sources are dynamic and can individually be protected by a Server-side Condition. If the condition passes, the resulting content is sent with the System Prompt to the AI Service with each request, in essence acting as additional System Prompts.

A RAG Source contains the following:

  • Name - A name of the RAG Source in the App Builder UI.
  • Description - A description of the included data to be sent to the AI Service.
  • Source Type:
    • SQL Query - When chosen, the result set is included in CSV format. Make sure to only include the relavant columns, and limit the result set to the relevant rows.
    • Function Body Returning CLOB
    • Static text

RAG Sources and Server-side Conditions

Each RAG Source that passes a Server-side Condition is evaluated and included as an additional system message. Note that the RAG Sources are re-evaluated and sent with each call, which depending on the payload might have a large token usage.

To ensure only the relevant data to the conversation is included, you can use one of the following approaches for conditionally including RAG data:

  • Using a Security, Authorization Scheme can be helpful for providing certain data sets for certain users only.
  • Using a Server-side Condition offers even more flexibility. Besides the typical Condition types, RAG Sources support two Generative AI-specific Condition types: Any User Prompt Contains and Last User Prompt Contains. You can use these condition types to provide a comma-separated list of case-insensitive keywords. If any of the user prompts, or the last user prompts contains such a keyword, the RAG Source will be evaluated and the data will be included.
  • For maximum flexibility, two new bind variables are available both when executing Server-side Condition code, as well as within the SQL Query or Function Body. APEX$AI_ALL_USER_PROMPTS and APEX$AI_LAST_USER_PROMPT are CLOB bind variables that you can use to perform custom RAG logic.

Available Dictionary Views

You can also use the following dictionary views to query an application's AI Configurations:

  • APEX_APPL_AI_CONFIGS
  • APEX_APPL_AI_CONFIG_RAG_SRCS

18.8.4.3.2 Creating an AI Configuration

Create an AI Configuration in Shared Components on the Generative AI Configurations page.

Tip:

Before you can create an AI configuration, you must define a Generative AI Service and create an application. See Managing Generative AI Services and Creating Applications.

To create an AI Configuration:

  1. Navigate to the AI Configuration page:
    1. On the Workspace home page, click the App Builder icon.
    2. Select the application.
    3. On the Application Home page, click Shared Components.
      The Shared Components page appears.
    4. Under Generative AI and click AI Configurations.
      The Generative AI Services page appears.
  2. Click Create.
    The Create / Edit page appears.
  3. Configure the AI Configuration attributes:
    1. Identification, Name - Enter the name of the AI Configuration.
    2. Identification, Static ID - Enter a Static ID of the AI Configuration. Use this ID to reference the AI Configuration in the APIs in the APEX_AI package.
    3. Generative AI, Service - Select the Generative AI Service to be used by the AI Configuration. By default, the Application Default is used.
    4. Generative AI, System Prompt - Specify the initial instructions or context for the AI service. A well-crafted system prompt guides the AI's behavior and sets the tone for its responses. See item Help for more details.
    5. Generative AI, Welcome Message - Enter optional welcome message shown by the AI Assistant, for example:

      How may I help you today?

    6. Advanced, Temperature - Specify the creativity and randomness of the responses. A lower temperature makes the output more focused, deterministic, and conservative, favoring common or predictable answers. A higher temperature increases the models creativity, making it more likely to produce varied and less conventional responses. Adjust the temperature based on the desired balance between precision and creativity in the responses.

      Temperature may vary depending on the AI Provider. Oracle recommends the temperature values of the AI Service be evaluated when choosing the appropriate value.

    7. Advanced, Comments - Enter comments or notes.
    8. Click Create.

    Once you create an AI Configuration, you can continue to edit it or create a RAG Source. Retrieval-Augmented Generation (RAG) Sources are used by the Generative AI Service to improve response quality by providing relevant information

  4. To create a RAG Source, click Create RAG Source.

    The RAG Source page appears.

  5. Configure the RAG Source:
    1. Identification, Name - Enter the name of the RAG Source.
    2. Description, Description - Enter a brief description of the RAG Source that will be sent to the AI Service. This description should clearly explain the nature and content of the data being provided, helping the AI to better understand and process the information.
    3. Source, Type - Select the Source Type that defines the RAG Source for this Generative AI configuration. Options include:
      • SQL Query - Data is sourced from a SQL Query from the local database.
      • Function Body - Data is sourced from a Function Body that returns a CLOB.
      • Static - User-defined static text, suitable for entering hard-coded text information that is not sourced from your database.

      Depending upon your selection, enter the SQL Query, Function Body, or text in the Code Editor. See item Help adjacent to the Code Editor to learn more and view examples for each option.

    4. Advanced, Maximum Tokens - Specify the maximum number of tokens that this RAG source can include. If a row exceeds the remaining token limit, it will be entirely skipped to ensure the response stays within the specified token count.

      Note:

      The token calculation is only an approximate estimate of the exact calculation used by the AI Service.
    5. Server-Side Condition, Type - Select a condition type that must be met in order for this RAG Source to execute. In addition to the typical Condition types, RAG Sources support two Generative AI-specific Condition types: Any User Prompt Contains and Last User Prompt Contains. You can use these condition types to provide a comma-separated list of case-insensitive keywords. If any of the user prompts, or the last user prompts contains such a keyword, the RAG Source will be evaluated and the data will be included.

      You can use the following special bind variables to access and evaluate the user's prompt:

      • APEX$AI_LAST_USER_PROMPT - Retrieves the most recent user-entered prompt.
      • APEX$AI_ALL_USER_PROMPTS - Retrieves all user prompts, concatenated into a single string.
    6. Configuration, Build Option - Optionally select an authorization scheme which must evaluate to TRUE in order for this RAG source to be executed.
    7. Comments, Comments - Enter any comments or notes.
    8. Click Create.

18.8.4.3.3 Editing or Deleting an AI Configuration

Edit or delete an AI Configuration or RAG Source from the Generative AI Services, Create/Edit page.

To edit or delete an AI Configuration or RAG Source:

  1. Navigate to the AI Configuration page:
    1. On the Workspace home page, click the App Builder icon.
    2. Select the application.
    3. On the Application Home page, click Shared Components.
      The Shared Components page appears.
    4. Under Generative AI and click AI Configurations.
      The Generative AI Configurations page appears.
  2. To edit an AI Configuration:
    1. On the Generative AI Configurations page, click the configuration Name.

      The Create / Edit page appears.

    2. Edit the appropriate attributes. To learn more about a specific attribute, see item Help.
    3. Click Apply Changes.
  3. To delete an AI Configuration:

    Tip:

    If an AI Configuration is in use, you cannot delete it.
    1. On the Generative AI Configurations page, click the configuration Name.
    2. Click Delete.
    3. Confirm your selection and click Delete again.
  4. To edit a RAG Source:
    1. On the Generative AI Configurations page, click the RAG Source Name.

      The RAG Source page appears.

    2. Edit the appropriate attributes. To learn more about a specific attribute, see item Help.
    3. Click Apply Changes.
  5. To delete a RAG Source:
    1. On the Generative AI Configurations page, click the RAG Source Name.

      The RAG Source page appears.

    2. Click Delete.
    3. Confirm your selection and click Delete again.

18.8.4.3.4 Copying or Subscribing to an AI Configuration

Copy an AI Configuration from the current application or from another application. When copying an AI Configuration from another application, you can also subscribe to it.

To copy an AI Configuration:

  1. Navigate to the AI Configuration page:
    1. On the Workspace home page, click the App Builder icon.
    2. Select the application.
    3. On the Applicatioin Home page, click Shared Components.
      The Shared Components page appears.
    4. Under Generative AI and click AI Configurations.
      The Generative AI Services page appears.
  2. On the AI Configuration, click Copy.
  3. Copy From - Choose where to copy the AI Configuration from. Options include:
    • This Application
    • Other Application
  4. To copy from the current application:
    1. Copy From - Select This Application.
    2. Copy Configuration - Select the configuration to copy.
    3. Name - Enter the name of the configuration you would like to create.
    4. Click Copy.
  5. To copy from another application:
    1. Copy From - Select Other Application.
    2. Application - Select the application from which you want to copy.
    3. Copy Configuration - Select the configuration to copy.
    4. Subscribe - Enable Subscribe to subscribe to the configuration.
    5. Click Copy.

18.8.4.3.5 Viewing AI Configuration Utilization

View a report that details where AI Configurations are used within the current workspace.

To view the AI Configurations Utilization report:

  1. Navigate to the Generative AI Services page:
    1. On the Workspace home page, click the App Builder icon.
    2. Select the application.
    3. On the Application Home page, click Shared Components.
      The Shared Components page appears.
    4. Under Generative AI and click AI Configurations.
      The Generative AI Configurations page appears.
  2. On Generative AI Configurations page, click Utilization.

    The Generative AI Configurations Utilization report appears.

18.8.4.3.6 Viewing AI Configuration History

View a report of recent modifications made to AI Configurations in this workspace.

To view the AI Configurations History report:

  1. Navigate to the Generative AI Services page:
    1. On the Workspace home page, click the App Builder icon.
    2. Select the application.
    3. On the Application Home page, click Shared Components.
      The Shared Components page appears.
    4. Under Generative AI and click AI Configurations.
      The Generative AI Configurations page appears.
  2. On the Generative AI Configurations page, click History.

    The Generative AI Configurations History report appears.