DBMS_AI_SEM Package
The DBMS_AI_SEM package creates and manages semantic sources that Select AI can use.
Summary of DBMS_AI_SEM Subprograms
This section covers the DBMS_AI_SEM subprograms and supporting parameter or attribute references provided with Autonomous AI Database.
| Subprogram | Description |
|---|---|
CREATE_SEMANTIC_SOURCE |
Creates a semantic source configuration. |
DISABLE_SEMANTIC_SOURCE |
Disables a semantic source. |
DROP_SEMANTIC_SOURCE |
Drops a semantic source. |
ENABLE_SEMANTIC_SOURCE |
Enables a semantic source. |
GET_DEFINITION |
Returns a semantic source definition. |
GRANT_SEMANTIC_SOURCE_ACCESS |
Grants access to a semantic source. |
REFRESH_SEMANTIC_SOURCE |
Refreshes existing cached object context. |
REVOKE_SEMANTIC_SOURCE_ACCESS |
Revokes access to a semantic source. |
UPDATE_SEMANTIC_SOURCE |
Updates source attributes. |
CREATE_SEMANTIC_SOURCE Procedure
Creates a semantic source and configures how Select AI retrieves context from it.
Syntax
DBMS_AI_SEM.CREATE_SEMANTIC_SOURCE(
source_name IN VARCHAR2,
type IN VARCHAR2,
attributes IN CLOB,
status IN VARCHAR2 DEFAULT NULL,
description IN CLOB DEFAULT NULL
);
Parameters
| Parameter | Description |
|---|---|
source_name |
Specify a name of the semantic source. This is a mandatory parameter. |
type |
Source type: catalog, custom, file, or mcp. This is a mandatory parameter. |
attributes |
JSON object containing source configuration attributes. This is a mandatory parameter. |
status |
Initial status: ENABLED or DISABLED. Defaults to ENABLED when omitted or NULL. |
description |
Optional source description. Defaults to NULL. |
Usage Notes
- Creating a source does not attach it to an AI profile. Configure the profile’s
semantic_sourceattribute separately. See Profile Attributes for more details. - See Prerequisites for Using Semantic Context with Select AI for more information.
- When you omit
statusor pass SQLNULL, the package sets the status toENABLED. - The package rejects an empty or blank value for a required string attribute. When you omit
description, pass SQLNULL, or specify an empty description, the source has no description. - You cannot update
descriptionafter creating the source. - You must provide
attributesparameter. - Required attributes must contain nonempty values that satisfy the source type and scope.
Example
- For prerequisites, see Prerequisites for Using Semantic Context with Select AI.
- Create the
SALES_GLOBAL_CONTEXTcallback before you create the semantic source. The user who uses the source must have theEXECUTEprivilege on the callback function. When another schema owns the callback, specify its qualified name. The callback owner must grant the required privilege. See Custom Callback Input and Output Contract for the complete request and response requirements.
The following example creates a custom semantic source that retrieves global context from the SALES_GLOBAL_CONTEXT callback function.
BEGIN
DBMS_AI_SEM.CREATE_SEMANTIC_SOURCE(
source_name => 'SALES_BUSINESS_CONTEXT',
type => 'custom',
attributes => '{
"scope": "global",
"global_callback_func": "SALES_GLOBAL_CONTEXT"
}'
);
END;
/
Semantic Source Attributes
Lists semantic source attributes that can used in the DBMS_AI_SEM.CREATE_SEMANTIC_SOURCE procedure.
Common Attributes
| Attribute | Required | Default Value | Data Type | Description |
|---|---|---|---|---|
scope |
Yes | None | String: object, global, or all | Specifies object, global, or all. File sources support only global. |
source_endpoint |
Required for catalog, MCP, and file sources | None | String, nonempty, maximum 4,000 characters | Specifies the endpoint or file location. |
credential_name |
Conditional Catalog or MCP: Yes. File: Required for URI or object-store locations; Optional for directory files. |
None | String | Credential used to access the configured source. Not used for custom sources or database directory files. |
cache |
No | true |
Boolean | Enables object-context caching for catalog and MCP sources with object or all scope. The package rejects unsupported source-type and scope combinations. |
refresh_rate |
No | 60 minutes |
Number: positive whole number | Specifies the proactive refresh interval. For cache-enabled catalog and MCP sources, it controls scheduled object-cache refresh. For file sources, it controls the file-indexing pipeline. It is not a cache time-to-live value. |
match_limit |
No | 10 (File: 5) |
Number: positive whole number | Maximum results requested for global context. Defaults to 10 for Alation, Informatica, and MCP sources and 5 for file sources. Does not apply to object context. |
For caching support, cache population, retention, refresh failures, and lifecycle behavior, see Semantic-Context Caching.
Catalog Attributes
| Attribute | Required | Default Value | JSON Data Type | Description |
|---|---|---|---|---|
provider |
Yes | None | String: alation or informatica | Specify the catalog provider. For example, alation or informatica. |
data_source_name |
Yes for object and all |
None | Nonempty string | Identifies the catalog data source containing object metadata. |
For object context, Select AI sends authorized database-object identifiers to the catalog provider adapter. For global context, the adapter searches for business terms related to the natural-language request.
The provider adapter maps catalog results to semantic context. A valid response with no matching entries represents an empty result.
For data catalog provider, such as, Alation object context, Select AI matches returned table names to requested database objects without case sensitivity. If multiple requested objects have the same table name, Select AI excludes the ambiguous table and its column metadata.
Custom Attributes
| Attribute | Required | Default Value | JSON Data Type | Description |
|---|---|---|---|---|
object_callback_func |
Yes for object and all scope |
None | String: PL/SQL function name | Function that returns object context. |
global_callback_func |
Yes for global or all scope |
None | String: PL/SQL function name | Function that returns global context. |
params |
No | None | JSON object | Optional JSON object passed to callbacks. |
Custom Callback Input and Output Contract
A custom semantic source uses PL/SQL callback functions to supply business context. Each callback accepts one CLOB containing a JSON request and returns one CLOB containing a JSON array.
The callback function must use the following signature:
FUNCTION callback_name(
p_request IN CLOB
) RETURN CLOB;
The user who uses the semantic source must have the EXECUTE privilege on the configured callback function.
Object Callback Request
For object context, Select AI supplies the requested database objects and configured parameters:
{
"objects": [
{
"owner": "ADB_USER",
"name": "CUSTOMERS"
}
],
"params": {
"domain": "sales"
}
}
| Property | Required | Description |
|---|---|---|
objects |
Yes | Array of database objects for which Select AI requests context. |
objects[].owner |
Yes | Object owner or schema name. |
objects[].name |
Yes | Object name. |
params |
Yes | Parameters from the semantic-source configuration. Select AI supplies {} when the source has no configured parameters. |
Select AI does not include user_prompt in an object callback request.
Global Callback Request
For global context, Select AI supplies the natural-language request and configured parameters:
{
"user_prompt": "Which customers are at risk?",
"params": {
"domain": "sales"
}
}
| Property | Required | Description |
|---|---|---|
user_prompt |
Yes | User’s natural-language request. |
params |
Yes | Parameters from the semantic-source configuration. Select AI supplies {} when the source has no configured parameters. |
Select AI does not include objects in a global callback request.
Callback Response
The callback returns a top-level JSON array. Do not wrap the array in an items property.
A valid empty array represents an empty result. Select AI continues processing the remaining semantic sources.
For object context:
definitionis required and must contain a nonempty value.applies_tois required.applies_tomust contain exactly one object withownerandname.- The object must identify a database object from the callback request.
termis optional.
The following response associates a definition with the ADB_USER.CUSTOMERS table:
[
{
"term": "TOTAL_SPEND",
"definition": "Cumulative lifetime spend for a customer.",
"applies_to": [
{
"owner": "ADB_USER",
"name": "CUSTOMERS"
}
]
}
]
For global context:
definitionis required and must contain a nonempty value.termis optional and can contain an empty value.- Do not include
applies_to.
The following response includes a term:
[
{
"term": "At-Risk Customer",
"definition": "A high-value customer with no order in the last 90 days and an open support escalation."
}
]
The following response omits the optional term:
[
{
"definition": "A high-value customer has no order in the last 90 days and an open support escalation."
}
]
When a response omits term, SHOWCONTEXT displays the definition without a term prefix.
File Attributes
| Attribute | Required | Default Value | Data Type | Description |
|---|---|---|---|---|
profile_name |
Yes | None | String: existing Select AI embedding-profile identifier | Embedding profile used to process and index file content. |
File sources support only global scope.
During source creation, Select AI extracts the file content, divides it into chunks, creates vector embeddings through the configured embedding profile, and indexes the content.
At request time, Select AI searches the vector index for content relevant to the natural-language request. The match_limit attribute controls the maximum number of results.
The refresh_rate attribute controls the file-indexing pipeline. It does not control an object-context cache.
File endpoints support * and ? wildcard characters for matching file names and Object Storage paths.
MCP Attributes
The following attributes configure the tools that an MCP semantic source uses to retrieve object or global context.
| Attribute | Required | Default | JSON Data Type | Description |
|---|---|---|---|---|
object_tool |
For object or all scope |
None | JSON object | Configuration for the MCP tool that retrieves object-specific context. |
global_tool |
For global or all scope |
None | JSON object | Configuration for the MCP tool that retrieves global context. |
Each tool configuration contains the following attributes:
| Attribute | Required | Description |
|---|---|---|
name |
Yes | Name of the MCP tool. |
arguments |
Yes | JSON object containing arguments supported by the configured MCP tool. The MCP server defines the argument names and values. The values can contain supported template variables. |
response_mapping |
Yes | Maps fields in the MCP tool response to normalized semantic-context items. |
MCP Template Variables
Use template variables to pass request information to the MCP tool and map provider object identifiers to database objects.
| Location | Variable | Example Value | Description |
|---|---|---|---|
object_tool.arguments |
${object_names} |
CUSTOMERS and ORDERS |
Names of the requested database objects. Template variables are supported in JSON values, not keys. |
object_tool.arguments |
${objects_qualified} |
SALES.CUSTOMERS and SALES.ORDERS |
Names of the requested database objects qualified with their schema owners. |
global_tool.arguments |
${prompt} |
Which customers are at risk? |
Complete natural-language request. |
global_tool.arguments |
${prompt_keywords} |
customers, risk |
Keywords extracted from the request, or the complete request when Select AI cannot extract keywords. If no keywords are extracted, the full user prompt is used instead, and the MCP tool is still called. |
global_tool.arguments |
${match_limit} |
10 |
Configured global-result limit. The default is 10. |
object_tool.response_mapping.object_pattern |
${owner} |
SALES |
Schema owner of the requested database object. |
object_tool.response_mapping.object_pattern |
${name} |
CUSTOMERS |
Name of the requested database object. |
MCP Request Mapping
Argument names belong to the configured MCP tool. Select AI does not require fixed argument names such as objects, question, or keywords.
Configure supported template variables in JSON values, not JSON property names. Select AI substitutes each variable before contacting the configured tool. The following table describes the values that Select AI supplies for MCP template variables:
| Location | Template Variable | Supplied Value |
|---|---|---|
object_tool.arguments |
${object_names} |
Names of the requested database objects without schema qualification. |
object_tool.arguments |
${objects_qualified} |
Names of the requested database objects qualified with their schema owners. |
global_tool.arguments |
${prompt} |
Complete natural-language request. |
global_tool.arguments |
${prompt_keywords} |
Keywords extracted from the request. If Select AI cannot extract keywords, it supplies the complete request. |
global_tool.arguments |
${match_limit} |
Configured global-result limit. The default is 10. Select AI supplies a number when this variable forms the complete JSON value. |
object_tool.response_mapping.object_pattern |
${owner} |
Owner of the requested database object. |
object_tool.response_mapping.object_pattern |
${name} |
Name of the requested database object. |
Argument names belong to the configured MCP tool. Select AI does not require fixed argument names such as objects, question, or keywords. Map the supported template variables to the argument names that the MCP tool expects.
MCP Response Mapping
The response_mapping object maps fields in a provider-specific MCP response to normalized semantic-context items.
| Field | Required | Description |
|---|---|---|
items |
Yes | JSON path that selects the response items. The path must end with [*], for example, $.results[*]. |
term |
Yes | JSON path that selects the term or name from each response item. |
definition |
Yes | JSON path that selects the semantic definition from each response item. |
object |
For an object tool | JSON path that selects the provider’s object identifier from each response item. |
object_pattern |
For an object tool | Pattern that maps the provider’s object identifier to the requested database object. The pattern must contain ${owner} and ${name}. |
Usage Notes for MCP Response
-
For an object tool, specify both
objectandobject_pattern. Each normalized object-context item must identify a requested database object. -
For a global tool, do not specify
objectorobject_pattern. These fields are not supported in the response mapping for a global tool. -
The fields selected by
termanddefinitionmust contain nonempty values. Select AI excludes an item when either value is missing or empty. -
If
response_mappingselects no items from an otherwise valid MCP response, Select AI treats the result as empty semantic context and continues processing. -
Select AI validates the MCP tool configuration when you create or update the semantic source. It does not check whether the tool is available at configuration time. If the tool is unavailable or returns an error during semantic-context retrieval, the retrieval and the Select AI request fail.
Source Retrieval and Empty-Result Behavior
A valid empty result is not a retrieval failure. Select AI continues processing the remaining enabled semantic sources.
If retrieval fails for any enabled semantic source, the entire Select AI request fails. Select AI does not return partial context from other sources.
This behavior applies to SHOWCONTEXT and other Select AI actions.
DISABLE_SEMANTIC_SOURCE Procedure
Disables a semantic source. A disabled source does not contribute context to profiles that reference it.
Note: Select AI skips a disabled semantic source during context retrieval, even when the source remains attached to the active AI profile. Select AI continues to use other enabled sources. If the profile references a semantic source that does not exist, the request fails.
Syntax
DBMS_AI_SEM.DISABLE_SEMANTIC_SOURCE(
source_name IN VARCHAR2
);
Parameters
| Parameter | Description |
|---|---|
source_name |
Name of the source to disable. |
Example
The following example disables the SALES_ALATION_CONTEXT semantic source:
BEGIN
DBMS_AI_SEM.DISABLE_SEMANTIC_SOURCE(
source_name => 'SALES_ALATION_CONTEXT'
);
END;
/
DROP_SEMANTIC_SOURCE Procedure
Drops a semantic source. Only the source owner can drop the source.
Syntax
DBMS_AI_SEM.DROP_SEMANTIC_SOURCE(
source_name IN VARCHAR2,
force IN BOOLEAN DEFAULT FALSE
);
Parameters
| Parameter | Description |
|---|---|
source_name |
Name of the source to drop. |
force |
When TRUE, suppresses an error if the source does not exist. Defaults to FALSE. |
Usage Notes
- The source cannot be dropped while attached to an active AI profile.
- Dropping a catalog or MCP source removes its associated cached context.
- For a file source, the procedure also removes the source’s vector index, pipeline, and indexed data.
For complete lifecycle behavior, see Cached-Context Lifecycle.
Example
The following example drops SALES_ALATION_CONTEXT and suppresses an error if the source does not exist:
BEGIN
DBMS_AI_SEM.DROP_SEMANTIC_SOURCE(
source_name => 'SALES_ALATION_CONTEXT',
force => TRUE
);
END;
/
ENABLE_SEMANTIC_SOURCE Procedure
Enables a semantic source so that it can contribute context to profiles that reference it.
Syntax
DBMS_AI_SEM.ENABLE_SEMANTIC_SOURCE(
source_name IN VARCHAR2
);
Parameters
| Parameter | Description |
|---|---|
source_name |
Name of the source to enable. |
Example
The following example enables the SALES_ALATION_CONTEXT semantic source:
BEGIN
DBMS_AI_SEM.ENABLE_SEMANTIC_SOURCE(
source_name => 'SALES_ALATION_CONTEXT'
);
END;
/
GET_DEFINITION Function
Returns the definition of a semantic source.
Syntax
DBMS_AI_SEM.GET_DEFINITION(
source_name IN VARCHAR2
) RETURN CLOB;
Parameters
| Parameter | Description |
|---|---|
source_name |
Name of the source whose definition you want to retrieve. |
Returns
A CLOB containing the source definition.
Usage Notes
- Only the semantic source owner can retrieve its definition. The source name can be unqualified or qualified with the owner’s schema.
- The definition includes configured credential names and references to callbacks or embedding profiles, but not their definitions or credential secrets.
- Source access grants and AI profile associations are not included and must be configured separately.
- Replaying the definition creates the source in the user’s schema.
Example
The following query returns the definition of the SALES_ALATION_CONTEXT semantic source:
SELECT DBMS_AI_SEM.GET_DEFINITION(
source_name => 'SALES_ALATION_CONTEXT'
)
FROM dual;
GRANT_SEMANTIC_SOURCE_ACCESS Procedure
Grants a database user or role access to a semantic source.
Syntax
DBMS_AI_SEM.GRANT_SEMANTIC_SOURCE_ACCESS(
source_name IN VARCHAR2,
user_or_role_name IN VARCHAR2
);
Parameters
| Parameter | Description |
|---|---|
source_name |
Name of the source to share. |
user_or_role_name |
Database user or role that receives access. |
Usage Notes
Only the source owner can grant access. A grantee can attach and use the source but cannot modify or drop it.
For custom sources, the requesting user also requires EXECUTE privilege on the callback functions.
Example
The following example grants REPORTING_ROLE access to the SALES_ALATION_CONTEXT semantic source:
BEGIN
DBMS_AI_SEM.GRANT_SEMANTIC_SOURCE_ACCESS(
source_name => 'SALES_ALATION_CONTEXT',
user_or_role_name => 'REPORTING_ROLE'
);
END;
/
REFRESH_SEMANTIC_SOURCE Procedure
Refreshes existing cached object context.
Syntax
DBMS_AI_SEM.REFRESH_SEMANTIC_SOURCE(
source_name IN VARCHAR2
);
Parameters
| Parameter | Description |
|---|---|
source_name |
Name of the source whose cached context you want to refresh. |
Usage Notes
-
Only the source owner can perform a refresh.
-
The source must be a catalog or MCP source with
cacheset totrueandobjectorallscope. - The procedure refreshes object context already represented in the cache.
- The procedure does not discover new database objects or update the automated object-list index.
- The refresh runs asynchronously. The procedure returns after the database accepts the request.
- The package reports an error if a scheduled or requested refresh is already in progress.
For cache retention and refresh-failure behavior, see Semantic-Context Caching.
Example
The following example requests a refresh of the cached object context for the SALES_ALATION_CONTEXT semantic source:
BEGIN
DBMS_AI_SEM.REFRESH_SEMANTIC_SOURCE(
source_name => 'SALES_ALATION_CONTEXT'
);
END;
/
REVOKE_SEMANTIC_SOURCE_ACCESS Procedure
Revokes a database user or role’s access to a semantic source.
Syntax
DBMS_AI_SEM.REVOKE_SEMANTIC_SOURCE_ACCESS(
source_name IN VARCHAR2,
user_or_role_name IN VARCHAR2
);
Parameters
| Parameter | Description |
|---|---|
source_name |
Name of the shared source. |
user_or_role_name |
Database user or role whose access you want to revoke. |
Usage Notes
Only the source owner can revoke access. After revocation, the grantee can no longer attach or use the source.
Example
The following example revokes access to the SALES_ALATION_CONTEXT semantic source from REPORTING_ROLE:
BEGIN
DBMS_AI_SEM.REVOKE_SEMANTIC_SOURCE_ACCESS(
source_name => 'SALES_ALATION_CONTEXT',
user_or_role_name => 'REPORTING_ROLE'
);
END;
/
UPDATE_SEMANTIC_SOURCE Procedure
Updates one or more attributes of an existing semantic source.
Syntax
DBMS_AI_SEM.UPDATE_SEMANTIC_SOURCE(
source_name IN VARCHAR2,
attribute_name IN VARCHAR2,
attribute_value IN CLOB DEFAULT NULL
);
DBMS_AI_SEM.UPDATE_SEMANTIC_SOURCE(
source_name IN VARCHAR2,
attribute_name IN VARCHAR2,
attribute_value IN VARCHAR2
);
DBMS_AI_SEM.UPDATE_SEMANTIC_SOURCE(
source_name IN VARCHAR2,
attribute_name IN VARCHAR2,
attribute_value IN BOOLEAN
);
DBMS_AI_SEM.UPDATE_SEMANTIC_SOURCE(
source_name IN VARCHAR2,
attributes IN CLOB
);
Parameters
| Parameter | Description |
|---|---|
source_name |
Name of the source to update. |
attribute_name |
Attribute to update in a single-attribute call. |
attribute_value |
Specify a new value. The CLOB overload defaults to NULL. |
attributes |
JSON object containing attributes to update. |
Usage Notes
- Only the source owner can update its configuration. The source type determines which attributes are valid.
- The procedure rejects SQL
NULLfor an attribute that requires a value. - The
BOOLEANoverload treatsNULLasfalse. - A multiple-attribute update changes only the attributes included in the JSON object.
- Attributes omitted from a multiple-attribute update retain their existing values.
- A multiple-attribute update changes only the attributes present in the JSON object.
- Omitted attributes retain their existing values.
- Passing SQL
NULLor{}to the multiple-attributeattributesparameter makes no changes. - The package rejects an explicit JSON
nullwithORA-20061. It does not remove the attribute, restore its default, or change its current value. - The package rejects an empty or blank value for a required string attribute.
- You cannot update
description. - To restore a supported attribute to its default, assign its documented default value explicitly. For example, set explicit values for
cache,refresh_rate, ormatch_limitto restore these defaults. - The package does not provide a general reset-to-default operation.
Example
The following example enables caching for the SALES_ALATION_CONTEXT semantic source:
BEGIN
DBMS_AI_SEM.UPDATE_SEMANTIC_SOURCE(
source_name => 'SALES_ALATION_CONTEXT',
attributes => '{"cache": true}'
);
END;
/