试用
SQL is hard,这个基本上是每一个开发者都会遇到的问题,尤其是对于新手来说,SQL的语法和逻辑并不是那么容易理解。
那么如何利用自然语言和大语言模型生成SQL就成为必要,这就是Text2SQL的作用。
对应大多数同学来说,最简单的text2sql就是 prompt + database schema,如下:
curl -X POST "https://www.text2sql.ai/api/sql/generate"
-H "Authorization: Bearer YOUR_API_KEY"
-H "Content-Type: application/json"
-d '{
"prompt": "Find all items with id 1.",
"type": "mysql",
"schema": "Items (id, ..."
}'
下图是AWS的text2SQL的架构:

借助于RAG,Text2SQL的升级版可能是RAG2SQL,如下:

Text2SQL & Friends
- postgres.new: In-browser Postgres sandbox with AI assistance - https://github.com/supabase-community/postgres-new
- text2sql.ai: Generate SQL with AI - https://www.text2sql.ai/
- https://github.com/vanna-ai/vanna
References
- Awesome-Text2SQL: https://github.com/eosphoros-ai/Awesome-Text2SQL
- Spider: large-scale complex and cross-domain semantic parsing and text-to-SQL dataset - https://yale-lily.github.io/spider
- Improving Text2SQL Performance with Ease on Databricks: https://www.databricks.com/blog/improving-text2sql-performance-ease-databricks
- No More Text2SQL, It's Now RAG2SQL: https://mlnotes.substack.com/p/no-more-text2sql-its-now-rag2sql
- AI SQL Accuracy: https://vanna.ai/blog/ai-sql-accuracy.html