# DuckDB Data Accelerator

To use DuckDB as Data Accelerator, specify `duckdb` as the `engine` for acceleration.

```yaml
datasets:
  - from: spice.ai:path.to.my_dataset
    name: my_dataset
    acceleration:
      engine: duckdb
```

> **Warning**
>
> Spice v2.4 deprecates the `duckdb` engine, and Spice v2.5 removes it. Move each acceleration to [Spice Cayenne](https://spiceai.org/docs/components/data-accelerators/cayenne): set `engine: cayenne`. On native Windows, Cayenne is not available: run Spice in Docker or WSL first. Restart Spice and confirm that Cayenne finished its first load before you delete anything. The old acceleration can hold data that the source no longer has. Then delete the DuckDB database file and its `.wal` file, unless another dataset still uses that file on `duckdb`. A `mode: memory` acceleration leaves no file. See the [Cayenne migration guide](https://spiceai.org/docs/components/data-accelerators/cayenne/migration).

## Why Cayenne Replaces DuckDB

The DuckDB accelerator stores a dataset in one DuckDB database file, and one process at a time writes that file. As accelerated datasets grew, this design set three limits:

- **Writes queue under load.** The single file serializes concurrent writes, so refreshes queue behind each other during heavy ingestion.
- **Memory grows with the dataset.** Memory overhead rises with dataset size. DuckDB indexes do not spill to disk, and `duckdb_memory_limit` does not cover every allocation.
- **One file limits size.** At large sizes, the single-file model sets a practical limit on how much data one dataset can hold.

[Spice Cayenne](https://spiceai.org/docs/components/data-accelerators/cayenne) stores data in immutable Vortex files and keeps metadata in an embedded SQLite metastore. A refresh stages new files and commits them in one metastore transaction. Queries read the previous snapshot until the commit completes. A memory pool enforces limits for the whole runtime, and queries spill to disk instead of failing.

In the Spice benchmarks, Cayenne ran TPC-H at scale factor 100 1.4 times faster than DuckDB, with nearly three times less memory. On ClickBench, Cayenne ran 14% faster and used 3.4 times less memory. The tests compared DuckDB v1.4.2 in file mode with Spice v1.9.0, on a 16 vCPU, 64 GiB instance with local NVMe storage. See [Introducing Spice Cayenne](https://spice.ai/blog/introducing-spice-cayenne-data-accelerator).

## Move a DuckDB Acceleration to Cayenne

Set `engine: cayenne` and remove `duckdb_file`, `duckdb_data_dir`, and the other `duckdb_*` parameters. A `mode: file` DuckDB dataset keeps `mode: file`:

```yaml
datasets:
  - from: spice.ai:path.to.my_dataset
    name: my_dataset
    ready_state: on_load
    acceleration:
      engine: cayenne
      mode: file
```

With `ready_state: on_load`, queries do not fall back to the source during the first Cayenne load. Compare query results with the old acceleration before you delete the DuckDB file. A dataset that uses the DuckDB vector engine needs more changes, and its vector scores change scale. See the [Cayenne migration guide](https://spiceai.org/docs/components/data-accelerators/cayenne/migration) for these steps.

## Configuration

The DuckDB accelerator supports `mode: memory`, `mode: file`, `mode: file_create`, and `mode: file_update`.

Configuration `params` are provided in the `acceleration` section for a data store. For the other common `acceleration` fields, see [Data Accelerators](https://spiceai.org/docs/components/data-accelerators).

> **Warning**
>
> **LIMITATIONS**
>
> - The DuckDB accelerator does not support nested lists, or structs with nested structs/lists [field types](https://duckdb.org/docs/sql/data_types/overview). For example:
>   - Supported:
>     - `SELECT {'x': 1, 'y': 2, 'z': 3}`
>   - Unsupported:
>     - `SELECT [['duck', 'goose', 'heron'], ['frog', 'toad']]`
>     - `SELECT {'x': [1, 2, 3]}`
> - The DuckDB accelerator does not support enum, dictionary, or map [field types](https://duckdb.org/docs/sql/data_types/overview). For example:
>   - Unsupported:
>     - `SELECT MAP(['key1', 'key2', 'key3'], [10, 20, 30])`
> - The DuckDB accelerator does not support `Decimal256` (76 digits), as it exceeds DuckDB's maximum Decimal width of 38 digits.
> - Updating a dataset with DuckDB acceleration while the Spice Runtime is running (hot-reload) will cause the DuckDB accelerator query federation to disable until the Runtime is restarted.

> **Warning**
>
> **MEMORY CONSIDERATIONS**
>
> When accelerating a dataset using `mode: memory` (the default), some or all of the dataset is loaded into memory. Ensure sufficient memory is available, including overhead for queries and the runtime, especially with concurrent queries.
