Answers.Body: <blockquote>
  <p>is LLM model fine-tuning using your own data required for this type of tasks?</p>
  </blockquote>
  <p>not necessarily</p>
  <blockquote>
  <p>where should mapping between database fields and the query components happen?</p>
  </blockquote>
  <p>this is where we leverage LLM to do the work for us automatically</p>
  <blockquote>
  <p>Any online sources that give an implementation example would be great:</p>
  </blockquote>
  <p>This is a common task these days. Check out <a href="https://gpt-index.readthedocs.io/en/latest/guides/tutorials/sql_guide.html" rel="nofollow noreferrer">this</a> page for an example.</p>
  <pre><code>query_engine = NLSQLTableQueryEngine(
      sql_database=sql_database,
      tables=[&quot;city_stats&quot;],
  )
  query_str = (
      &quot;Which city has the highest population?&quot;
  )
  response = query_engine.query(query_str)
  </code></pre>
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-08T01:21:05.530Z
Answers.Text: "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?
Answers.UserDisplayName: adjfac
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-08T01:26:43.063Z
Answers.Text: 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.
Answers.UserDisplayName: morpheus
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-05T17:35:18.377Z
Answers.LastActivityDate: 2023-07-05T17:35:18.377Z
Answers.UserDisplayName: morpheus
Body: <p>I've been doing some research on how to leverage a LLM model to &quot;translate&quot; English into a sql query that's capable to returning the desired results (like a little Q/A bot). For instance, one would ask &quot;show me the top growth account in the last three months in the state of FL?&quot; 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</p>
  <ol>
  <li>Build data model --&gt; 2. pick a LLM --&gt; 3. prompt design --&gt; 4. parse the question to query --&gt; 5. execute query --&gt; 6. parse result</li>
  </ol>
  <p>I have a a few questions:</p>
  <ol>
  <li>is LLM model fine-tuning using your own data required for this type of tasks?</li>
  <li>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 &quot;last 3 months&quot; request</li>
  <li>Any online sources that give an implementation example would be great</li>
  </ol>
  
Tags: <large-language-models>
Title: Using LLM to query specific databases - where can I find implementation examples
UserDisplayName: adjfac
ThreadText: # Using LLM to query specific databases - where can I find implementation examples
  
  (Asked by: username_0 on 2023-07-05)
  
  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
  
  **Tags:** large-language-models
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-07-05. Score: 2 | Accepted answer
  
  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.
  
  > **Comments:**
  > **username_0**: "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?  
  > **username_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.  
  
  ---
  
  