Skip to content

Commit 40c569b

Browse files
authored
Merge pull request #20 from SkardiLabs/BtXin/onnx_as_feature
Make onnx as feature
2 parents 0dea778 + acf0c17 commit 40c569b

21 files changed

Lines changed: 63 additions & 334 deletions

File tree

Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ RUN apt-get update && apt-get install -y \
1313
WORKDIR /app
1414
COPY . .
1515

16-
RUN cargo build --release -p skardi-server
16+
ARG FEATURES=""
17+
RUN if [ -n "$FEATURES" ]; then \
18+
cargo build --release -p skardi-server --features "$FEATURES"; \
19+
else \
20+
cargo build --release -p skardi-server; \
21+
fi
1722

1823
# Runtime stage - debian-slim includes all required runtime dependencies
1924
FROM debian:trixie-slim

README.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Skardi lets AI agents and applications query files, databases, data lakes, and v
3333
- **Vector search** — Native KNN similarity search via Lance integration
3434
- **S3 support** — Read CSV, Parquet, and Lance files directly from S3
3535
- **Docker ready** — Ship as a container with your config files mounted at runtime
36-
- **ONNX inference** — Run ONNX model predictions inline in SQL via the `onnx_predict` UDF
36+
- **ONNX inference** — Run ONNX model predictions inline in SQL via the `onnx_predict` UDF (requires `--features onnx`)
3737

3838
## Table of Contents
3939

@@ -345,7 +345,7 @@ export PG_USER="myuser"
345345
export PG_PASSWORD="mypassword"
346346
```
347347

348-
For detailed setup, CRUD examples, and federated queries, see [demo/postgres/POSTGRES_DEMO.md](demo/postgres/POSTGRES_DEMO.md).
348+
For detailed setup, CRUD examples, and federated queries, see [demo/postgres/README.md](demo/postgres/README.md).
349349

350350
### MySQL
351351

@@ -366,7 +366,7 @@ export MYSQL_USER="myuser"
366366
export MYSQL_PASSWORD="mypassword"
367367
```
368368

369-
For detailed setup, CRUD examples, and federated queries, see [demo/mysql/MYSQL_DEMO.md](demo/mysql/MYSQL_DEMO.md).
369+
For detailed setup, CRUD examples, and federated queries, see [demo/mysql/README.md](demo/mysql/README.md).
370370

371371
### SQLite
372372

@@ -388,7 +388,7 @@ SQLite requires no credentials — just the path to the database file.
388388
skardi query --sql "SELECT * FROM './data/my_database.db.users'"
389389
```
390390

391-
For detailed setup, CRUD examples, and federated queries, see [demo/sqlite/SQLITE_DEMO.md](demo/sqlite/SQLITE_DEMO.md).
391+
For detailed setup, CRUD examples, and federated queries, see [demo/sqlite/README.md](demo/sqlite/README.md).
392392

393393
### MongoDB
394394

@@ -411,7 +411,7 @@ export MONGO_USER="myuser"
411411
export MONGO_PASS="mypassword"
412412
```
413413

414-
For detailed setup, CRUD examples, and federated queries, see [demo/mongo/MONGO_DEMO.md](demo/mongo/MONGO_DEMO.md).
414+
For detailed setup, CRUD examples, and federated queries, see [demo/mongo/README.md](demo/mongo/README.md).
415415

416416
### Redis
417417

@@ -429,7 +429,7 @@ Full CRUD support with point lookups (O(1) via direct key construction), full sc
429429

430430
Redis keys follow the pattern `{key_space}:{table}:{key_column_value}`, where `key_column` is extracted from the key suffix and exposed as a SQL column. For initially empty tables, use the `columns` option to declare the schema upfront so INSERT operations work immediately.
431431

432-
For detailed setup, CRUD examples, and federated queries, see [demo/redis/REDIS_DEMO.md](demo/redis/REDIS_DEMO.md).
432+
For detailed setup, CRUD examples, and federated queries, see [demo/redis/README.md](demo/redis/README.md).
433433

434434
### Apache Iceberg
435435

