CREATE CONTEXT
Creates a new SQL-GPT context. The context can contain one or more base tables, a set of sample question/answer pairs, and a set of rules for the table to aid in generating appropriate SQL. While the tables, samples, and rules clauses are all optional, a context must contain at least one clause of any kind to be considered valid.CREATE CONTEXT Syntax
Parameters
OR REPLACE
OR REPLACE
Any existing context reference with the same name will be dropped before creating this
one
TEMP
TEMP
The context will be a temporary one; which means it will not be persisted (if the
database is restarted, the context will be removed) and, if not continually accessed
within the specified TTL, will be removed.
<schema name>
<schema name>
Name of the schema containing the context
<context name>
<context name>
Name of the context
<table definition clause>
<table definition clause>
Optional clause containing the definitions of all tables to be used within the context
<sample definition clause>
<sample definition clause>
Optional clause containing sample question/answer pairs that can help SQL-GPT
understand the relationships between natural language and the tables within the context
<rule definition clause>
<rule definition clause>
Optional clause containing global rules SQL-GPT should take into account when generating
SQL from the tables within the context
WITH OPTIONS
WITH OPTIONS
Optional indicator that a comma-delimited list of option/value assignments will follow.
The following options are available:
| Option | Description |
|---|---|
ttl | Time-to-live, in minutes, for the context. If the context is not accessed for this amount of time, it will be automatically removed from the database. If TEMP is not specified, this option will be ignored. |
Table Definition Clause
The table definition clause provides information about a single table to SQL-GPT. All parameters are optional except for the table name. The table definition clause itself is also optional.Kinetica will pass the all columns of the table to SQL-GPT
regardless of whether they are named in the
COMMENTS or RULES
sections. To avoid consuming unnecessary space in the SQL-GPT context with
the unused columns, create a view with descriptive column names containing
only the columns needed for generating SQL.Table Definition Clause Syntax
Parameters
TABLE
TABLE
Specifier for the mandatory table definition table name
<schema name>
<schema name>
Name of the schema containing the table to include in the
context
<table name>
<table name>
Name of the table to include in the context
COMMENT
COMMENT
Specifier for an optional table comment
<table comment>
<table comment>
Note about the table that can give SLQ-GPT information about its use and the data it holds
COMMENTS
COMMENTS
Specifier for an optional comma-separated list of column name & comment pairs
<column name>
<column name>
Name of a column in the given table
<column comment>
<column comment>
Note about the column that can give SQL-GPT information about its use and the specific data
it holds
RULES
RULES
Specifier for an optional comma-separated list of rules for SQL-GPT to use in employing this
table to generate SQL
<table rule>
<table rule>
Rule for SQL-GPT to use in employing this table to generate SQL; e.g., which columns should
be considered (or not considered) when generating SQL using the table
Sample Definition Clause
A sample definition contains a set of question & answer pairs used to train SQL-GPT for generating SQL. Few (if any) samples should be required to customize SQL-GPT for a use case. The sample definition clause is optional.A sample definition should reference tables that are included
in table definitions within either its own context or a separate
context that is passed along with it into a
GENERATE SQL or EXECUTE_AI_QUERY
command. This ensures that SQL-GPT has a proper definition (and
understanding) of the tables and columns referenced in each sample query.
Sample Definition Clause Syntax
Parameters
SAMPLES
SAMPLES
Sample definition specifier keyword
<question>
<question>
Natural-language question that will be answered by the corresponding
<SQL answer> query<SQL answer>
<SQL answer>
SQL query that answers
<question> using the tables contained within the contextQuoted constants within the query will need to be escaped as per standard SQL
convention; e.g.,
'lamp' in the following:Rule Definition Clause
A rule definition contains a set of global rules that SQL-GPT should use in employing the various tables named in the context to generate SQL. By convention, rules that apply to a specific table belong in theRULES section
of the table definition,
while rules that apply across tables or independently from any tables belong
here. The rule definition clause is optional.
A rule definition should reference tables that are included
in table definitions within either its own context or a separate
context that is passed along with it into a
GENERATE SQL or EXECUTE_AI_QUERY
command. This ensures that SQL-GPT has a proper definition (and
understanding) of any tables and columns referenced in each rule.
Rule Definition Clause Syntax
Parameters
RULES
RULES
Global rule definition specifier keyword
<global rule>
<global rule>
Global rule for SQL-GPT to use in employing multiple tables to generate SQL (joins, etc.) or
when referencing database features that are independent of any table (functions, etc.)
Example
The following example creates a SQL-GPT context with the following criteria:-
Contains one table,
atc_current_position, with:- a description
- 4 column comments
- 1 rule suggesting avoidance of one of the columns
-
Contains one table,
atc_points, with no extra definitions -
Contains one table,
airport_positions, with:- a description
- 2 column comments
- Contains 2 sample questions and their corresponding queries
-
Contains 1 global rule suggesting how the
atc_current_position&atc_pointstables should be joined together
CREATE CONTEXT Example
ALTER CONTEXT
Alters the configuration of a SQL-GPT context. Multiple context entries can be added & removed in one command. The general form is:ALTER CONTEXT Syntax
Add Context Table
A context table can be added to a SQL-GPT context.Add Context Table Syntax
<table definition clause>.
Examples
To add theexample.atc_country table to the
example.atc_ctx SQL-GPT context:
Add Context Table Example
Drop Context Table
A context table can be removed from a SQL-GPT context.Drop Context Table Syntax
Examples
To drop theexample.atc_country table from the
example.atc_ctx SQL-GPT context:
Drop Context Table Example
Add Context Samples
Context samples can be added to a SQL-GPT context that has not been configured with any. To add samples to a context already configured with one or more, first drop all existing samples, and then add the new and any previous samples all at once.Add Context Samples Syntax
<sample definition clause>.
Examples
To add a sample query for finding JFK airport’s location to theexample.atc_ctx SQL-GPT context:
Add Context Samples Example
Drop Context Samples
Context samples can be removed from a SQL-GPT context that has been configured with one or more.Drop Context Samples Syntax
Examples
To drop all context samples from theexample.atc_ctx SQL-GPT context:
Drop Context Samples Example
Add Context Rules
Context rules can be added to a SQL-GPT context that has not been configured with any. To add rules to a context already configured with one or more, first drop all existing rules, and then add the new and any previous rules all at once.Add Context Rules Syntax
<rule definition clause>.
Examples
To add a rule for joining theexample.airport_positions table with the
atc_current_position table to the example.atc_ctx SQL-GPT context:
Add Context Rules Example
Drop Context Rules
Context rules can be removed from a SQL-GPT context that has been configured with one or more.Drop Context Rules Syntax
Examples
To drop all context rules from theexample.atc_ctx SQL-GPT context:
Drop Context Rules Example
DROP CONTEXT
Removes an existing SQL-GPT context.DROP CONTEXT Syntax
Examples
To remove theexample.atc_ctx SQL-GPT context:
DROP CONTEXT Example
SHOW CONTEXT
Outputs the DDL statement required to reconstruct the given SQL-GPT context.SHOW CONTEXT Syntax
The response to
SHOW CONTEXT is a single-column result set
with the DDL statement as the value in the CONTEXT_DEFINITION column.Parameters
<schema name>
<schema name>
Name of the schema containing the SQL-GPT context to show
<context name>
<context name>
Name of the existing SQL-GPT context for which the DDL will be output; use
* instead of
schema/context name to output the DDL of all contextsExamples
To output the DDL for a SQL-GPT context,example.atc_ctx:
SHOW CONTEXT Example
SHOW CONTEXT (All Contexts) Example
DESCRIBE CONTEXT
Outputs the configuration of an existing SQL-GPT context.DESCRIBE CONTEXT Syntax
Parameters
<schema name>
<schema name>
Name of the schema containing the SQL-GPT context to describe
<context name>
<context name>
Name of the existing SQL-GPT context for which the configuration will be output; use
*
instead of schema/context name to output the configuration of all contextsResponse
The response toDESCRIBE CONTEXT is a seven-column result set:
| Output Column | Description |
|---|---|
CONTEXT_NAME | Name of the SQL-GPT context |
OBJECT_TYPE | Type of the context entity being described within the context |
OBJECT_NAME | For a table entity type, the name of the table |
OBJECT_DESCRIPTION | For a table entity type, the table comment |
OBJECT_RULES | For a table entity type, rules associated with the table |
OBJECT_COMMENTS | For a table entity type, the table’s column comments |
OBJECT_SAMPLES | For a samples entity type, the list of question/answer pairs |
Examples
To show the configuration for a SQL-GPT context,example.atc_ctx:
DESCRIBE CONTEXT Example
DESCRIBE CONTEXT (All Contexts) Example
GENERATE SQL
Creates a SQL query equivalent of the given natural-language question using the specified SQL-GPT context.GENERATE SQL Syntax
Parameters
<question>
<question>
Natural-language question for which an equivalent SQL query will be generated
<schema name>
<schema name>
Name of the schema containing the context to use in generating
the query
WITH OPTIONS
WITH OPTIONS
Optional indicator that a comma-delimited list of SQL generation option/value assignments will
follow.See SQL Generation Options for the complete list of options.
SQL Generation Options
The following options can be specified to modify the way SQL queries are generated.ai_api_provider
ai_api_provider
Name of an LLM service to use other than the default one; the default,
sqlgpt, uses the
Kinetica SQLGPT.io service.ai_api_url
ai_api_url
URL of an LLM service to use other than the default one.
context_name
context_name
Name of the SQL-GPT context to use as a basis for generating SQL queries; should be of the
form
[<schema name>.]<context name>.context_names
context_names
Comma-separated list of names of SQL-GPT contexts to use as a basis for generating SQL
queries; each should be of the form
[<schema name>.]<context name>, and the entire list
should be single-quoted.For example:use_rag
use_rag
Whether to use retrieval-augmented generation (RAG) facilities
with the given SQL-GPT contexts when processing this request.
SQL Generation Examples
To generate the SQL equivalent query to a given question using theexample.atc_ctx SQL-GPT context:
GENERATE SQL Example
nyctaxi_ctx & flights_ctx SQL-GPT contexts with SQL RAG:
GENERATE SQL with RAG Example
GENERATE TOKENS
Counts the number of tokens that would be used in generating the SQL in an equivalent GENERATE SQL call. This is, effectively, the number of combined tokens in the given contexts, taking into account whether RAG is being used.GENERATE TOKENS Syntax
Parameters
<question>
<question>
Natural-language question for which an equivalent SQL query will be generated
<schema name>
<schema name>
Name of the schema containing the context to use in generating
the query
WITH OPTIONS
WITH OPTIONS
Optional indicator that a comma-delimited list of SQL generation option/value assignments will
follow.See SQL Token Generation Options for the complete list of options.
SQL Token Generation Options
The following options can be specified to modify the way the counted tokens are generated.context_name
context_name
Name of the SQL-GPT context to use as a basis for counting generated tokens; should be of the
form
[<schema name>.]<context name>.context_names
context_names
Comma-separated list of names of SQL-GPT contexts to use as the basis for counting generated
tokens; each should be of the form
[<schema name>.]<context name>, and the entire list
should be single-quoted.For example:use_rag
use_rag
Whether to use retrieval-augmented generation (RAG) facilities
with the given SQL-GPT contexts when processing this request.
SQL Token Generation Examples
To count the generated tokens for theexample.atc_ctx
SQL-GPT context:
GENERATE TOKENS Example
nyctaxi_ctx & flights_ctx
SQL-GPT contexts with SQL RAG:
GENERATE TOKENS with RAG Example
EXECUTE_AI_QUERY
Executes a SQL query equivalent of the given natural-language question using the specified SQL-GPT context.EXECUTE_AI_QUERY Table Function Syntax
Parameters
<question>
<question>
Natural-language question for which an equivalent SQL query will be executed
<schema name>
<schema name>
Name of the schema containing the context to use in generating
the query
OPTIONS
OPTIONS
SQL generation options, specified as a set of key/value pairs
passed as a comma-delimited list of
<key> = '<value>' assignments to the KV_PAIRS
function; e.g.:SQL Generation Options
The following options can be specified to modify the way the executed SQL query is generated.ai_api_provider
ai_api_provider
Name of an LLM service to use other than the default one; the default,
sqlgpt, uses the
Kinetica SQLGPT.io service.ai_api_url
ai_api_url
URL of an LLM service to use other than the default one.
context_name
context_name
Name of the SQL-GPT context to use in generating the executed query; should be of the form
[<schema name>.]<context name>.context_names
context_names
Comma-separated list of names of SQL-GPT contexts to use in generating the executed query;
each should be of the form
[<schema name>.]<context name>, and the entire list should be
single-quoted.For example:use_rag
use_rag
Whether to use retrieval-augmented generation (RAG) facilities
with the given SQL-GPT contexts when processing this request.
SQL Execution Examples
To execute the SQL equivalent query to a given question using theexample.atc_ctx SQL-GPT context:
EXECUTE_AI_QUERY Example
nyctaxi_ctx & flights_ctx SQL-GPT contexts with SQL RAG:
EXECUTE_AI_QUERY with RAG Example