Find answers from the community

Updated 2 months ago

Logan M 8260 Hi I m using Langchain

Hi, I'm using Langchain SQLDatabase to wrap with actual SQL database connection, but creating SQLDatabase object takes long time, over 2m sometimes. Is there any way to make it faster? Seems only creating SQLDatabase object takes a long time. Without creating this object, just create SQLAlchemy engine to connect to db is really fast. Why creating Langchain SQLDatabase object takes such a long time? Is there any way to faster it?
j
c
6 comments
hey @cincy, could you share the code? are you using the raw langchain sqldatabase class or our sqldatabase class?
from langchain.sql_database import SQLDatabase

driver = "{ODBC Driver 17 for SQL Server}"
server = "{sql_server_name}.database.windows.net"
database = "{database_name}"
user = ""
password = ""
conn = f"Driver={driver};Server=tcp:{server},1433;Database={database};Uid={user};Pwd={password};Authentication=ActiveDirectoryServicePrincipal;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;"
params = urllib.parse.quote_plus(conn)
conn_str = 'mssql+pyodbc:///?autocommit=true&odbc_connect={}'.format(params)

db = SQLDatabase.from_uri(conn_str, include_tables=[""])
Hi @jerryjliu0 This is the code I'm using. for last step to create SQLDatabase object, it takes over 2min.
@jerryjliu0 I checked if I don't create SQLDatabase object, but just creating sql alchemy to connect to azure sql db, it's fast. But creating this SQLDatabase object takes a long time.
@jerryjliu0 I'm trying to see if I can create sql index to let LLM generate sql query without creating this object, but seems it can not be avoided. So just would like to see if I'm not configuring correctly? Or why this object creation takes a long time.
I see...weird. SQLDatabase.from_uri should just call SQLAlchemy's create function under the hood
Add a reply
Sign up and join the conversation on Discord