Ollama · duckdb-nsql

![duckdb-nsql model](https://github.com/ollama/ollama/assets/3325447/b9217c78-0803-45fe-90cf-00bd76705a37) DuckDB-NSQL is a 7 billion parameter text-to-SQL model designed specifically for SQL generat…

ollama/duckdb-nsql

![duckdb-nsql model](https://github.com/ollama/ollama/assets/3325447/b9217c78-0803-45fe-90cf-00bd76705a37)

DuckDB-NSQL is a 7 billion parameter text-to-SQL model designed specifically for SQL generation tasks.

This model is based on Meta's original Llama-2 7B model and further pre-trained on a dataset of general SQL queries and then fine-tuned on a dataset composed of DuckDB text-to-SQL pairs.

## Usage

### Example Prompt

``` Provided this schema:

CREATE TABLE taxi ( VendorID bigint, tpep_pickup_datetime timestamp, tpep_dropoff_datetime timestamp, passenger_count double, trip_distance double, fare_amount double, extra double, tip_amount double, tolls_amount double, improvement_surcharge double, total_amount double, );

Give me taxis with more than 2 passengers ```

### Example output

``` SELECT * FROM taxi WHERE passenger_count > 2 ```

## Setting the system prompt

This model expects the schema in the system prompt as input:

``` /set system """Here is the database schema that the SQL query will run on: CREATE TABLE taxi ( VendorID bigint, tpep_pickup_datetime timestamp, tpep_dropoff_datetime timestamp, passenger_count double, trip_distance double, fare_amount double, extra double, tip_amount double, tolls_amount double, improvement_surcharge double, total_amount double, );"""

```

Once the schema is provided in the system prompt, the model will use it in subsequent responses.

For the following prompt:

``` get all columns ending with _amount from taxi table ```

The model will output something like this:

``` SELECT COLUMNS('.*_amount') FROM taxi; ```

## API example

``` $ curl http://localhost:11434/api/generate -d '{ "model": "duckdb-nsql:7b-q4_0", "system": "Here is the database schema that the SQL query will run on: CREATE TABLE taxi (VendorID bigint, tpep_pickup_datetime timestamp, tpep_dropoff_datetime timestamp, passenger_count double, trip_distance double, fare_amount double, extra double, tip_amount double, tolls_amount double, improvement_surcharge double, total_amount double,);", "prompt": "get all columns ending with _amount from taxi table" }' ```

## Python library example

``` pip install ollama ```

``` import ollama

r = ollama.generate( model='duckdb-nsql:7b-q4_0', system='''Here is the database schema that the SQL query will run on: CREATE TABLE taxi ( VendorID bigint, tpep_pickup_datetime timestamp, tpep_dropoff_datetime timestamp, passenger_count double, trip_distance double, fare_amount double, extra double, tip_amount double, tolls_amount double, improvement_surcharge double, total_amount double, );''', prompt='get all columns ending with _amount from taxi table', )

print(r['response']) ```

## Training Data

200k DuckDB text-to-SQL pairs, synthetically generated using Mixtral-8x7B-Instruct-v0.1, guided by the DuckDB v0.9.2 documentation. And text-to-SQL pairs from NSText2SQL that were transpiled to DuckDB SQL using sqlglot.

## Training Procedure

DuckDB-NSQL was trained using cross-entropy loss to maximize the likelihood of sequential inputs. For finetuning on text-to-SQL pairs, we only compute the loss over the SQL portion of the pair. The model is trained using 80GB A100s, leveraging data and model parallelism. We fine-tuned for 10 epochs.

## Intended Use and Limitations

The model was designed for text-to-SQL generation tasks from given table schema and natural language prompts. The model works best with the prompt format defined below and outputs. In contrast to existing text-to-SQL models, the SQL generation is not contrained to SELECT statements, but can generate any valid DuckDB SQL statement, including statements for official DuckDB extensions.

## References

[Hugging Face](https://huggingface.co/motherduckdb/DuckDB-NSQL-7B-v0.1)

Specifications & capabilities

Published model ID
duckdb-nsql

Deployments & artifacts

1–17 / 17

ollama

source id
ollama
execution mode
local
parameter size
7B
parameter count
7000000000
parameter count is approximate
true
quantization level
Q4_0
context window
16000
context window is approximate
true
artifact size bytes
3825898502
updated at
2026-11-16T08:10:06.079865+00:00

ollama

source id
ollama
execution mode
local
parameter size
7B
parameter count
7000000000
parameter count is approximate
true
quantization level
F16
context window
16000
context window is approximate
true
artifact size bytes
13478367718
updated at
2026-11-16T08:10:06.079865+00:00

ollama

source id
ollama
execution mode
local
parameter size
7B
parameter count
7000000000
parameter count is approximate
true
quantization level
Q2_K
context window
16000
context window is approximate
true
artifact size bytes
2532939782
updated at
2026-11-16T08:10:06.079865+00:00

ollama

source id
ollama
execution mode
local
parameter size
7B
parameter count
7000000000
parameter count is approximate
true
quantization level
Q3_K_L
context window
16000
context window is approximate
true
artifact size bytes
3597193734
updated at
2026-11-16T08:10:06.079865+00:00

ollama

source id
ollama
execution mode
local
parameter size
7B
parameter count
7000000000
parameter count is approximate
true
quantization level
Q3_K_M
context window
16000
context window is approximate
true
artifact size bytes
3298087430
updated at
2026-11-16T08:10:06.079865+00:00

ollama

source id
ollama
execution mode
local
parameter size
7B
parameter count
7000000000
parameter count is approximate
true
quantization level
Q3_K_S
context window
16000
context window is approximate
true
artifact size bytes
2948387334
updated at
2026-11-16T08:10:06.079865+00:00

ollama

source id
ollama
execution mode
local
parameter size
7B
parameter count
7000000000
parameter count is approximate
true
quantization level
Q4_0
context window
16000
context window is approximate
true
artifact size bytes
3825898502
updated at
2026-11-16T08:10:06.079865+00:00

ollama

source id
ollama
execution mode
local
parameter size
7B
parameter count
7000000000
parameter count is approximate
true
quantization level
Q4_1
context window
16000
context window is approximate
true
artifact size bytes
4238844934
updated at
2026-11-16T08:10:06.079865+00:00

ollama

source id
ollama
execution mode
local
parameter size
7B
parameter count
7000000000
parameter count is approximate
true
quantization level
Q4_K_M
context window
16000
context window is approximate
true
artifact size bytes
4081095686
updated at
2026-11-16T08:10:06.079865+00:00

ollama

source id
ollama
execution mode
local
parameter size
7B
parameter count
7000000000
parameter count is approximate
true
quantization level
Q4_K_S
context window
16000
context window is approximate
true
artifact size bytes
3856831494
updated at
2026-11-16T08:10:06.079865+00:00

ollama

source id
ollama
execution mode
local
parameter size
7B
parameter count
7000000000
parameter count is approximate
true
quantization level
Q5_0
context window
16000
context window is approximate
true
artifact size bytes
4651791366
updated at
2026-11-16T08:10:06.079865+00:00

ollama

source id
ollama
execution mode
local
parameter size
7B
parameter count
7000000000
parameter count is approximate
true
quantization level
Q5_1
context window
16000
context window is approximate
true
artifact size bytes
5064737798
updated at
2026-11-16T08:10:06.079865+00:00

ollama

source id
ollama
execution mode
local
parameter size
7B
parameter count
7000000000
parameter count is approximate
true
quantization level
Q5_K_M
context window
16000
context window is approximate
true
artifact size bytes
4783256582
updated at
2026-11-16T08:10:06.079865+00:00

ollama

source id
ollama
execution mode
local
parameter size
7B
parameter count
7000000000
parameter count is approximate
true
quantization level
Q5_K_S
context window
16000
context window is approximate
true
artifact size bytes
4651791366
updated at
2026-11-16T08:10:06.079865+00:00

ollama

source id
ollama
execution mode
local
parameter size
7B
parameter count
7000000000
parameter count is approximate
true
quantization level
Q6_K
context window
16000
context window is approximate
true
artifact size bytes
5529302534
updated at
2026-11-16T08:10:06.079865+00:00

ollama

source id
ollama
execution mode
local
parameter size
7B
parameter count
7000000000
parameter count is approximate
true
quantization level
Q8_0
context window
16000
context window is approximate
true
artifact size bytes
7161229830
updated at
2026-11-16T08:10:06.079865+00:00

ollama

source id
ollama
execution mode
local
parameter size
7B
parameter count
7000000000
parameter count is approximate
true
quantization level
Q4_0
context window
16000
context window is approximate
true
artifact size bytes
3825898502
updated at
2026-11-16T08:10:06.079865+00:00

Original sources

1–2 / 2

Ollama · Model page ↗

Ollama · Catalog ↗

Source links

1–1 / 1

Explore more models

Models

Loading
EVIDENCE / COMPARISON

Benchmarks

Explore every benchmark

Loading

These charts contain model-linked results. The charts above also include unlinked source profiles. Compare scores within each evaluation. Model quality, usage, transparency and system performance measure different things.

Install TensorTrace