Feedback

Select AI enables you to provide feedback to help improve your selected LLM's ability to generate more accurate SQL queries.

Note:

This feature is available only on Oracle Database 23ai. You can use it alongside the existing Select AI actions: runsql, showsql, and explainsql. Ensure that your AI profile is configured for NL2SQL generation and not RAG.

You can provide feedback to improve the accuracy of the generated SQL through the feedback action or the DBMS_CLOUD_AI.FEEDBACK procedure. Select AI creates a default vector index named <profile_name>_FEEDBACK_VECINDEX with default attributes when you use the feedback feature for the first time. This index helps refine future generated SQL based on the feedback provided. See Vector Index for FEEDBACK for more information.

Tip:

Use the DBMS_CLOUD_AI.FEEDBACK procedure when your specified LLM fails to generate the correct SQL query or does not return the expected result from one of the NL2SQL SELECT AI actions. You can also use the DBMS_CLOUD_AI.FEEDBACK procedure to add the correct SQL directly to the vector table. This helps guide future SQL generation by serving as a reference for similar prompts.

The following types of feedback are accepted:
  • Positive feedback: You approve and confirm the accuracy of the generated SQL. The system stores the confirmed query for future reference.

  • Negative feedback: If the results from your NL2SQL SELECT AI action fails to generate the correct SQL, you can provide the necessary SQL query improvements using SELECT AI feedback <feedback> or using the DBMS_CLOUD_AI.FEEDBACK procedure by identifying errors in the query or providing guidance as to what was expected in prose. The system refines the query using an LLM and stores the refined version for future Select AI query generation. The stored refined queries are then used as hints and sent to the LLM as part of the augmented prompt.

See FEEDBACK Procedure and Example: Select AI Feedback to learn more.

Topics

Benefits of Feedback

The feedback action and procedure in Select AI introduces a prompt tuning mechanism that enhances the accuracy of SQL query generation.

The owner of the AI profile can provide feedback for generated SQL queries and the Select AI system learns from the user interaction over time. This learning involves amassing a repository of prompts and feedback content where vector search is used to identify prompts similar to your current prompt. The top matching examples are provided as metadata to the LLM as part of the augmented prompt. The following are the benefits:
  • Can improve accuracy of SQL queries.
  • Enables the owner of AI profile to provide feedback by confirming the correct queries or suggesting corrections by providing the semantic intention or business definitions to produce a correct query.
  • Uses historical feedback as hints for future query generation thereby adapting to your needs.

How Do I Use Feedback

Select AI enables you to provide feedback either by using the feedback action or by calling the DBMS_CLOUD_AI.FEEDBACK procedure.

Caution:

Do not use the feedback action in applications where multiple users share database sessions under a single database user that owns the AI profile. The AI profile owner should provide feedback only after confirming that the corrected query is appropriate for all users of that profile.

You can provide feedback by including the following:
  • SQL_TEXT: Include the feedback in quotes for your current SQL query or you can get the SQL_TEXT for a particular query by querying the V$MAPPED_SQL view.

  • SQL_ID: You can get the SQL_ID by querying the V$MAPPED_SQL view.

  • Use the last generated SQL: Provide your feedback in natural language.

    Note:

    To use last sql, be sure to set server output off in Oracle SQL*Plus or Oracle SQLcl. You must have SELECT privilege on v$session and v$mapped_sql tables.

See FEEDBACK Procedure and Example: Select AI Feedback to learn more.