Example: Use Semantic Context with Select AI
Use semantic context to provide business definitions that Select AI needs to interpret a natural-language question. This example shows how to supplement database metadata with business terminology and relationships, custom callbacks, a supported data catalog from Alation or Informatica, a file, and an MCP server source.
Each example follows this workflow:
- Prepare the database objects and business metadata.
- Create the semantic source.
- Attach the semantic source to a Select AI profile.
- Use the
SHOWCONTEXTaction to inspect the retrieved semantic context. - Use the
SHOWSQLaction to inspect the generated SQL. - Run the natural-language request.
The examples use ADB_USER as the application schema.
About This Example
The following table summarizes the example:
| Semantic source | Example scenario | Context supplied to Select AI |
|---|---|---|
| Custom | Find countries that have automobile customers who owe money | Callback functions describe the tables, join, business sector, and meaning of a negative account balance. |
| Catalog | Ask the same question using data catalog provider, such as Alation and Informatica, metadata | Alation and Informatica supplies table and column descriptions and business-glossary definitions. |
| File | Query emissions data using terminology from a file source | A PDF defines environmental acronyms such as VOC, NOx, EI, and AER. |
| MCP | Retrieve the customer metadata from an MCP server | MCP tools supply object descriptions and prompt-level business definitions. |
Before You Begin
Complete the following before you run the examples:
- Prerequisites for Using Semantic Context with Select AI.
- Perform Prerequisites for Select AI
- Connect as a schema user, for example,
ADB_USERunless an example explicitly instructs an administrator to run a statement. - Create an OCI credential. The example uses OCI Generative AI credential named
OCI_CRED, or replaceOCI_CREDwith the name of your credential. -
Replace the following values in each Select AI profile:
<region><model_name><oci_compartment_id>
- Review the source content before attaching a semantic source. Select AI can include retrieved semantic context in the request that it sends to the configured large language model.
Select a Source Configuration
Complete the common setup once. Then complete one of the following source configurations and run the shared verification steps.
| Source type | Scope in this example | |
|---|---|---|
| Custom | You need user-defined PL/SQL callback functions and custom logic to retrieve business context. | all |
| File | Your team maintains business definitions in a document that Select AI can process and index. | global |
| MCP | Your organization exposes business metadata through MCP tools. | all |
| Catalog: Alation, Informatica | Your organization maintains object descriptions and business terms in Alation or Informatica. | all |
The configurations use separate AI profiles. Each profile references one source so that you can compare the alternatives independently.
Prepare the Sample Data and Callback Functions for Custom Semantic Source
The custom, catalog, and MCP examples use the same customer and country data. The data includes one country that satisfies the example request.
Create the Customer and Country Test Data
The custom, catalog, and MCP examples use the same customer and country data. The data includes one country that satisfies the example request.
Create the country table:
CREATE TABLE nation (
country_id NUMBER PRIMARY KEY,
country_name VARCHAR2(40) NOT NULL
);
--Create the customer table:
CREATE TABLE customer (
customer_id NUMBER PRIMARY KEY,
country_id NUMBER NOT NULL REFERENCES nation(country_id),
market_segment VARCHAR2(30) NOT NULL,
account_balance NUMBER(12,2) NOT NULL
);
--Insert two countries:
INSERT INTO nation VALUES (1, 'INDIA');
INSERT INTO nation VALUES (2, 'UNITED STATES');
--Insert three customers:
INSERT INTO customer VALUES (1, 1, 'AUTOMOBILE', -50);
INSERT INTO customer VALUES (2, 2, 'AUTOMOBILE', 100);
INSERT INTO customer VALUES (3, 2, 'HOUSEHOLD', -25);
COMMIT;
--Run the direct SQL query to establish the expected result:
SELECT DISTINCT n.country_name
FROM customer c
JOIN nation n
ON n.country_id = c.country_id
WHERE c.market_segment = 'AUTOMOBILE'
AND c.account_balance < 0
ORDER BY n.country_name;
The query returns:
COUNTRY_NAME
--------------
INDIA
The examples use the following business definitions:
| Business expression | Database meaning |
|---|---|
| Automobile customer | CUSTOMER.MARKET_SEGMENT = 'AUTOMOBILE' |
| Owes money | CUSTOMER.ACCOUNT_BALANCE < 0 |
| Customer country | Join CUSTOMER.COUNTRY_ID to NATION.COUNTRY_ID. |
| Country name | Read NATION.COUNTRY_NAME. |
Example: Use a Custom Semantic Source
A custom semantic source calls PL/SQL functions that return semantic context. This example creates one callback for database-object context and another callback for prompt-level context.
The object callback describes the requested tables. The global callback explains the business expressions in the natural-language request.
Before You Begin
Complete the following:
- See Prerequisites for Using Semantic Context with Select AI
- Grant
EXECUTEon custom callback functions when a user other than the function owner runs Select AI with those callbacks.
Create the Object Callback
The object callback receives a JSON object with an objects array. Each array element contains an object owner and object name.
The callback returns a top-level JSON array. The callback returns applies_to as an array containing one object with the database object’s owner and name:
Create the object callback:
CREATE OR REPLACE FUNCTION customer_object_callback(
p_request IN CLOB
) RETURN CLOB
IS
l_request JSON_OBJECT_T := JSON_OBJECT_T.parse(p_request);
l_objects JSON_ARRAY_T := l_request.get_array('objects');
l_result JSON_ARRAY_T := JSON_ARRAY_T('[]');
l_object JSON_OBJECT_T;
l_item JSON_OBJECT_T;
l_applies JSON_ARRAY_T;
l_applies_object JSON_OBJECT_T;
l_owner VARCHAR2(128);
l_name VARCHAR2(128);
BEGIN
IF l_objects IS NULL OR l_objects.get_size = 0 THEN
RETURN l_result.to_clob;
END IF;
FOR i IN 0 .. l_objects.get_size - 1 LOOP
l_object := TREAT(l_objects.get(i) AS JSON_OBJECT_T);
l_owner := UPPER(l_object.get_string('owner'));
l_name := UPPER(l_object.get_string('name'));
IF l_owner = USER
AND l_name IN ('CUSTOMER', 'NATION') THEN
l_applies := JSON_ARRAY_T('[]');
l_applies_object := JSON_OBJECT_T('{}');
l_applies_object.put('owner', l_owner);
l_applies_object.put('name', l_name);
l_applies.append(l_applies_object);
l_item := JSON_OBJECT_T('{}');
l_item.put('term', l_name);
l_item.put(
'definition',
CASE l_name
WHEN 'CUSTOMER' THEN
'CUSTOMER.COUNTRY_ID joins NATION.COUNTRY_ID; ' ||
'MARKET_SEGMENT identifies the business sector; ' ||
'a negative ACCOUNT_BALANCE means that the customer owes money.'
ELSE
'COUNTRY_NAME identifies the country for COUNTRY_ID.'
END
);
l_item.put('applies_to', l_applies);
l_result.append(l_item);
END IF;
END LOOP;
RETURN l_result.to_clob;
END;
/
For example, the callback returns the following object association for the ADB_USER.CUSTOMER table:
"applies_to": [
{
"owner": "ADB_USER",
"name": "CUSTOMER"
}
]
Check the compilation results:
SHOW ERRORS
Create the Global Callback
The global callback receives the natural-language request in user_prompt. It returns an empty JSON array when the request does not contain a relevant business expression.
Create the global callback:
CREATE OR REPLACE FUNCTION customer_global_callback(
p_request IN CLOB
) RETURN CLOB
IS
l_request JSON_OBJECT_T := JSON_OBJECT_T.parse(p_request);
l_result JSON_ARRAY_T := JSON_ARRAY_T('[]');
l_item JSON_OBJECT_T;
BEGIN
IF INSTR(
LOWER(l_request.get_string('user_prompt')),
'automobile'
) > 0 THEN
l_item := JSON_OBJECT_T('{}');
l_item.put('term', 'automobile sector');
l_item.put(
'definition',
'Automobile sector means MARKET_SEGMENT = AUTOMOBILE. ' ||
'Owes money means ACCOUNT_BALANCE < 0.'
);
l_result.append(l_item);
END IF;
RETURN l_result.to_clob;
END;
/
Check the compilation results:
SHOW ERRORS
Create the Custom Semantic Source
Create a source with all scope so that Select AI can retrieve both object and global context.
Object-context caching is not supported for custom source type. See Semantic-Context Caching for information on caching.
BEGIN
DBMS_AI_SEM.CREATE_SEMANTIC_SOURCE(
source_name => 'CUSTOMER_CUSTOM_SOURCE',
type => 'custom',
attributes => '{
"scope": "all",
"object_callback_func": "CUSTOMER_OBJECT_CALLBACK",
"global_callback_func": "CUSTOMER_GLOBAL_CALLBACK"
}'
);
END;
/
Create the Select AI Profile and Attach the Semantic Source
Create a profile that exposes the two test tables and attaches the custom semantic source through semantic_source parameter :
BEGIN
DBMS_CLOUD_AI.CREATE_PROFILE(
profile_name => 'CUSTOMER_CUSTOM_PROFILE',
attributes => '{
"provider": "oci",
"region": "<region>",
"credential_name": "OCI_CRED",
"model": "<model_name>",
"oci_compartment_id": "<oci_compartment_id>",
"object_list": [
{"owner": "ADB_USER", "name": "CUSTOMER"},
{"owner": "ADB_USER", "name": "NATION"}
],
"enforce_object_list": true,
"semantic_source": [
"CUSTOMER_CUSTOM_SOURCE"
]
}'
);
END;
/
Inspect and Run the Request
Set the profile:
EXEC DBMS_CLOUD_AI.SET_PROFILE('CUSTOMER_CUSTOM_PROFILE');
Use SHOWCONTEXT to inspect the object and global context:
SELECT AI SHOWCONTEXT
Which countries have automobile customers who owe money;
The response likely includes:
- The join from
CUSTOMER.COUNTRY_IDtoNATION.COUNTRY_ID. - The meaning of
MARKET_SEGMENT. - The interpretation of a negative
ACCOUNT_BALANCE. - The definition of the automobile sector.
Use SHOWPROMPT to confirm that Select AI adds the semantic context to the provider prompt:
SELECT AI SHOWPROMPT
Which countries have automobile customers who owe money;
Use SHOWSQL to inspect the SQL:
SELECT AI SHOWSQL
Which countries have automobile customers who owe money;
Run the request:
SELECT AI
Which countries have automobile customers who owe money;
The request should return INDIA.
Cleanup
Drop the profile before dropping the attached semantic sources.
BEGIN
DBMS_CLOUD_AI.DROP_PROFILE('CUSTOMER_CUSTOM_PROFILE', TRUE);
DBMS_AI_SEM.DROP_SEMANTIC_SOURCE('CUSTOMER_CUSTOM_SOURCE', TRUE);
END;
/
Drop the callback functions:
DROP FUNCTION customer_global_callback;
DROP FUNCTION customer_object_callback;
Without the business definition, Select AI might interpret “automobile customers who owe money” differently or omit a condition. The baseline response depends on the model and available metadata; it has no fixed expected SQL.
Example: Use an Alation Catalog as a Semantic Source
This example uses Alation as the data catalog provider. Alation semantic source retrieves object descriptions and business-glossary terms from Alation.
This example uses the same ADB_USER.CUSTOMER and ADB_USER.NATION tables prepared in Prepare the Sample Data and Callback Functions for Custom Semantic Source as the custom example.
Before You Begin
Complete these Alation-specific requirements:
- Register
ADB_USER.CUSTOMERandADB_USER.NATIONin the Alation data source. - Add descriptions for the tables, join columns,
MARKET_SEGMENT, andACCOUNT_BALANCE. -
Add these glossary definitions:
Term Definition Automobile sector Customers for whom MARKET_SEGMENTequalsAUTOMOBILE.Owes money A customer owes money when ACCOUNT_BALANCEis less than zero. -
Obtain an OAuth 2.0 client ID and client secret from the Alation administrator. See Prerequisites for Using Semantic Context with Select AI for more details.
Note: Data catalog providers have different authorization requirements. Create a separate credential for each provider by using the
DBMS_CLOUD.CREATE_CREDENTIALprocedure. Specify this credential in thecredential_nameattribute when you create the catalog semantic source. See CREATE_CREDENTIAL Procedure and CREATE_SEMANTIC_SOURCE Procedure for more information. - Replace
org.alation.comwith the host name of the Alation instance. - Replace
<data_source_name>with the exact Alation data-source name that contains the metadata forADB_USER.
Grant Network Access
Connect as an administrator and grant ADB_USER HTTP access to the Alation host:
BEGIN
DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE(
host => 'org.alation.com',
ace => xs$ace_type(
privilege_list => xs$name_list('http'),
principal_name => 'ADB_USER',
principal_type => xs_acl.ptype_db
)
);
END;
/
Create the OAuth Credential for the Data Catalog Provider
Connect as the schema user or ADB_USER.
Create the credential only when it does not already exist. Replace the values with your own values:
BEGIN
DBMS_CLOUD.CREATE_CREDENTIAL(
credential_name => 'ALATION_OAUTH_CRED',
params => JSON_OBJECT(
'oauth2' VALUE JSON_OBJECT(
'client_id' VALUE '<client_id>',
'client_secret' VALUE '<client_secret>',
'grant_type' VALUE 'client_credentials',
'scope' VALUE 'all',
'endpoint' VALUE
'https://org.alation.com/oauth/v2/token/'
)
)
);
END;
/
Create the Semantic Source
Create the catalog source with all scope so Select AI can retrieve both object metadata and global glossary definitions:
BEGIN
DBMS_AI_SEM.CREATE_SEMANTIC_SOURCE(
source_name => 'CUSTOMER_ALATION_SOURCE',
type => 'catalog',
attributes => '{
"provider": "alation",
"scope": "all",
"source_endpoint": "https://org.alation.com",
"credential_name": "ALATION_OAUTH_CRED",
"data_source_name": "<data_source_name>"
}'
);
END;
/
Create the Select AI Profile and Attach the Semantic Source
Attach the Alation source to a profile through the semantic_source parameter, that exposes the customer and country tables:
BEGIN
DBMS_CLOUD_AI.CREATE_PROFILE(
profile_name => 'CUSTOMER_ALATION_PROFILE',
attributes => '{
"provider": "oci",
"region": "<region>",
"credential_name": "OCI_CRED",
"model": "<model_name>",
"oci_compartment_id": "<oci_compartment_id>",
"object_list": [
{"owner": "ADB_USER", "name": "CUSTOMER"},
{"owner": "ADB_USER", "name": "NATION"}
],
"enforce_object_list": true,
"semantic_source": [
"CUSTOMER_ALATION_SOURCE"
]
}'
);
END;
/
Inspect and Run the Request
Set the profile:
EXEC DBMS_CLOUD_AI.SET_PROFILE('CUSTOMER_ALATION_PROFILE');
Inspect the Alation context:
SELECT AI SHOWCONTEXT
Which countries have automobile customers who owe money;
Inspect the generated SQL:
SELECT AI SHOWSQL
Which countries have automobile customers who owe money;
Run the request:
SELECT AI
Which countries have automobile customers who owe money;
The request should return INDIA.
Cleanup
Drop the profile before dropping the attached semantic sources.
BEGIN
DBMS_CLOUD_AI.DROP_PROFILE('CUSTOMER_ALATION_PROFILE', TRUE);
DBMS_AI_SEM.DROP_SEMANTIC_SOURCE('CUSTOMER_ALATION_SOURCE', TRUE);
END;
/
Example: Use an Informatica Catalog as a Semantic Source
This example creates an Informatica semantic source and attaches it to a Select AI profile. Select AI retrieves object-level descriptions for the CUSTOMER and NATION tables from the Informatica catalog. This example assumes that the required descriptions for the sample tables are available in Informatica catalog.
Semantic source type: catalog
Catalog provider: informatica
Scope: object
Before You Begin
Complete the following:
- Complete Perform Prerequisites for Select AI and Grant Privileges for Select AI.
-
Ask your administrator to grant the
EXECUTEprivilege on theDBMS_AI_SEMpackage:GRANT EXECUTE ON DBMS_AI_SEM TO ADB_USER; - Create a credential that provides access to the Informatica endpoint. Authorization requirements depend on the catalog provider. See CREATE_CREDENTIAL Procedure and Prerequisites for Using Semantic Context with Select AI for more information.
- Grant
ADB_USERnetwork access to the host specified by the semantic source’ssource_endpoint. -
Identify the Informatica data source that contains the metadata for the database objects. This example uses:
Data source:
customer_source - Ensure that the Informatica data source contains metadata for sample tables, such as,
CUSTOMERandNATION. - Ensure that
ADB_USERcan access theCUSTOMERandNATIONtables. - Create an LLM credential for the Select AI profile and obtain the OCI Generative AI model name and compartment OCID.
Grant Network Access
Connect as an administrator and grant ADB_USER HTTP access to the Informatica host:
BEGIN
DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE(
host => 'mcp.dmp-us.informaticacloud.com',
ace => XS$ACE_TYPE(
privilege_list => XS$NAME_LIST('http'),
principal_name => 'ADB_USER',
principal_type => XS_ACL.PTYPE_DB
)
);
END;
/
Create the OAuth Credential for the Data Catalog Provider
Connect as the schema user or ADB_USER.
Create the credential only when it does not already exist. Replace the values with your own specific values:
BEGIN
DBMS_CLOUD.CREATE_CREDENTIAL(
credential_name => 'INFORMATICA_OAUTH_CRED',
params => JSON_OBJECT(
'oauth2' VALUE JSON_OBJECT(
'client_id' VALUE '<CLIENT_ID>',
'client_secret' VALUE '<CLIENT_SECRET>',
'grant_type' VALUE 'client_credentials',
'endpoint' VALUE '<INFORMATICA_OAUTH_TOKEN_ENDPOINT>'
)
)
);
END;
/
Create the Semantic Source
The following statement creates a cache-enabled catalog source that retrieves object-level context from Informatica. Replace the credential placeholder with the name of your Informatica credential and source_endpoint value with your specific value:
BEGIN
DBMS_AI_SEM.CREATE_SEMANTIC_SOURCE(
source_name => 'INFORMATICA_SEC_SOURCE',
type => 'catalog',
attributes => '{
"provider": "informatica",
"source_endpoint": "https://mcp.dmp-us.informaticacloud.com/mcp-servers/public/example",
"credential_name": "<INFORMATICA_CREDENTIAL>",
"data_source_name": "customer_source",
"scope": "object",
"cache": true,
"refresh_rate": 60
}'
);
END;
/
The source uses settings described in CREATE_SEMANTIC_SOURCE Procedure.
Create the Select AI Profile and Attach the Semantic Source
The following statement creates a Select AI profile and attaches the Informatica semantic source. Replace the credential, model, and compartment placeholders with values for your environment:
BEGIN
DBMS_CLOUD_AI.CREATE_PROFILE(
profile_name => 'INFORMATICA_SEC_PROFILE',
attributes => '{
"provider": "oci",
"credential_name": "<LLM_CREDENTIAL>",
"model": "<MODEL_NAME>",
"oci_compartment_id": "<COMPARTMENT_OCID>",
"object_list": [
{
"owner": "<OWNER>",
"name": "CUSTOMER"
},
{
"owner": "<OWNER>",
"name": "NATION"
}
],
"semantic_source": [
"INFORMATICA_SEC_SOURCE"
]
}'
);
END;
/
The object_list identifies the database objects that Select AI can consider. Attaching a semantic source does not add objects to the profile’s object list or override the requesting user’s database privileges.
Inspect and Run the Request
Set the profile active for the current session:
EXEC DBMS_CLOUD_AI.SET_PROFILE('INFORMATICA_SEC_PROFILE');
The following statement displays the normalized semantic context that Informatica provides for the request:
SELECT AI SHOWCONTEXT 'Show customer details';
The output can contain table and column descriptions for the accessible objects. For example:
Object semantic context
Source: ADB_USER.INFORMATICA_SEC_SOURCE
<OWNER>.CUSTOMER
- CUSTOMER: Contains detailed customer information such as customer ID,
name, contact details, and demographic data.
Select AI excludes context for any database object that the requesting user cannot access.
The following statement displays the prompt that Select AI constructs using database metadata and the retrieved semantic context:
SELECT AI SHOWPROMPT 'Show customer details';
Inspect the generated SQL without running it:
SELECT AI SHOWSQL 'Show customer details';
Run the request:
SELECT AI 'Show customer details';
Cleanup
Drop the profile before dropping the attached semantic sources.
BEGIN
DBMS_CLOUD_AI.DROP_PROFILE('INFORMATICA_SEC_PROFILE', TRUE);
DBMS_AI_SEM.DROP_SEMANTIC_SOURCE('INFORMATICA_SEC_SOURCE', TRUE);
END;
/
Cache Behavior
Select AI populates the cache when it retrieves object context that is not already cached. It updates cached context through scheduled or explicit refresh.
Cached context does not expire automatically. The refresh_rate value specifies the scheduled refresh interval. If a refresh fails, Select AI retains the existing cached context. Dropping the semantic source removes its cached context.
Example: Use a File from Object Storage as Semantic Source
A file semantic source processes a document, creates vector embeddings, and retrieves relevant content for each prompt. A file semantic source extracts, chunks, embeds, and indexes file content. Select AI retrieves relevant chunks as global semantic context. File sources support global scope.
This example uses a PDF containing Texas Commission on Environmental Quality acronyms and definitions available as an Object Storage document. It uses the PDF to interpret environmental terms such as:
| Term | Meaning |
|---|---|
VOC |
Volatile organic compound |
NOx |
Nitrogen oxides |
EI |
Emissions inventory |
AER |
Allowable emission rate |
tpy |
Tons per year |
Before You Begin
Review these prerequisites:
- Perform Prerequisites for Select AI
- Prerequisites for Using Semantic Context with Select AI
- Create an Object Storage credential named
OBJ_STORE_CRED, or replace that name with an existing credential that can read the object. See Examples of Using Select AI for related credential and profile examples. - Upload the PDF containing environmental emission data to an Object Storage location and obtain the URI.
- Select an embedding model that your OCI Generative AI account supports. See Profile Attributes.The embedding profile processes the source document. The SQL-generation profile answers the business question. These profiles serve different purposes.
- Provide the privileges and quota required to create the file source’s indexing resources.
- Configure network access to the Object Storage host when the database network configuration requires an ACL.
Create the Emissions Test Data
Create the table:
CREATE TABLE sem_pdf_ei (
site_name VARCHAR2(40),
yr NUMBER,
poll VARCHAR2(8),
ei_tpy NUMBER,
aer_tpy NUMBER
);
Insert the tested rows:
INSERT INTO sem_pdf_ei VALUES ('Alpha Works', 2025, 'VOC', 10, 28);
INSERT INTO sem_pdf_ei VALUES ('Beta Works', 2025, 'VOC', 20, 28);
INSERT INTO sem_pdf_ei VALUES ('Cedar Power', 2025, 'NOx', 44, 40);
INSERT INTO sem_pdf_ei VALUES ('Gulf Coatings', 2025, 'NOx', 11, 10);
COMMIT;
Create the Embedding Profile
Create the profile that Select AI uses to embed the file. Replace the embedding model, region, and compartment placeholders. Create the embedding profile in the same schema that owns the file semantic source.
BEGIN
DBMS_CLOUD_AI.CREATE_PROFILE(
profile_name => 'PDF_EMBEDDING_PROFILE',
attributes => '{
"provider": "oci",
"region": "<region>",
"credential_name": "OCI_CRED",
"embedding_model": "cohere.embed-v4.0",
"oci_compartment_id": "<oci_compartment_id>"
}'
);
END;
/
Create the File Semantic Source
Create the global file source:
BEGIN
DBMS_AI_SEM.CREATE_SEMANTIC_SOURCE(
source_name => 'PDF_SOURCE',
type => 'file',
attributes => '{
"scope": "global",
"source_endpoint":
"https://objectstorage.<region>.oraclecloud.com/n/<namespace>/b/<bucket>/o/semantic-context/tceq_glossary_and_descriptions.pdf",
"credential_name": "OBJ_STORE_CRED",
"profile_name": "PDF_EMBEDDING_PROFILE"
}'
);
END;
/
The file source supports only global scope. File sources do not use the object-context cache.
Create the Select AI Profile and Attach the Semantic Source
Create the Select AI profile:
BEGIN
DBMS_CLOUD_AI.CREATE_PROFILE(
profile_name => 'QUERY_PROFILE',
attributes => '{
"provider": "oci",
"region": "<region>",
"credential_name": "OCI_CRED",
"model": "<model_name>",
"temperature": 0,
"seed": 42,
"oci_compartment_id": "<oci_compartment_id>",
"object_list": [
{"owner": "ADB_USER", "name": "SEM_PDF_EI"}
],
"enforce_object_list": true,
"semantic_source": [
"PDF_SOURCE"
]
}'
);
END;
/
Verify File Ingestion
Query the pipeline that the file source creates:
SELECT pipeline_name,
status
FROM user_cloud_pipelines
WHERE pipeline_name = 'PDF_SOURCE$SEMVECIDX$VECPIPELINE';
Wait until the pipeline reports a usable status before testing retrieval.
Inspect and Run a VOC Request
Set the query profile:
EXEC DBMS_CLOUD_AI.SET_PROFILE('QUERY_PROFILE');
Inspect the retrieved PDF context:
SELECT AI SHOWCONTEXT
For 2025 show site name and emissions inventory tons per year
for poll code 'VOC' ordered by site name;
Inspect the SQL:
SELECT AI SHOWSQL
For 2025 show site name and emissions inventory tons per year
for poll code 'VOC' ordered by site name;
Run the request:
SELECT AI
For 2025 show site name and emissions inventory tons per year
for poll code 'VOC' ordered by site name;
Compare the result with the direct SQL query:
SELECT site_name,
ei_tpy AS reference_tpy
FROM sem_pdf_ei
WHERE yr = 2025
AND poll = 'VOC'
ORDER BY site_name;
The direct query returns:
SITE_NAME |
REFERENCE_TPY |
|---|---|
Alpha Works |
10 |
Beta Works |
20 |
Inspect and Run a Nitrogen Oxides Request
Inspect the retrieved definition and generated SQL:
SELECT AI SHOWCONTEXT
For 2025 show site name and reported tons per year for nitrogen oxides
where emissions inventory exceeds allowable emission rate
ordered by site name;
SELECT AI SHOWSQL
For 2025 show site name and reported tons per year for nitrogen oxides
where emissions inventory exceeds allowable emission rate
ordered by site name;
Run the request:
SELECT AI
For 2025 show site name and reported tons per year for nitrogen oxides
where emissions inventory exceeds allowable emission rate
ordered by site name;
Compare the result with the direct query:
SELECT site_name,
ei_tpy AS reference_tpy
FROM sem_pdf_ei
WHERE yr = 2025
AND poll = 'NOx'
AND ei_tpy > aer_tpy
ORDER BY site_name;
The direct query returns:
SITE_NAME |
REFERENCE_TPY |
|---|---|
Cedar Power |
44 |
Gulf Coatings |
11 |
Cleanup
Drop the profile before dropping the attached semantic sources.
BEGIN
DBMS_CLOUD_AI.DROP_PROFILE('QUERY_PROFILE', TRUE);
DBMS_AI_SEM.DROP_SEMANTIC_SOURCE('PDF_SOURCE', TRUE);
END;
/
Example: Use a Database Directory File as Semantic Source
If your administrator provides a database directory, place the semantic context document containing the business definition in that directory and grant ADB_USER the required access. Use DIRECTORY_NAME:file_name syntax and omit credential_name.
Create this alternative source instead of Object Storage file. Replace the directory name if your environment uses a different name.
BEGIN
DBMS_AI_SEM.CREATE_SEMANTIC_SOURCE(
source_name => 'DIRECTORY_SOURCE',
type => 'file',
attributes => '{
"scope": "global",
"source_endpoint": "SC_CONTEXT_DIR:tceq_glossary_and_descriptions.pdf",
"profile_name": "EMBED_PROFILE",
"refresh_rate": 60,
"match_limit": 5
}'
);
END;
/
Create the Select AI Profile and Attach the Semantic Source
Create the Select AI profile:
BEGIN
DBMS_CLOUD_AI.CREATE_PROFILE(
profile_name => 'QUERY_PROFILE',
attributes => '{
"provider": "oci",
"region": "<region>",
"credential_name": "OCI_CRED",
"model": "<model_name>",
"temperature": 0,
"seed": 42,
"oci_compartment_id": "<oci_compartment_id>",
"object_list": [
{"owner": "ADB_USER", "name": "SEM_PDF_EI"}
],
"enforce_object_list": true,
"semantic_source": [
"DIRECTORY_SOURCE"
]
}'
);
END;
/
Continue with the verification steps documented in Example: Use a File from Object Storage as Semantic Source.
Example: Use an MCP Semantic Source
An MCP semantic source calls MCP tools on an MCP-compatible server that return object-specific metadata and prompt-level business definitions. You configure the tool names, arguments, and response mappings that match your server.
This example uses the customer and country tables from the sample data setup. It preserves placeholders because every MCP server defines its own endpoint, authentication method, tool names, arguments, and response format.
This configuration assumes that your server exposes one tool for object descriptions and another tool for business definitions.
Before You Begin
Complete these prerequisites:
- Complete Before You Begin, Prepare the Sample Data, and Create the Profile Helper and Baseline Profile.
- Obtain the MCP endpoint URL.
- Create a database credential named
MCP_CREDusing the authentication method that your MCP endpoint supports. - Configure network access for your mcp endpoint. Grant
ADB_USERnetwork ACL access to the host in<mcp_endpoint>. - Configure the two tools in this example, or adapt the source attributes to tools that your server already exposes.
- Test the tools independently and confirm that their responses match the configured JSON paths.
Prepare an MCP server that provides:
- An object tool that accepts qualified object names.
- A global tool that accepts the user request, extracted keywords, and a result limit.
- Object responses that identify the database object for each metadata item.
- Global responses that return business terms and definitions.
This example does not deploy an MCP server.
Replace these placeholders:
| Placeholder | Supply this value |
|---|---|
<mcp_endpoint> |
HTTPS endpoint of the MCP server |
<mcp_credential> |
Credential that authenticates to the MCP server |
<object_tool_name> |
Tool that returns table and column metadata |
<global_tool_name> |
Tool that returns business terms |
$.results[*] and child paths |
JSON paths that match the actual MCP responses |
Expected Object-Tool Response
The example configuration expects the object tool to return a response shaped like this:
{
"results": [
{
"name": "CUSTOMER",
"description": "CUSTOMER.COUNTRY_ID joins NATION.COUNTRY_ID. MARKET_SEGMENT identifies the business sector. A negative ACCOUNT_BALANCE means that the customer owes money.",
"object": "ADB_USER.CUSTOMER"
},
{
"name": "NATION",
"description": "COUNTRY_NAME identifies the country for COUNTRY_ID.",
"object": "ADB_USER.NATION"
}
]
}
Expected Global-Tool Response
The example expects the global tool to return a response shaped like this:
{
"results": [
{
"name": "automobile sector",
"description": "Automobile sector means MARKET_SEGMENT = AUTOMOBILE."
},
{
"name": "owes money",
"description": "Owes money means ACCOUNT_BALANCE < 0."
}
]
}
Create the MCP Semantic Source
Create the MCP source after replacing the server-specific placeholders:
BEGIN
DBMS_AI_SEM.CREATE_SEMANTIC_SOURCE(
source_name => 'CUSTOMER_MCP_SOURCE',
type => 'mcp',
attributes => '{
"scope": "all",
"source_endpoint": "<mcp_endpoint>",
"credential_name": "<mcp_credential>",
"object_tool": {
"name": "<object_tool_name>",
"arguments": {
"tables": "${objects_qualified}"
},
"response_mapping": {
"items": "$.results[*]",
"term": "$.name",
"definition": "$.description",
"object": "$.object",
"object_pattern": "${owner}.${name}"
}
},
"global_tool": {
"name": "<global_tool_name>",
"arguments": {
"question": "${prompt}",
"keywords": "${prompt_keywords}",
"limit": "${match_limit}"
},
"response_mapping": {
"items": "$.results[*]",
"term": "$.name",
"definition": "$.description"
}
}
}'
);
END;
/
The items path must end with [*]. The object response mapping must include both object and object_pattern.
Create the Select AI Profile and Attach the MCP Semantic Source
Create the Select AI profile and attach the CUSTOMER_MCP_SOURCE MCP source:
BEGIN
DBMS_CLOUD_AI.CREATE_PROFILE(
profile_name => 'CUSTOMER_MCP_PROFILE',
attributes => '{
"provider": "oci",
"region": "<region>",
"credential_name": "OCI_CRED",
"model": "<model_name>",
"oci_compartment_id": "<oci_compartment_id>",
"object_list": [
{"owner": "ADB_USER", "name": "CUSTOMER"},
{"owner": "ADB_USER", "name": "NATION"}
],
"enforce_object_list": true,
"semantic_source": [
"CUSTOMER_MCP_SOURCE"
]
}'
);
END;
/
Inspect and Run the Request
Set the profile:
EXEC DBMS_CLOUD_AI.SET_PROFILE('CUSTOMER_MCP_PROFILE');
Inspect object and global MCP context:
SELECT AI SHOWCONTEXT
Which countries have automobile customers who owe money;
Inspect the generated SQL:
SELECT AI SHOWSQL
Which countries have automobile customers who owe money;
Run the request:
SELECT AI
Which countries have automobile customers who owe money;
The request should return INDIA.
Select AI substitutes template values at runtime. When ${match_limit} occupies the complete argument value, Select AI passes a number.
Select AI validates the tool configuration when you create or update the source. It checks tool availability when it calls the tool at runtime. A missing tool or tool error causes context retrieval to fail.
Cleanup
Drop profiles before dropping their attached semantic sources.
BEGIN
DBMS_CLOUD_AI.DROP_PROFILE('CUSTOMER_MCP_PROFILE', TRUE);
DBMS_AI_SEM.DROP_SEMANTIC_SOURCE('CUSTOMER_MCP_SOURCE', TRUE);
END;
/
Example: Use Multiple Semantic Sources with Select AI
You can attach multiple semantic sources to one Select AI profile. Select AI retrieves applicable context from each enabled source and combines the context before it generates SQL.
In this example:
- An Alation catalog source supplies metadata for the
CUSTOMERandNATIONtables. - An MCP source supplies the business meanings of automobile customer and owes money.
- Both sources supplement the same natural-language request.
Before You Begin
Complete the following requirements:
- Complete Prerequisites for Using Semantic Context with Select AI.
- Create the sample tables and data described in Prepare the Sample Data and Callback Functions for Custom Semantic Source.
- Create the Alation source described in Example: Use a Catalog Semantic Source.
- Create the MCP source as described in Example: Use an MCP Semantic Source.
- Configure both sources so that
ADB_USERcan use them. - Configure network ACL access to the Alation and MCP
source_endpointhosts. - Create the LLM credential and external-source credentials.
- Replace the profile placeholders with values for your environment.
This example uses the following sources:
| Source | Type | Context supplied |
|---|---|---|
CUSTOMER_ALATION_SOURCE |
Catalog | Table, column, and relationship metadata for ADB_USER.CUSTOMER and ADB_USER.NATION |
CUSTOMER_MCP_SOURCE |
MCP | Business definitions for automobile customer and owes money |
{=”Semantic sources attached to the multiple-source Select AI profile.”}
This example uses the NATION and CUSTOMER tables created in Prepare Sample Data. The sample data includes automobile customers with positive and negative account balances, allowing the generated SQL to demonstrate the meanings supplied by the semantic sources.
Configure Alation with metadata that describes:
ADB_USER.CUSTOMERADB_USER.NATION- The join between
CUSTOMER.COUNTRY_IDandNATION.COUNTRY_ID CUSTOMER.MARKET_SEGMENTCUSTOMER.ACCOUNT_BALANCENATION.COUNTRY_NAME
Configure the MCP source to return these business definitions:
| Term | Definition |
|---|---|
| Automobile customer | A customer whose MARKET_SEGMENT value equals AUTOMOBILE. |
| Owes money | A customer owes money when ACCOUNT_BALANCE is less than zero. |
{=”Business definitions returned by the MCP source.”}
For a simple separation of responsibilities, configure the Alation source for object context and the MCP source for global context. This approach reduces the chance that both sources return competing definitions for the same term.
Verify the Semantic Sources
Verify that both sources exist and have ENABLED status:
SELECT source_name,
source_type,
status
FROM user_ai_semantic_sources
WHERE source_name IN (
'CUSTOMER_ALATION_SOURCE',
'CUSTOMER_MCP_SOURCE'
)
ORDER BY source_name;
Verify their configured attributes:
SELECT source_name,
attribute_name,
attribute_value
FROM user_ai_semantic_source_attributes
WHERE source_name IN (
'CUSTOMER_ALATION_SOURCE',
'CUSTOMER_MCP_SOURCE'
)
ORDER BY source_name,
attribute_name;
Create a Profile with Multiple Semantic Sources
Create a Select AI profile and attach both semantic sources through the semantic_source array:
BEGIN
DBMS_CLOUD_AI.CREATE_PROFILE(
profile_name => 'CUSTOMER_MULTI_SOURCE_PROFILE',
attributes => '{
"provider": "oci",
"region": "<region>",
"credential_name": "<llm_credential>",
"model": "<model_name>",
"oci_compartment_id": "<compartment_id>",
"object_list": [
{
"owner": "ADB_USER",
"name": "CUSTOMER"
},
{
"owner": "ADB_USER",
"name": "NATION"
}
],
"enforce_object_list": true,
"semantic_source": [
"CUSTOMER_ALATION_SOURCE",
"CUSTOMER_MCP_SOURCE"
]
}'
);
END;
/
The semantic_source array attaches both sources to the profile. It does not establish precedence between them.
Verify the Profile Configuration
Verify that the profile references both sources:
SELECT profile_name,
attribute_name,
attribute_value
FROM user_cloud_ai_profile_attributes
WHERE profile_name = 'CUSTOMER_MULTI_SOURCE_PROFILE'
AND attribute_name = 'semantic_source';
The ATTRIBUTE_VALUE column should contain both source names.
Set the Profile
Set the multiple-source profile for the current session:
EXEC DBMS_CLOUD_AI.SET_PROFILE('CUSTOMER_MULTI_SOURCE_PROFILE');
Inspect the Combined Semantic Context
Use the SHOWCONTEXT action to inspect the context retrieved from both sources:
SELECT AI SHOWCONTEXT
Which countries have automobile customers who owe money;
The result should include context from both sources:
- The Alation source should describe the tables, columns, and join.
- The MCP source should explain automobile customer and owes money.
The exact output can vary with the metadata stored in Alation and the responses returned by the MCP tools.
Inspect the Combined Prompt
Use the SHOWPROMPT action to verify that Select AI adds the combined semantic context to the provider prompt:
SELECT AI SHOWPROMPT
Which countries have automobile customers who owe money;
SHOWPROMPT can include provider-specific request formatting in addition to the database metadata and semantic context.
Inspect the Generated SQL
Use the SHOWSQL action to inspect the generated SQL:
SELECT AI SHOWSQL
Which countries have automobile customers who owe money;
The generated SQL should:
- Join
CUSTOMER.COUNTRY_IDtoNATION.COUNTRY_ID. - Filter
CUSTOMER.MARKET_SEGMENTforAUTOMOBILE. - Filter
CUSTOMER.ACCOUNT_BALANCEfor values less than zero. - Return the applicable country name.
Run the Request
Run the natural-language request:
SELECT AI
Which countries have automobile customers who owe money;
The request should return:
COUNTRY_NAME
--------------
INDIA
{=”Expected Select AI result when both semantic sources contribute context.”}
Semantic Source Ordering and Conflicting Context
Note: The order of source names in the semantic_source array does not define source precedence. The first source does not override a later source, and a later source does not override an earlier source.
Select AI retrieves context from every applicable enabled source and combines the retrieved context. Use the array to identify the sources that the profile uses, not to establish a conflict-resolution order.
If multiple sources return conflicting definitions for the same term, Select AI can include both definitions in the combined context. The array order does not provide a deterministic winner for that conflict.
To avoid ambiguous SQL generation:
- Assign distinct responsibilities to the sources when possible. For example, use Alation for object metadata and MCP for global business terms.
- Maintain consistent definitions when multiple sources describe the same term.
- Use
SHOWCONTEXTto review the context that each source contributes. - Update, disable, or detach a source when it returns obsolete or conflicting context.
- Do not rely on rearranging source names in the array to resolve a conflict.
Cleanup
Drop the profile when not needed:
BEGIN
DBMS_CLOUD_AI.DROP_PROFILE(
profile_name => 'CUSTOMER_MULTI_SOURCE_PROFILE',
force => TRUE
);
END;
/
Example: Share a Semantic Source
A semantic source owner can grant a database user or role access to a semantic source. The grantee can attach the shared source to a Select AI profile and use its context without creating another semantic source.
Authorized users can reuse cached object-level context from a shared, cache-enabled Catalog or MCP source, subject to semantic-source access and database-object visibility checks. Cached context does not expire automatically; Select AI populates it on a cache miss and updates it through scheduled or explicit refresh. The refresh_rate attribute specifies the scheduled refresh interval, not an expiration time. Dropping the semantic source removes its cached context. The source owner controls cache refresh and purge operations.
This example uses:
ADB_USERas the semantic source owner.REPORTING_USERas the grantee.- The
CUSTOMERandNATIONtables from Prepare the Sample Data and Callback Functions for Custom Semantic Source. - The
CUSTOMER_ALATION_SOURCEsource from Example: Use a Catalog Semantic Source. - The same natural-language request that the custom, catalog, MCP, and multiple-source examples use.
Before You Begin
Complete the following requirements:
- Complete Prerequisites for Using Semantic Context with Select AI.
- Create the tables and rows described in Prepare the Sample Data and Callback Functions for Custom Semantic Source.
- Create
CUSTOMER_ALATION_SOURCEas described in Example: Use a Catalog Semantic Source. - Enable object-context caching for the semantic source if users need to reuse cached context. See Semantic-Context Caching.
- Grant
REPORTING_USERthe privileges required to use Select AI and query the business tables. - Create an LLM credential for
REPORTING_USER. - Ensure that
REPORTING_USERcan resolve any provider credential that the external semantic source requires. - Configure network access for the applicable LLM and semantic-source endpoints.
The example uses the following database users:
| User | Responsibility |
|---|---|
ADB_USER |
Owns the sample tables and CUSTOMER_ALATION_SOURCE. |
REPORTING_USER |
Queries the tables and uses the shared source through its own Select AI profile. |
Grant Access to the Business Tables
Run the following statements as ADB_USER or another user that can grant access to the tables.
Grant REPORTING_USER access to the customer table:
GRANT SELECT ON customer TO reporting_user;
Grant REPORTING_USER access to the country table:
GRANT SELECT ON nation TO reporting_user;
Access to a semantic source does not grant access to the database objects that the source describes. REPORTING_USER must hold the applicable object privileges.
Grant Access to the Semantic Source
Run the following block as ADB_USER.
Grant REPORTING_USER access to CUSTOMER_ALATION_SOURCE:
BEGIN
DBMS_AI_SEM.GRANT_SEMANTIC_SOURCE_ACCESS(
source_name => 'CUSTOMER_ALATION_SOURCE',
user_or_role_name => 'REPORTING_USER'
);
END;
/
See GRANT_SEMANTIC_SOURCE_ACCESS Procedure for the complete syntax and usage information.
The grant allows REPORTING_USER to attach and use the source. It does not allow REPORTING_USER to:
- Update the source configuration.
- Enable or disable the source.
- Refresh or purge its cached context.
- Grant the source to another user or role.
- Revoke another user’s access.
- Drop the source.
ADB_USER retains control of these operations.
Verify Access to the Shared Source
Connect as REPORTING_USER.
Query the semantic-source views to verify that the source appears as an accessible source:
SELECT owner,
source_name,
source_type,
status
FROM all_ai_semantic_sources
WHERE owner = 'ADB_USER'
AND source_name = 'CUSTOMER_ALATION_SOURCE';
The query should return the enabled source owned by ADB_USER.
See DBMS_AI_SEMANTIC Views for information about the USER_, ALL_, and DBA_ semantic-source views.
Create a Profile That Uses the Shared Source
REPORTING_USER must create and use its own Select AI profile. The profile must reference the shared source with its qualified name:
ADB_USER.CUSTOMER_ALATION_SOURCE
Create the profile as REPORTING_USER:
BEGIN
DBMS_CLOUD_AI.CREATE_PROFILE(
profile_name => 'SHARED_CUSTOMER_PROFILE',
attributes => '{
"provider": "oci",
"region": "<region>",
"credential_name": "OCI_CRED",
"model": "<model_name>",
"oci_compartment_id": "<compartment_id>",
"object_list": [
{
"owner": "ADB_USER",
"name": "CUSTOMER"
},
{
"owner": "ADB_USER",
"name": "NATION"
}
],
"enforce_object_list": true,
"semantic_source": [
"ADB_USER.CUSTOMER_ALATION_SOURCE"
]
}'
);
END;
/
Replace the profile placeholders with values from the REPORTING_USER environment.
The profile uses:
- The
OCI_CREDcredential owned or otherwise resolvable byREPORTING_USER. - Business tables owned by
ADB_USER. - A semantic source owned by
ADB_USER. - External provider configuration controlled by the semantic source owner.
Verify the Profile Configuration
Run the following query as REPORTING_USER to verify the qualified semantic-source reference:
SELECT profile_name,
attribute_name,
attribute_value
FROM user_cloud_ai_profile_attributes
WHERE profile_name = 'SHARED_CUSTOMER_PROFILE'
AND attribute_name = 'semantic_source';
The ATTRIBUTE_VALUE column should include:
["ADB_USER.CUSTOMER_ALATION_SOURCE"]
Set the Shared-Source Profile
Set the profile for the current session:
EXEC DBMS_CLOUD_AI.SET_PROFILE('SHARED_CUSTOMER_PROFILE');
Inspect the Shared Semantic Context
Use the SHOWCONTEXT action to verify that REPORTING_USER can retrieve context from the shared source:
SELECT AI SHOWCONTEXT
'Which countries have automobile customers who owe money'
FROM dual;
The result should include applicable descriptions for:
ADB_USER.CUSTOMERADB_USER.NATION- The relationship between
CUSTOMER.COUNTRY_IDandNATION.COUNTRY_ID CUSTOMER.MARKET_SEGMENTCUSTOMER.ACCOUNT_BALANCENATION.COUNTRY_NAME
The output depends on the metadata stored in Alation.
Inspect the Combined Prompt
Use the SHOWPROMPT action to verify that Select AI adds the shared semantic context to the LLM request:
SELECT AI SHOWPROMPT
'Which countries have automobile customers who owe money';
SHOWPROMPT can include provider-specific request formatting in addition to database metadata and semantic context.
Inspect the Generated SQL
Use the SHOWSQL action to inspect the generated SQL:
SELECT AI SHOWSQL
'Which countries have automobile customers who owe money';
The generated SQL should:
- Query
ADB_USER.CUSTOMERandADB_USER.NATION. - Join the tables through
COUNTRY_ID. - Filter
MARKET_SEGMENTforAUTOMOBILE. - Filter
ACCOUNT_BALANCEfor values less than zero. - Return the applicable country name.
Run the Request
Run the natural-language request:
SELECT AI
'Which countries have automobile customers who owe money';
The request should return:
COUNTRY_NAME
--------------
INDIA
Cleanup
Drop the profile before dropping the attached semantic sources.
BEGIN
DBMS_CLOUD_AI.DROP_PROFILE('SHARED_CUSTOMER_PROFILE', TRUE);
DBMS_AI_SEM.DROP_SEMANTIC_SOURCE('CUSTOMER_ALATION_SOURCE', TRUE);
END;
/