Find answers from the community

Updated 2 years ago

How to connect LLM to SQL database with ...

At a glance
The community member is new to the community and has a question about how LlamaIndex can connect LLM with SQL. They have read articles claiming that LlamaIndex can only query one table with high accuracy and fails when there are more than one table. The comments suggest that LlamaIndex can work with multiple tables, but for over 10 tables, a table retriever may be needed to trim down the query space. It also helps to provide the tables with extra context information. The comments indicate that the number of rows in a table does not matter, and the LLM can generate a SQL query to find customers that ordered with a value of $1000 or more and the order must contain a discount.
Useful resources
Hello, I am new to this community. I have a question on how LlamaIndex can connect LLM with SQL. If you have complex tables and you are trying to run join queries for example, is that something LlamaIndex can support?

I read some articles (https://medium.com/dataherald/how-to-connect-llm-to-sql-database-with-llamaindex-fae0e54de97c) where they claim that LlamaIndex is good but it's can only query one table with high accuracy. It fails when there is more than 1 table.

Thoughts?
L
M
5 comments
It's worked fine for me in the past with multiple tables, But if you have over, say, 10 tables, you'll likely want to use some kind of table retriever to trim down the query space

https://gpt-index.readthedocs.io/en/stable/end_to_end_tutorials/structured_data/sql_guide.html#building-our-table-index
It helps to give the tables extra context information too (like that example does)
How effective is it when you have a lot of data in all these tables. Let's say we have 100,000 customers with 1M orders total. Can it query something like this:

Find the customers that ordered with value $1000 or more and the order must contain a discount?
The number of rows in a table does not matter. The LLM just reads the table(s) schema and generates a SQL query. That query sounds more than doable
Add a reply
Sign up and join the conversation on Discord