Find answers from the community

Updated 3 months ago

Hi I have 2 questions

Hi I have 2 questions.

This question is in the context of using SQL Join Query Engine, where I've noticed the pitfall where SQL queries fail.

Q1:
What should I do in case the SQL query fails for some reason and throws an exception. Is there an option to make it do a retry? Also I notice that SQL query fails when it doesn't find an exact match on input and what's there in the record for that field. What if we can pull data if it somewhat matches? There can be a typo but the system can make out if this is the correct record to pull.

For example, "Can you tell me if there are any doctors who are experts in clinical oncology?" The query fails because SQL database contains the word "Clinical Oncology". There must be a way before entering SQL query, it should know for certain fields what values are possible. "Doctors who have expertise in heart related issues" -> "WHERE expertise LIKE 'Cardiology'"

Q2:
How can I inject my own prompt templates when querying SQL index? I think for each data source, I need to inject a set of sample commands for it to perform well that are tailored to that data source? Can I do that for each different index?
L
1 comment
I think the solution to both of these questions is providing additional descriptions of the table

When the text2sql conversion happens, all the LLM reads is the schema of the db and the user query

In addition to the automatic schema of each query, you can provide extra descriptions of each table (and these descriptions can also include instructions!)

See the table context dict in this section
https://gpt-index.readthedocs.io/en/latest/guides/tutorials/sql_guide.html#injecting-context


Side note, there isn't really any checking before executing a query, at least by default. But we are working on a microsoft guidance integration that may be able to improve text2sql queries
Add a reply
Sign up and join the conversation on Discord