Last active
November 21, 2024 22:42
-
-
Save cboettig/d3bf761e7b46bba702e76f502dbc622c to your computer and use it in GitHub Desktop.
langchain + ibis share a connection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parquet = "https://espm-157-f24.github.io/spatial-carl-amanda-tyler/new_haven_stats.parquet" | |
# create sharable low-level connection, see: https://github.com/Mause/duckdb_engine | |
import sqlalchemy | |
eng = sqlalchemy.create_engine("duckdb:///:memory:") | |
# ibis can talk to this connection and create the VIEW | |
import ibis | |
con = ibis.duckdb.from_connection(eng.raw_connection()) | |
tbl = con.read_parquet(parquet, "mydata") | |
# langchain can also talk to this connection and see the table: | |
from langchain_community.utilities import SQLDatabase | |
db = SQLDatabase(eng, view_support=True) | |
print(db.get_usable_table_names()) | |
# we can now do both `tbl.sql()` commands and use `db` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment