Datus-agent¶
Deployment¶
Pulling submodule code locally¶
Install the Necessary Dependencies¶
Using uv¶
# Create a virtual environment
uv venv -p 3.12
# Synchronize all dependencies
uv sync
# with dev dependencies
uv sync --dev
# Use current environment
source .venv/bin/activate
Using conda¶
Using venv¶
virtualenv datus-agent --python=python3.12
source datus-agent/bin/activate
pip install -r requirements.txt
Configuration¶
Agent.yml¶
Then modify conf/agent.yml as needed:
agent:
target: deepseek-v3
models:
deepseek-v3:
type: deepseek
base_url: https://api.deepseek.com
api_key: ${DEEPSEEK_API_KEY}
model: deepseek-chat
deepseek-r1:
type: deepseek
base_url: https://api.deepseek.com
api_key: ${DEEPSEEK_API_KEY}
model: deepseek-reasoner
storage_path: data
benchmark:
bird_dev:
benchmark_path: benchmark/bird/dev_20240627
spider2:
benchmark_path: benchmark/spider2/spider2-snow
namespace: # namespace is a set of database connections
local_duckdb:
type: duckdb
uri: ./tests/duckdb-demo.duckdb
spider-snow:
type: snowflake
warehouse: ${SNOWFLAKE_WAREHOUSE}
account: ${SNOWFLAKE_ACCOUNT}
username: ${SNWOFLAKE_USER}
password: ${SNOWFLAKE_PASSWORD}
bird_sqlite:
type: sqlite
path_pattern: benchmark/bird/dev_20240627/dev_databases/**/*.sqlite
storage:
base_path: data
# Local model recommendations:
# 1. For extreme performance: all-MiniLM-L6-v2 (~100M) or intfloat/multilingual-e5-small (~460M)
# 2. For balanced performance and quality: intfloat/multilingual-e5-large-instruct (~1.2G)
# 3. For optimal retrieval quality: BAAI/bge-large-en-v1.5 or BAAI/bge-large-zh-v1.5 (~3.6G)
# You can also select any model that suits your requirements.
# Default: all-MiniLM-L6-v2 if no model is configured.
# Claude model suggestions: Now we just support openai.
database:
registry_name: sentence-transformers # default is sentence-transformers, now just support sentence-transformers and openai.
model_name: text-embedding-v3
dim_size: 1024
# batch_size: 10 # This configuration is required when the registration mode is openai
document:
model_name: intfloat/multilingual-e5-large-instruct
dim_size: 1024
metric:
model_name: all-MiniLM-L6-v2
dim_size: 384
You can configure multiple models and databases. The target is the default model to use.
Langsmith (Optional)¶
Set the following environment variables for Langsmith integration:
LANGSMITH_TRACING=true
LANGSMITH_ENDPOINT=https://api.smith.langchain.com
LANGCHAIN_API_KEY=xxx
LANGSMITH_PROJECT=Datus-agent
Have a Try¶
Test Connection¶
Example Output:
LLM model test successful
Final Result: {"status": "success", "message": "LLM model test successful", "response": "Yes, I can 'hear' you! π How can I assist you today?"}
Run SQL¶
python -m datus.cli.main --namespace local_duckdb --config conf/agent.yml
Datus> select * from tree;
βββββββββββββ³ββββββββββββββ³βββββββββββββ³βββββββββ
β Continent β TradingBloc β Country β GDP β
β‘ββββββββββββββββββββββββββββββββββββββββββββββββ©
β NA β US β US β 19.485 β
β Asia β China β China β 12.238 β
β Asia β Japan β Japan β 4.872 β
β Europe β EU β Germany β 3.693 β
β Asia β India β India β 2.651 β
β Europe β UK β UK β 2.638 β
β Europe β EU β France β 2.583 β
β SA β Brazil β Brazil β 2.054 β
β Europe β EU β Italy β 1.944 β
β NA β US β Canada β 1.647 β
β Europe β Russia β Russia β 1.578 β
β Asia β SouthKorea β SouthKorea β 1.531 β
β Australia β Australia β Australia β 1.323 β
β Europe β EU β Spain β 1.314 β
β NA β US β Mexico β 1.151 β
βββββββββββββ΄ββββββββββββββ΄βββββββββββββ΄βββββββββ
Returned 15 rows in 0.03 seconds
Datus> .help
Spider2 Benchmark¶
Initialization¶
Update agent.yml if needed:
benchmark:
spider2:
benchmark_path: benchmark/spider2/spider2-snow
namespace:
spidersnow:
type: snowflake
username: ${SNOWFLAKE_USER}
account: ${SNOWFLAKE_ACCOUNT}
warehouse: ${SNOWFLAKE_WAREHOUSE}
password: ${SNOWFLAKE_PASSWORD}
Bootstrap Knowledge Base¶
python -m datus.main bootstrap-kb --namespace spidersnow --benchmark spider2 --kb_update_strategy overwrite
β οΈ May take hours (approx. 14,000 tables).
Run Test by IDs¶
python -m datus.main benchmark --namespace spidersnow --benchmark spider2 --benchmark_task_ids sf_bq104
python -m datus.cli.main --namespace spidersnow --config conf/agent.yml
Datus> !darun_screen
Creating a new SQL task
Enter task ID (49856268):
Enter task description (): Based on the most recent refresh date, identify the top-ranked rising search term for the week that is exactly one year prior to the latest available week in the dataset.
Enter database name: GOOGLE_TRENDS
Enter output directory (output):
Enter external knowledge (optional) ():
SQL Task created: 49856268
Database: snowflake - GOOGLE_TRENDS
¶
python -m datus.cli.main --namespace spidersnow --config conf/agent.yml
Datus> !darun_screen
Creating a new SQL task
Enter task ID (49856268):
Enter task description (): Based on the most recent refresh date, identify the top-ranked rising search term for the week that is exactly one year prior to the latest available week in the dataset.
Enter database name: GOOGLE_TRENDS
Enter output directory (output):
Enter external knowledge (optional) ():
SQL Task created: 49856268
Database: snowflake - GOOGLE_TRENDS
Bird Benchmark¶
Initialization¶
Update Configuration:
benchmark:
bird_dev:
benchmark_path: benchmark/bird/dev_20240627
namespace:
bird_sqlite:
type: sqlite
path_pattern: benchmark/bird/dev_20240627/dev_databases/**/*.sqlite
Download and Extract Bird Dev¶
wget https://bird-bench.oss-cn-beijing.aliyuncs.com/dev.zip
unzip dev.zip
mkdir -p benchmark/bird
mv dev_20240627 benchmark/bird
cd benchmark/bird/dev_20240627
unzip dev_databases
cd ../../..
Bootstrap Knowledge Base¶
python -m datus.main bootstrap-kb --namespace bird_sqlite --benchmark bird_dev --kb_update_strategy overwrite
Run Tests¶
python -m datus.main benchmark --namespace bird_sqlite --benchmark bird_dev --plan fixed --schema_linking_rate medium --benchmark_task_ids 14 15
python -m datus.main benchmark --namespace bird_sqlite --benchmark bird_dev --schema_linking_rate fast --benchmark_task_ids 32
python -m datus.main benchmark --namespace bird_sqlite --benchmark bird_dev --plan fixed --schema_linking_rate medium
Using cli to develop¶
Semantic Layer Benchmark¶
Initialization¶
Install Metricflow:
# poetry config virtualenvs.in-project true
poetry lock
poetry install
source .venv/bin/activate
# make sure these commands succeeded
mf setup
mf tutorial
mf validate-configs
Update Configuration ~/.metricflow/config.yml:
model_path: </path/to/semantic-models-dir>
dwh_schema: mf_demo
dwh_dialect: duckdb
dwh_database: <home dir>/.metricflow/duck.db
Update Configuration conf/agent.yml:
namespace:
duckdb:
type: duckdb
name: duck
uri: ~/.metricflow/duck.db
benchmark:
semantic_layer:
benchmark_path: benchmark/semantic_layer
Export Environment Variables:
export MF_PATH=</path/to/metricflow>/.venv/bin/mf
export MF_VERBOSE=true
export MF_MODEL_PATH=</path/to/semantic-models-dir>
Bootstrap Metrics Generation¶
python -m datus.main bootstrap-kb --namespace duckdb --components metrics --kb_update_strategy overwrite