Query SQL database in natural language
It's often a headache to write ad-hoc SQL queries to fetch data from databases, so teams build internal tools or PowerBI dashboards to make data accessible for non-tech teams. However, building good dashboards is not easy, and they're not always sufficient to meet ad-hoc query needs. As a result, fast-growing teams often spend significant time coordinating between data teams and non-tech teams for ad-hoc queries.
In the era of AI, teams should embrace artificial intelligence to boost their productivity. This article will introduce several best practices and tools for querying databases using natural language.
Ways to Query Databases with AI
1. Use Open Source Tools to Build Your Own Solution
There are some good open-source tools like Langchain and LlamaIndex which provide utility tools. The advantage is that you don't need to pay any subscription fees; it's completely free.
Good resources include:
- Connect SQL with LangChain
- LlamaIndex SQL Agent tutorial
- Open-source SQL Agent Demo on GitHub
However, building a production-ready SQL Agent is challenging even with these handy tools. You still need to implement:
- How to sync schema with your database
- How to implement access control and hide sensitive data like passwords from non-tech users
- Embedding tools like Code Interpreter or other visualization tools to create graphs
It still takes a lot of time to build this chatbot, even for tech professionals.
2. Use Out-of-the-Box Solutions
If your team just needs such solutions, whether for customers or internal teams, you can opt for out-of-the-box solutions like AskYourDatabase, Akkio, or Seek.ai. These tools are built with all the features you need, and all you have to do is connect your database, and you're ready to go.
Example: AskYourDatabase
Tools like AskYourDatabase provide several key features, for example:
- Flexible data visualizations
- Flexible data analysis powered by Code Interpreter
- Integration with Excel
- Support for access control
- Can be embedded into any website
If you're a team that doesn't want to spend time building such tools, solutions like AskYourDatabase are made for you.
Conclusion
The best approach depends on your team and whether you can invest time in building a SQL AI Agent.
For technical teams who want more customized solutions, tools like Langchain may be the best choice. For non-tech teams, choosing tools like AskYourDatabase will likely be the lowest-cost option.