Use Semantic Context with Select AI
Select AI uses semantic context from external metadata sources to interpret business terminology when generating SQL from natural language or text-to-SQL. You can configure semantic sources to provide business definitions, metric calculations, table and column descriptions, and relationships that supplement database metadata.
For example, your organization can define an at-risk customer as a high-value customer who has not placed an order in the last 90 days and has an open support escalation. When you attach a source containing this definition to an AI profile, Select AI can use the definition to generate SQL for a request such as “Show me at-risk customers.”
About Semantic Context
Select AI augments natural-language prompts with metadata before sending the prompts to a large language model (LLM) for SQL generation. Semantic context supplements these inputs.
Existing metadata can include table names, column names and data types, table and column comments, constraints, annotations available with Oracle AI Database 26ai, and custom profile instructions. Semantic context adds business meaning to that metadata.
Select AI uses semantic context to interpret business terms when generating SQL. Database metadata describes the structure of your data. Semantic context supplies the business definitions needed to interpret a request.
For example, a numeric spending column does not establish which customers your organization considers high-value. A business definition supplies that meaning.
Semantic Sources and Semantic Context
A semantic source provides the configuration that Select AI uses to access business information.
Semantic context is the information that the source returns.
Creating a source stores a configuration that Select AI uses to retrieve business context; it does not retrieve the configuration itself. Semantic context enriches only the database objects already available to the active AI profile and does not override the requesting user’s privileges on those objects.
The following are the supported semantic sources:
| Source type | Purpose | Example |
|---|---|---|
catalog |
Retrieves metadata from a supported catalog provider. | A catalog source returns table descriptions and business glossary definitions. |
custom |
Calls customer-provided PL/SQL functions. | A custom callback returns definitions that your application maintains. |
file |
Retrieves relevant context from a configured file. | A file source returns relevant business information from a configured file. |
mcp |
Calls configured tools on an MCP-compatible server. | An MCP source calls configured tools to retrieve business information. |
A source can contribute object context, global context, or all:
- Object context describes specific database objects that Select AI identifies for a request.
- Global context provides business terms and definitions related to the natural-language request.
- All context combines object and global context.
How Semantic Context Interacts with Select AI
Select AI processes semantic context as part of its existing prompt and SQL-generation flow:
-
Select AI reads the active AI profile and identifies its attached semantic sources.
-
Select AI identifies candidate database objects from the profile’s object list or automated object-selection index.
-
Select AI verifies that the requesting user can access those objects.
-
Select AI obtains object and global context according to each source’s configured scope.
-
Select AI normalizes the context into terms, definitions, and associated database objects.
-
Select AI combines the semantic context with database metadata, comments, annotations, and profile instructions.
-
The configured language model uses the combined information to generate SQL.
Semantic context does not add database objects to the active profile and does not bypass database privileges.
Interaction with Select AI Capabilities
| Select AI capability | Interaction with semantic context |
|---|---|
object_list |
Select AI uses information only about the database objects listed in the profile’s object list. |
| Automated object selection | Select AI adds useful information about database objects while building its index. When you ask a question, it uses the objects chosen from that index. |
enforce_object_list |
Semantic context does not add objects to the profile’s object list. |
| Table and column comments | Semantic context adds to existing table and column descriptions. It does not replace them. |
role and additional_instructions |
Select AI follows the profile’s existing instructions as well as the semantic context. |
| Multiple semantic sources | Select AI combines information from every enabled semantic source connected to the active profile. The order of source names in the semantic_source array does not define precedence. If two sources provide different definitions for the same term, both definitions can appear in the prompt. If an enabled source is unavailable or returns an error, semantic-context retrieval fails and the Select AI request fails. For source-specific request and response requirements, see Semantic Source Attributes. |
SHOWCONTEXT |
Select AI shows the normalized semantic context included in the configured model prompt for the request. |
SHOWPROMPT |
Select AI shows the complete prompt it used, including semantic information, database details, and profile instructions. |
SHOWSQL |
Select AI creates SQL after adding the relevant semantic information to the prompt. |
SELECT AI |
Select AI creates and runs the SQL according to the configured settings and profile. |
Semantic Source Scope
The scope attribute determines which type of context a semantic source contributes. See Common Attributes for more details.
| Supported Scope | Description | Includes |
|---|---|---|
object |
Select AI requests context for database objects selected for the natural-language request. Select AI filters inaccessible objects before checking the cache or sending object identifiers to an external semantic provider. | Table descriptions Column descriptions Metric definitions associated with a table, including the business meaning and calculation of a measurable value Object-specific business rules Business names for physical database objects |
global |
Select AI requests business context related to the user’s natural-language request. Select AI obtains global context for each request and does not cache global context. | Glossary terms Business definitions Domain terminology General business rules Metric definitions that do not belong to a single database object Note: File semantic sources support only global scope. They do not support object or all scope. For the scopes supported by each source type, see Common Attributes. |
all |
A source contributes both object and global context. The source must provide the configuration required for both paths. A source can return an empty result for either path; a valid empty result does not cause the Select AI request to fail. | Custom source: object_callback_func and global_callback_funcMCP source: object_tool and global_toolCatalog source: attributes required for object retrieval, including data_source_name |
See Also:
Prerequisites for Using Semantic Context with Select AI
Complete the following prerequisites before using semantic context with Select AI:
- Perform Prerequisites for Select AI
- Grant Privileges for Select AI
-
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.For example, Alation, a data catalog provider, uses OAuth 2.0 authentication. The following example creates an Alation credential by using the client credentials grant type. Replace the endpoint with the OAuth token endpoint for your Alation instance. See Authentication into Alation APIs, Service User Authorization, and Obtain Access JSON Web Token in the Alation documentation.
BEGIN DBMS_CLOUD.CREATE_CREDENTIAL( credential_name => 'ALATION_OAUTH_CRED', params => JSON_OBJECT( 'oauth2' VALUE JSON_OBJECT( 'client_id' VALUE :<sem_alation_client_id>, 'client_secret' VALUE :<sem_alation_client_secret>, 'grant_type' VALUE 'client_credentials', 'scope' VALUE 'all', 'endpoint' VALUE 'https://<example>.alationcloud.com/oauth/v2/token/' ) ) ); END; / - Your administrator must grant access to the semantic source package:</code></pre>sql
GRANT EXECUTE ON DBMS_AI_SEM TO ADB_USER;
- Configure network access to the host specified in `source_endpoint` of the `DBMS_AI_SEM.CREATE_SEMANTIC_SOURCE` procedure. See [CREATE_SEMANTIC_SOURCE Procedure](dbms-ai-sem-package.html#GUID-AA682461-745B-4B0C-BA94-1975B24381A5) for more details. Catalog and MCP sources require network ACL access to their configured endpoints. For a file source that reads from Object Storage, configure access to the applicable Object Storage endpoint. Configure network access to the LLM and embedding provider separately. For example, the following statement grants `ADB_USER` access to an Alation endpoint. Specify only the endpoint host in the `host` parameter.sql 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; / ``` Replace
org.alation.comwith thehostfrom the catalog or MCPsource_endpoint. See Grant Privileges for Select AI for more information about configuring network ACL access. - For custom callback functions, your administrator or the function owner must grant the
EXECUTEprivilege to the user who uses Select AI and runs the callback functions.
How to Use Semantic Context with Select AI
The following steps guide you to create and use semantic context with Select AI:
- Create a semantic source. See CREATE_SEMANTIC_SOURCE Procedure for more information.
- Attach the semantic sources to a Select AI profile. See
semantic_sourcein Profile Attributes for more information. - Set the profile for the session. See SET_PROFILE Procedure for more information.
- Inspect the context used for a prompt using
showcontextas a Select AI action. See Use AI Keyword to Enter Prompts and Example: Select AI Actions for more information. - Use natural language prompts to query the data.
- (Optional) Query
DBMS_AI_SEMANTIC Viewsfor information about theUSER_,ALL_, andDBA_semantic-source views. See DBMS_AI_SEMANTIC Views for more information.
For an end-to-end example covering supported semantic sources, see Example: Use Semantic Context with Select AI.
Use Cases for Semantic Context
Use semantic context to supplement database metadata with business information when generating SQL from natural-language questions. The following use cases illustrate how you can apply semantic context with Select AI.
-
Query data using business definitions: Provide definitions for business terms that users include in their questions.
For example, define an at-risk customer as a customer whose lifetime spend exceeds 50,000 USD, who has not placed an order in the last 90 days, and who has an open support escalation. Select AI can use this definition to interpret a request such as “List at-risk customers by region.”
-
Use metadata maintained in a data catalog: Connect a supported catalog, such as Alation or Informatica, to use existing business glossary terms and object descriptions.
For example, attach a catalog source that describes customer tables, explains spending columns, and defines customer classifications. Select AI retrieves the applicable context and combines it with database metadata for SQL generation.
-
Retrieve business context from application sources: Configure custom PL/SQL callbacks or MCP tools to retrieve definitions from customer-managed sources.
For example, an application can maintain metric definitions in its own tables. A callback retrieves those definitions and returns them as semantic context, allowing Select AI to use the application’s business terminology.
-
Use business reference files: Configure a file source to make glossary entries, metric definitions, or business rules available as global context.
For example, a sales reference file can explain customer classifications and reporting terminology. Select AI retrieves relevant file content to help interpret a sales question.
-
Combine object descriptions and business rules: Attach multiple semantic sources to an AI profile when the required information resides in different systems.
For example, use a catalog source for table and column descriptions and a custom source for business definitions. The profile references both sources through its semantic_source array.
Object context describes selected database objects. Global context supplies business meaning that can apply across those objects.
-
Support automated object discovery: Use object-level semantic context to enrich database object metadata during automated object-list indexing.
For example, a business description can associate a table with terminology that users include in their questions, helping Select AI identify relevant objects.
Refreshing cached semantic context does not automatically rebuild the automated object-list index.
-
Validate and troubleshoot context: Use
SHOWCONTEXTto inspect the definitions retrieved for a question. Review the generated SQL withSHOWSQLand compare the results with known business examples. Query semantic-source views to inspect source configurations and attributes. This helps you investigate missing definitions, incorrect source associations, or unexpected context.
Benefits of Using Semantic Context
Semantic context provides the following benefits when you use Select AI:
- Align SQL generation with business terminology: Supply definitions, metric calculations, and relationships that help Select AI interpret questions according to your organization’s intended meaning.
- Reuse existing business knowledge: Retrieve information already maintained in catalogs, reference files, applications, and other configured sources instead of reproducing the same definitions in individual prompts.
- Select sources that match your environment: Use supported catalog integrations, files, custom callbacks, MCP services, or ontology integrations according to where your organization maintains its knowledge.
- Reuse source configurations across profiles: Attach a source to multiple AI profiles. The source owner can grant other users or roles access while retaining control of the source configuration.
- Inspect context used for SQL generation: Use
SHOWCONTEXTto verify the retrieved definitions before reviewing generated SQL or investigating query results. - Adopt semantic context incrementally: Add sources to profiles that require additional business information. Profiles without semantic sources continue to use their existing metadata and instructions. Semantic context supplements database metadata and profile instructions. It does not expand database privileges or override object-list restrictions.