Skip to content

Commit b09d272

Browse files
committed
Add the final readme
1 parent 6038bc6 commit b09d272

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

text2sql/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Using Auto-Function calling capabilities, the LLM is able to retrieve from the p
3636

3737
- `./rag_with_text_2_sql.ipynb` provides example of how to utilise the Text2SQL plugin to query the database.
3838
- `./rag_with_ai_searchandtext_2_sql.ipynb` provides an example of how to use the Text2SQL and an AISearch plugin in parallel to automatically retrieve data from the most relevant source to answer the query.
39+
- This setup is useful for a production application as the SQL Database is unlikely to be able to answer all the questions a user may ask.
3940

4041
## SQL Plugin
4142

@@ -91,6 +92,22 @@ A full data dictionary must be built for all the views / tables you which to exp
9192

9293
The `./plugins/sql_plugin/sql_plugin.py` contains 3 key methods to power the Text2SQL engine.
9394

95+
#### system_prompt()
96+
97+
This method takes the loaded `entities.json` file and generates a system prompt based on it. Here, the **entity_name**, **description** and **selector** are used to build a list of available entities for the LLM to select.
98+
99+
This is then inserted into a pre-made Text2SQL generation prompt that already contains optimised and working instructions for the LLM. This system prompt for the plugin is added to the main prompt file at runtime.
100+
101+
The **target_engine** is passed to the prompt, along with **engine_specific_rules** to ensure that the SQL queries generated work on the target engine.
102+
103+
#### get_entity_schema()
104+
105+
This method is called by the Semantic Kernel framework automatically, when instructed to do so by the LLM, to fetch the full schema definitions for a given entity. This returns a JSON string of the chosen entity which allows the LLM to understand the column definitions and their associated metadata. This can be called in parallel for multiple entities.
106+
107+
#### run_sql_query()
108+
109+
This method is called by the Semantic Kernel framework automatically, when instructed to do so by the LLM, to run a SQL query against the given database. It returns a JSON string containing a row wise dump of the results returned. These results are then interpreted to answer the question.
110+
94111
## Sample Usage
95112

96113
### What is the top performing product by quantity of units sold?

0 commit comments

Comments
 (0)