Skip to content

Commit 8aa8f5e

Browse files
authored
Update the quickstart section (#12)
1 parent f68854b commit 8aa8f5e

File tree

15 files changed

+77
-47
lines changed

15 files changed

+77
-47
lines changed

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
blank_issues_enabled: true
1+
blank_issues_enabled: false
2+
contact_links:
3+
- name: Discussions
4+
url: https://github.com/CogitatorTech/infera/discussions
5+
about: Please ask and answer general questions here

.github/workflows/dist_pipeline.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: Build Extension Binaries
22
on:
33
workflow_dispatch:
4+
pull_request:
5+
branches:
6+
- main
47
push:
58
tags:
69
- 'v*'

Makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,17 @@ rust-coverage: ## Generate code coverage report for Infera crate
6161
.PHONY: rust-lint
6262
rust-lint: rust-format ## Run linter checks on Rust files
6363
@echo "Linting Rust files..."
64-
@cargo clippy --manifest-path infera/Cargo.toml --features "tract" -- -D warnings
64+
@cargo clippy --manifest-path infera/Cargo.toml --features "tract" -- -D warnings -D clippy::unwrap_used -D clippy::expect_used
6565

6666
.PHONY: rust-fix-lint
6767
rust-fix-lint: ## Fix Rust linter warnings
6868
@echo "Fixing linter warnings..."
69-
@cargo clippy --fix --allow-dirty --allow-staged --manifest-path infera/Cargo.toml --features "tract" -- -D warnings
69+
@cargo clippy --fix --allow-dirty --allow-staged --manifest-path infera/Cargo.toml --features "tract" -- -D warnings -D clippy::unwrap_used -D clippy::expect_used
70+
71+
.PHONY: rust-careful
72+
careful: ## Run security checks on Rust code
73+
@echo "Running security checks..."
74+
@cargo careful
7075

7176
.PHONY: rust-clean
7277
rust-clean: ## Clean Rust build artifacts
@@ -110,7 +115,7 @@ install-deps: ## Set up development environment (for Debian-based systems)
110115
@echo "Setting up development environment..."
111116
@sudo apt-get install -y cmake clang-format snap python3-pip
112117
@sudo snap install rustup --classic
113-
@cargo install cargo-tarpaulin cbindgen cargo-edit cargo-audit cargo-outdated
118+
@cargo install cargo-tarpaulin cbindgen cargo-edit cargo-audit cargo-outdated cargo-careful
114119
@cd infera && cargo check --features "tract"
115120
@git submodule update --init --recursive
116121
@pip install --user --upgrade pip uv

README.md

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ See the [ROADMAP.md](ROADMAP.md) for the list of implemented and planned feature
5555

5656
### Quickstart
5757

58+
#### Install from Community Extensions Repository
59+
60+
You can install and load Infera from
61+
the [DuckDB community extensions](https://duckdb.org/community_extensions/extensions/infera) repository by running the
62+
following SQL commands in the DuckDB shell:
63+
64+
```sql
65+
install infera from community;
66+
load infera;
67+
```
68+
69+
#### Build from Source
70+
71+
Alternatively, you can build Infera from source and use it by following these steps:
72+
5873
1. Clone the repository and build the Infera extension from source:
5974

6075
```bash
@@ -71,13 +86,21 @@ make release
7186
./build/release/duckdb
7287
```
7388

74-
3. Run the following SQL commands in the shell to try Infera out:
89+
> [!NOTE]
90+
> After building from source, the Infera binary will be `build/release/extension/infera/infera.duckdb_extension`.
91+
> You can load it using the `load 'build/release/extension/infera/infera.duckdb_extension';` in the DuckDB shell.
92+
> Note that the extension binary will only work with the DuckDB version that it was built against.
93+
> You can download the pre-built binaries from the [releases page](https://github.com/CogitatorTech/infera/releases) for
94+
> your platform.
95+
96+
97+
#### Trying Infera
7598

7699
```sql
77-
-- Normally, we need to load the extension first,
78-
-- but the `duckdb` binary that we built in the previous step
79-
-- already has Infera statically linked to it.
80-
-- So, we don't need to load the extension explicitly.
100+
-- 0. Install and load Infera
101+
-- Skip this step if you built from source and ran `./build/release/duckdb`
102+
install infera from community;
103+
load infera;
81104

82105
-- 1. Load a simple linear model from a remote URL
83106
select infera_load_model('linear_model',
@@ -93,21 +116,10 @@ select infera_unload_model('linear_model');
93116

94117
-- 4. Check the Infera version
95118
select infera_get_version();
96-
````
119+
```
97120

98121
[![Simple Demo 1](https://asciinema.org/a/745806.svg)](https://asciinema.org/a/745806)
99122

100-
> [!NOTE]
101-
> After building from source, the Infera binary will be `build/release/extension/infera/infera.duckdb_extension`.
102-
> You can load it using the `load 'build/release/extension/infera/infera.duckdb_extension';` in the DuckDB shell.
103-
> Note that the extension binary will only work with the DuckDB version that it was built against.
104-
> At the moment, Infera is not available as
105-
> a [DuckDB community extension](https://duckdb.org/community_extensions/list_of_extensions).
106-
> Nevertheless, you can still use Infera by building it from source yourself, or downloading pre-built binaries from
107-
> the [releases page](https://github.com/CogitatorTech/infera/releases) for your platform.
108-
> Please check the [this page](https://duckdb.org/docs/stable/extensions/installing_extensions.html) for more details on
109-
> how to use extensions in DuckDB.
110-
111123
---
112124

113125
### Documentation

docs/README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22

33
The table below includes the information about all SQL functions exposed by Infera.
44

5-
| # | Function | Return Type | Description |
6-
|----|:-------------------------------------------------------------|:-----------------|:--------------------------------------------------------------------------------------------------------------------------------------------|
7-
| 1 | `infera_load_model(name VARCHAR, path_or_url VARCHAR)` | `BOOLEAN` | Loads an ONNX model from a local file path or a remote URL and assigns it a unique name. Returns `true` on success. |
8-
| 2 | `infera_unload_model(name VARCHAR)` | `BOOLEAN` | Unloads a model, freeing its associated resources. Returns `true` on success. |
9-
| 3 | `infera_set_autoload_dir(path VARCHAR)` | `VARCHAR (JSON)` | Scans a directory for `.onnx` files, loads them automatically, and returns a JSON report of loaded models and any errors. |
10-
| 4 | `infera_get_loaded_models()` | `VARCHAR (JSON)` | Returns a JSON array containing the names of all currently loaded models. |
5+
| # | Function | Return Type | Description |
6+
|----|:-------------------------------------------------------------|:-----------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------|
7+
| 1 | `infera_load_model(name VARCHAR, path_or_url VARCHAR)` | `BOOLEAN` | Loads an ONNX model from a local file path or a remote URL and assigns it a unique name. Returns `true` on success. |
8+
| 2 | `infera_unload_model(name VARCHAR)` | `BOOLEAN` | Unloads a model, freeing its associated resources. Returns `true` on success. |
9+
| 3 | `infera_set_autoload_dir(path VARCHAR)` | `VARCHAR (JSON)` | Scans a directory for `.onnx` files, loads them automatically, and returns a JSON report of loaded models and any errors. |
10+
| 4 | `infera_get_loaded_models()` | `VARCHAR (JSON)` | Returns a JSON array containing the names of all currently loaded models. |
1111
| 5 | `infera_get_model_info(name VARCHAR)` | `VARCHAR (JSON)` | Returns a JSON object with metadata about a specific loaded model (name, input/output shapes). If the model is not loaded, this function raises an error. |
12-
| 6 | `infera_predict(name VARCHAR, features... FLOAT)` | `FLOAT` | Performs inference on a batch of data, returning a single float value for each input row. |
13-
| 7 | `infera_predict_multi(name VARCHAR, features... FLOAT)` | `VARCHAR (JSON)` | Performs inference and returns all outputs as a JSON-encoded array. This is useful for models that produce multiple predictions per sample. |
14-
| 8 | `infera_predict_multi_list(name VARCHAR, features... FLOAT)` | `LIST[FLOAT]` | Performs inference and returns all outputs as a typed list of floats. Useful for multi-output models without JSON parsing. |
15-
| 9 | `infera_predict_from_blob(name VARCHAR, data BLOB)` | `LIST[FLOAT]` | Performs inference on raw `BLOB` data (for example, used for an image tensor), returning the result as a list of floats. |
16-
| 10 | `infera_is_model_loaded(name VARCHAR)` | `BOOLEAN` | Returns `true` if the given model is currently loaded, otherwise `false`. |
17-
| 11 | `infera_get_version()` | `VARCHAR (JSON)` | Returns a JSON object with version and build information for the Infera extension. |
18-
| 12 | `infera_clear_cache()` | `BOOLEAN` | Clears the entire model cache directory, freeing up disk space. Returns `true` on success. |
19-
| 13 | `infera_get_cache_info()` | `VARCHAR (JSON)` | Returns cache statistics including directory path, total size in bytes, file count, and configured size limit. |
12+
| 6 | `infera_predict(name VARCHAR, features... FLOAT)` | `FLOAT` | Performs inference on a batch of data, returning a single float value for each input row. |
13+
| 7 | `infera_predict_multi(name VARCHAR, features... FLOAT)` | `VARCHAR (JSON)` | Performs inference and returns all outputs as a JSON-encoded array. This is useful for models that produce multiple predictions per sample. |
14+
| 8 | `infera_predict_multi_list(name VARCHAR, features... FLOAT)` | `LIST[FLOAT]` | Performs inference and returns all outputs as a typed list of floats. Useful for multi-output models without JSON parsing. |
15+
| 9 | `infera_predict_from_blob(name VARCHAR, data BLOB)` | `LIST[FLOAT]` | Performs inference on raw `BLOB` data (for example, used for an image tensor), returning the result as a list of floats. |
16+
| 10 | `infera_is_model_loaded(name VARCHAR)` | `BOOLEAN` | Returns `true` if the given model is currently loaded, otherwise `false`. |
17+
| 11 | `infera_get_version()` | `VARCHAR (JSON)` | Returns a JSON object with version and build information for the Infera extension. |
18+
| 12 | `infera_clear_cache()` | `BOOLEAN` | Clears the entire model cache directory, freeing up disk space. Returns `true` on success. |
19+
| 13 | `infera_get_cache_info()` | `VARCHAR (JSON)` | Returns cache statistics including directory path, total size in bytes, file count, and configured size limit. |
2020

2121
> [!NOTE]
2222
> The `features...` arguments accept `FLOAT` as well as values from `DOUBLE`, `INTEGER`, `BIGINT`, and `DECIMAL`

infera/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "infera"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
edition = "2021"
55
publish = false
66

infera/bindings/infera_extension.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ static void LoadInternal(ExtensionLoader &loader) {
527527

528528
void InferaExtension::Load(ExtensionLoader &loader) { LoadInternal(loader); }
529529
std::string InferaExtension::Name() { return "infera"; }
530-
std::string InferaExtension::Version() const { return "v0.2.0"; }
530+
std::string InferaExtension::Version() const { return "v0.3.0"; }
531531

532532
} // namespace duckdb
533533

infera/src/config.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// src/config.rs
21
// Centralized configuration management for Infera
32

43
use once_cell::sync::Lazy;

infera/src/engine.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// src/engine.rs
21
// Contains the core ONNX inference logic using the Tract library.
32

43
use crate::error::InferaError;
@@ -213,7 +212,11 @@ pub(crate) fn run_inference_blob_impl(
213212
let blob_bytes = unsafe { std::slice::from_raw_parts(blob_data, blob_len) };
214213
let float_vec: Vec<f32> = blob_bytes
215214
.chunks_exact(4)
216-
.map(|chunk| f32::from_ne_bytes(chunk.try_into().unwrap()))
215+
.map(|chunk| {
216+
// SAFETY: chunks_exact(4) guarantees exactly 4 bytes, so this conversion cannot fail
217+
let array: [u8; 4] = chunk.try_into().unwrap_or_default();
218+
f32::from_ne_bytes(array)
219+
})
217220
.collect();
218221
let expected_elements: usize = model
219222
.input_shape

infera/src/error.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// src/error.rs
21
// Contains the InferaError enum and thread-local error handling logic.
32

43
use std::cell::RefCell;

0 commit comments

Comments
 (0)