Skip to main content

Getting started with Spice.ai OSS

Follow these steps to get started with Spice.​

Step 1. Install the Spice CLI:

curl https://install.spiceai.org | /bin/bash

Or using brew:

brew install spiceai/spiceai/spice

Step 2. Initialize a new Spice app with the spice init command:

spice init spice_qs

A spicepod.yaml file is created in the spice_qs directory. Change to that directory:

cd spice_qs

Step 3. Start the Spice runtime:

spice run

Example output will be shown as follows:

Spice.ai runtime starting...
Using latest 'local' runtime version.
2024-06-03T23:21:26.819978Z INFO spiced: Metrics listening on 127.0.0.1:9090
2024-06-03T23:21:26.821863Z INFO runtime::http: Spice Runtime HTTP listening on 127.0.0.1:8090
2024-06-03T23:21:26.821898Z INFO runtime::flight: Spice Runtime Flight listening on 127.0.0.1:50051
2024-06-03T23:21:26.821958Z INFO runtime::opentelemetry: Spice Runtime OpenTelemetry listening on 127.0.0.1:50052
2024-06-03T23:21:26.822128Z INFO runtime: Initialized results cache; max size: 128.00 MiB, item ttl: 1s

The runtime is now started and ready for queries.

Step 4. In a new terminal window, add the spiceai/quickstart Spicepod. A Spicepod is a package of configuration defining datasets and ML models.

spice add spiceai/quickstart

The spicepod.yaml file will be updated with the spiceai/quickstart dependency.

version: v1beta1
kind: Spicepod
name: PROJECT_NAME
dependencies:
- spiceai/quickstart

The spiceai/quickstart Spicepod will add a taxi_trips data table to the runtime which is now available to query by SQL.

2024-06-03T23:21:29.721705Z  INFO runtime: Registered dataset taxi_trips
2024-06-03T23:21:29.722839Z INFO runtime::accelerated_table::refresh: Loading data for dataset taxi_trips
2024-06-03T23:21:50.813510Z INFO runtime::accelerated_table::refresh: Loaded 2,964,624 rows (421.71 MiB) for dataset taxi_trips in 21s 90ms.

Step 5. Start the Spice SQL REPL:

spice sql

The SQL REPL inferface will be shown:

Welcome to the Spice.ai SQL REPL! Type 'help' for help.

show tables; -- list available tables
sql>

Enter show tables; to display the available tables for query:

sql> show tables
+---------------+--------------+---------------+------------+
| table_catalog | table_schema | table_name | table_type |
+---------------+--------------+---------------+------------+
| spice | runtime | metrics | BASE TABLE |
| spice | runtime | query_history | BASE TABLE |
| spice | public | taxi_trips | BASE TABLE |
+---------------+--------------+---------------+------------+

Time: 0.007505084 seconds. 1 rows.

Enter a query to display the longest taxi trips:

sql> SELECT trip_distance, total_amount FROM taxi_trips ORDER BY trip_distance DESC LIMIT 10;

Output:

+---------------+--------------+
| trip_distance | total_amount |
+---------------+--------------+
| 312722.3 | 22.15 |
| 97793.92 | 36.31 |
| 82015.45 | 21.56 |
| 72975.97 | 20.04 |
| 71752.26 | 49.57 |
| 59282.45 | 33.52 |
| 59076.43 | 23.17 |
| 58298.51 | 18.63 |
| 51619.36 | 24.2 |
| 44018.64 | 52.43 |
+---------------+--------------+

Time: 0.015596458 seconds. 10 rows.

Next Steps​