Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Engine

Engines contain all of the relevant prompt templates and metadata required to generate results from generation functions. An engine must be created in order to generate SQL.

All engine names must be in snake case.


engines

List of engines currently available.

Usage

SELECT * FROM sqlgen.engines;

create_engine

Create an engine.

Returns

  • Type: VOID

Parameters

name
  • Description: Engine name.
  • Type: TEXT
  • Optional: false
instruct_model
  • Description: Name of instruct model to use for engine (see model).
  • Type: TEXT
  • Optional: false
encoder_model
  • Description: Name of encoder model to use for engine (see model).
  • Type: TEXT
  • Optional: false
schema_names
  • Description: Names of database schemas that model operates on.
  • Type: TEXT[]
  • Optional: true
  • Default: ARRAY[current_schema()
table_filter_type
  • Description: Determines how tables are filtered in the RAG workflow. quick uses cosine similarity, smart uses an LLM.
  • Type: TEXT, either quick or smart
  • Optional: true
  • Default: smart
column_filter_limit
  • Description: Determines how many instances of column metadata are passed into any prompt at a time. Useful if there are strong limits on a model’s maximum token input.
  • Type: INT
  • Optional: true
  • Default: 128
error_correction_rounds
  • Description: Determines how many rounds of error correction should be made before giving up.
  • Type: INT
  • Optional: true
  • Default: 3
system_prompt_template
  • Description: System prompt used when generating SQL queries from text. See Prompt templates for more information about formatting and defaults.
  • Type: TEXT
  • Optional: true
  • Default: NULL
user_prompt_template
  • Description: User prompt used when generating SQL queries from text. See Prompt templates for more information about formatting and defaults.
  • Type: TEXT
  • Optional: true
  • Default: NULL
relevant_ddls_template
  • Description: Segment of user_prompt_template used to specify how relevant DDL’s are rendered. See Prompt templates for more information about formatting and defaults.
  • Type: TEXT
  • Optional: true
  • Default: NULL
similar_queries_template
  • Description: Segment of user_prompt_template used to specify how similar queries are rendered. Currently not in use. See Prompt templates for more information about formatting and defaults.
  • Type: TEXT
  • Optional: true
  • Default: NULL
filter_ddls_template
  • Description: User prompt used when filtering DDLs with the smart filter. See Prompt templates for more information about formatting and defaults.
  • Type: TEXT
  • Optional: true
  • Default: NULL
syntax_correction_template
  • Description: User prompt used when correcting SQL syntax. See Prompt templates for more information about formatting and defaults.
  • Type: TEXT
  • Optional: true
  • Default: NULL
explain_query_template
  • Description: User prompt used when generating explanations of how queries work. See Prompt templates for more information about formatting and defaults.
  • Type: TEXT
  • Optional: true
  • Default: NULL

Example

SELECT create_engine('my_engine', 'my_llm', 'my_encoder');

SELECT sqlgen.create_engine(
    name => 'stub_engine',
    instruct_model => 'stub_model',
    encoder_model => 'stub_model',
    schema_names => ARRAY['public', 'analytics'],
    table_filter_type => 'quick'
);

remove_engine

Remove an engine.

Returns

  • Type: VOID

Parameters

name
  • Description: Name of engine.
  • Type: TEXT
  • Optional: false

Example

SELECT sqlgen.remove_engine('my_engine');

set_default_engine

Sets the default engine. When generation functions are called without an engine specified, the value set here is used.

Returns

  • Type: VOID

Parameters

engine
  • Description: Name of engine.
  • Type: TEXT
  • Optional: false

Example

SELECT sqlgen.set_default_engine('my_engine');

remove_default_engine

Removes the default engine.

Returns

  • Type: VOID

Example

SELECT sqlgen.remove_default_engine('my_engine');

add_schema_to_engine

Enable query generation capabilities for a specified text-to-sql engine.

Returns

  • Type: VOID

Parameters

engine
  • Description: Name of engine.
  • Type: TEXT
  • Optional: false
schema
  • Description: Name of schema to add.
  • Type: TEXT
  • Optional: false

Example

SELECT sqlgen.add_schema_to_engine('my_engine', 'my_schema');