2023-06-22 06:13:45 +00:00
|
|
|
# Motherduck
|
|
|
|
|
|
|
|
>[Motherduck](https://motherduck.com/) is a managed DuckDB-in-the-cloud service.
|
|
|
|
|
|
|
|
## Installation and Setup
|
|
|
|
|
|
|
|
First, you need to install `duckdb` python package.
|
|
|
|
|
|
|
|
```bash
|
|
|
|
pip install duckdb
|
|
|
|
```
|
|
|
|
|
|
|
|
You will also need to sign up for an account at [Motherduck](https://motherduck.com/)
|
|
|
|
|
|
|
|
After that, you should set up a connection string - we mostly integrate with Motherduck through SQLAlchemy.
|
|
|
|
The connection string is likely in the form:
|
|
|
|
|
|
|
|
```
|
|
|
|
token="..."
|
|
|
|
|
|
|
|
conn_str = f"duckdb:///md:{token}@my_db"
|
|
|
|
```
|
|
|
|
|
|
|
|
## SQLChain
|
|
|
|
|
|
|
|
You can use the SQLChain to query data in your Motherduck instance in natural language.
|
|
|
|
|
|
|
|
```
|
|
|
|
from langchain import OpenAI, SQLDatabase, SQLDatabaseChain
|
|
|
|
db = SQLDatabase.from_uri(conn_str)
|
|
|
|
db_chain = SQLDatabaseChain.from_llm(OpenAI(temperature=0), db, verbose=True)
|
|
|
|
```
|
|
|
|
|
2023-07-27 19:55:13 +00:00
|
|
|
From here, see the [SQL Chain](/docs/use_cases/tabular/sqlite.html) documentation on how to use.
|
2023-06-22 06:13:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
## LLMCache
|
|
|
|
|
|
|
|
You can also easily use Motherduck to cache LLM requests.
|
|
|
|
Once again this is done through the SQLAlchemy wrapper.
|
|
|
|
|
|
|
|
```
|
|
|
|
import sqlalchemy
|
|
|
|
eng = sqlalchemy.create_engine(conn_str)
|
|
|
|
langchain.llm_cache = SQLAlchemyCache(engine=eng)
|
|
|
|
```
|
|
|
|
|
|
|
|
From here, see the [LLM Caching](/docs/modules/model_io/models/llms/how_to/llm_caching) documentation on how to use.
|
|
|
|
|
|
|
|
|