0

I've been doing some research on how to leverage a LLM model to "translate" English into a sql query that's capable to returning the desired results (like a little Q/A bot). For instance, one would ask "show me the top growth account in the last three months in the state of FL?" and it will return the results. After googling around, a lot of information I've found is at a high level where you follow the pipeline of

  1. Build data model --> 2. pick a LLM --> 3. prompt design --> 4. parse the question to query --> 5. execute query --> 6. parse result

I have a a few questions:

  1. is LLM model fine-tuning using your own data required for this type of tasks?
  2. where should mapping between database fields and the query components happen? In my example above, let's say i have two date fields in my database - sales_date, and invoice_date, the LLM would know to use invoice_date for the "last 3 months" request
  3. Any online sources that give an implementation example would be great
adjfac
  • 103
  • 4

1 Answers1

2

is LLM model fine-tuning using your own data required for this type of tasks?

not necessarily

where should mapping between database fields and the query components happen?

this is where we leverage LLM to do the work for us automatically

Any online sources that give an implementation example would be great:

This is a common task these days. Check out this page for an example.

query_engine = NLSQLTableQueryEngine(
    sql_database=sql_database,
    tables=["city_stats"],
)
query_str = (
    "Which city has the highest population?"
)
response = query_engine.query(query_str)

Note that we need to specify the tables we want to use with this query engine. If we don’t the query engine will pull all the schema context, which could overflow the context window of the LLM.

morpheus
  • 274
  • 6
  • "this is where we leverage LLM to do the work for us automatically" - i don't think the LLM is "smart" enough to figure that out right? Some guidance in the code / prompt design is required? – adjfac Jul 08 '23 at 01:21
  • 1
    Yes. the devil is in the details. I have given you initial pointer. you will have to explore from there. also see: https://huggingface.co/docs/transformers/model_doc/rag. everyone is trying to do this these days. – morpheus Jul 08 '23 at 01:26
  • Thanks! will take a look! – adjfac Jul 08 '23 at 02:40