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

Query Certification

Query certification is a mechanism for storing queries that users consider ideal examples. These certified queries serve as reference specimens that language models can learn from, improving the accuracy of generated SQL.

A maximum of three certified queries with a cosine similarity of ≥ 0.75 are injected into the prompt.


certify_query

Certifies a functional query so that it can be provided to prompts to boost accuracy. Returns a unique identifier for the certified query.

Returns

  • Type: TEXT
  • Description: A UUID identifying the query certification instance.

Parameters

language_query
  • Description: Natural language query that accurately reflects sql_query.
  • Type: TEXT
  • Optional: false
sql_query
  • Description: SQL query that accurately reprsents the language_query.
  • Type: TEXT
  • Optional: false
engine
  • Description: Engine to set query for. If NULL, defaults to value set via set_default_engine.
  • Type: TEXT
  • Optional: true
  • Default: NULL

Example

-- Without default engine
SELECT sqlgen.certify_query(
    'SELECT name, price FROM inventory',
    'Get name and price from inventory'
);

-- Without default engine
SELECT sqlgen.certify_query(
    'SELECT name, price FROM inventory',
    'Get name and price from inventory',
    'my_engine'
);

decertify_query

Removes a certified query.

Returns

  • Type: VOID

Parameters

id
  • Description: Identifier for certified query.
  • Type: TEXT
  • Optional: false
engine
  • Description: Engine to remove query from. If NULL, defaults to value set via set_default_engine.
  • Type: TEXT
  • Optional: true
  • Default: NULL

Example

-- Without default engine
SELECT sqlgen.decertify_query('6d6e1596-f3a8-4847-a1d8-ccb3d60fc0e6');

-- Without default engine
SELECT sqlgen.decertify_query(
    '6d6e1596-f3a8-4847-a1d8-ccb3d60fc0e6',
    'my_engine'
);