Pool Nolasco
Pool Nolasco

Reputation: 137

Suggestion to improve chat with SQL database using Langchain

I am developing a script in python to chat with SQL server Database. Now I am using Langchain to connect with OpenAI´s LLM models. I found in the documentations of langchain two ways to chat with SQL database: Agents and Chains. During my tests i find out that CHAINS works faster than AGENTS to when receive a query (the query is in natural lenguaje, not SQL query) and return an answer. This test was only just for one database and one table.

Another test include a second tables in the same database. And the results was that AGENTS works really well with error: "column name ambiguous (209 error)". But CHAINS return the error 209. It was because both tables have same "heads" at the top. I think if there is other problems, maybe CHAINS even being fast not help to give answers.

But now I would like to increase the level of the chat. What about having two or much more databases in SQL (each database with one or multiple tables). As you can see in the documentation of LANGCHAIN (CHAINS or AGENTS), just use credentials to access respective database. Similar that any other package of database in python (sqlalchemy, pymsql,...).

Someone could give me advice or maybe have worked in similar "chat with SQL" project. Maybe use a layer before introduce the query in langchain, organize the query to recognize each database or so on, could be solutions. Or at the end another tool to chat with your database but using LLM. I apprecciate your suggestion.

Agents-langchain: https://python.langchain.com/docs/modules/agents/toolkits/sql_database

Chains-Langchain: https://python.langchain.com/docs/modules/chains/popular/sqlite

Upvotes: 2

Views: 3650

Answers (1)

Osmany Pujol
Osmany Pujol

Reputation: 1

One thing you can do is create an Agent Executor and provide other agents as tools to this executor.

With this, you can develop an SQL agent for each database since currently each agent only supports one database connection.

I have been doing this and is working okay. Like you said Agents are very slow and when you use gpt-4 its even slower. But gpt-35 has had very bad performance for me.

Upvotes: 0

Related Questions