@@ -458,7 +458,7 @@ For S3-backed Iceberg tables:
458458
aws_secret_access_key_env: "AWS_SECRET_ACCESS_KEY"
459459
```
460460

461-
For detailed setup and examples, see [demo/iceberg/ICEBERG_DEMO.md](demo/iceberg/ICEBERG_DEMO.md).
461+
For detailed setup and examples, see [demo/iceberg/README.md](demo/iceberg/README.md).
462462

463463
### Lance (Vector Search)
464464

@@ -490,7 +490,7 @@ WHERE knn.id != {ref_id}
490490
| 100K vectors | ~500ms | ~8ms | 62x |
491491
| 1M vectors | ~5000ms | ~15ms | 333x |
492492

493-
For full details on vector search, see [demo/lance/LANCE_DEMO.md](demo/lance/LANCE_DEMO.md).
493+
For full details on vector search, see [demo/lance/README.md](demo/lance/README.md).
494494

495495
### S3 Remote Files
496496

@@ -516,7 +516,12 @@ For full S3 configuration, IAM permissions, and troubleshooting, see [demo/S3_US
516516

517517
## ONNX Model Inference
518518

519-
Run ONNX model predictions directly in SQL using the built-in `onnx_predict` scalar UDF. Models are loaded lazily on first use and cached in memory.
519+
> **Note:** ONNX support is behind a feature flag. Build with `--features onnx` to enable it:
520+
> ```bash
521+
> cargo build --release -p skardi-server --features onnx
522+
> ```
523+
524+
Run ONNX model predictions directly in SQL using the `onnx_predict` scalar UDF. Models are loaded lazily on first use and cached in memory.
520525

521526
```sql
522527
onnx_predict('path/to/model.onnx', input1, input2, ...) -> FLOAT
@@ -542,7 +547,7 @@ LIMIT 10
542547

543548
Pre-built models are available in the `models/` directory (`ncf.onnx`, `TinyTimeMixer.onnx`).
544549

545-
For the full guide including the movie recommendation demo, see [demo/onnx_predict/ONNX_PREDICT_DEMO.md](demo/onnx_predict/ONNX_PREDICT_DEMO.md).
550+
For the full guide including the movie recommendation demo, see [demo/onnx_predict/README.md](demo/onnx_predict/README.md).
546551

547552
## Federated Queries
548553

@@ -575,6 +580,9 @@ query: |
575580

576581
```bash
577582
docker build -t skardi .
583+
584+
# With ONNX support
585+
docker build -t skardi --build-arg FEATURES=onnx .
578586
```
579587

580588
### Run with config files mounted
@@ -618,6 +626,9 @@ cargo install --path crates/cli
618626
619627
# Build server
620628
cargo build --release -p skardi-server
629+
630+
# Build server with ONNX model inference support
631+
cargo build --release -p skardi-server --features onnx
621632
```
622633

623634
## Demo & Examples

crates/model/.DS_Store

-8 KB
Binary file not shown.

crates/model/Cargo.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@ repository.workspace = true
88
homepage.workspace = true
99
license.workspace = true
1010

11+
[features]
12+
default = []
13+
onnx = ["dep:ort", "dep:ndarray", "dep:num_cpus"]
14+
1115
[dependencies]
1216
anyhow = { workspace = true }
1317
arrow = { workspace = true }
1418
datafusion = { workspace = true }
1519
log = { workspace = true }
16-
ndarray = "0.17"
17-
num_cpus = "1.17.0"
18-
ort = { version = "2.0.0-rc.12", default-features = false, features = ["std", "ndarray", "download-binaries", "tls-rustls"] }
20+
ndarray = { version = "0.17", optional = true }
21+
num_cpus = { version = "1.17.0", optional = true }
22+
ort = { version = "2.0.0-rc.12", default-features = false, features = ["std", "ndarray", "download-binaries", "tls-rustls"], optional = true }
1923
tokio = {workspace = true, features = ["macros", "rt-multi-thread", "sync"]}
2024
tracing = { workspace = true }
2125

crates/model/examples/.DS_Store

-8 KB
Binary file not shown.

crates/model/examples/demo.rs

Lines changed: 0 additions & 74 deletions
This file was deleted.

crates/model/examples/ncf_demo.rs

Lines changed: 0 additions & 80 deletions
This file was deleted.

crates/model/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
#[cfg(feature = "onnx")]
12
pub mod converter;
2-
pub mod linear;
33
pub mod model;
4+
#[cfg(feature = "onnx")]
45
pub mod onnx;
56

67
// Re-export for convenience
8+
#[cfg(feature = "onnx")]
79
pub use onnx::OnnxModelRegistry;

0 commit comments

Comments
 (0)