infera
Eine DuckDB-Erweiterung für In-Database-Inferenz
Maintainer: habedi
Installation und Laden
INSTALL infera FROM community;LOAD infera;Beispiel
-- 0. Assuming the extension is already installed and loaded
-- 1. Load a simple linear model from a remote URLSELECT infera_load_model('linear_model','https://github.com/CogitatorTech/infera/raw/refs/heads/main/test/models/linear.onnx');
-- 2. Run a prediction using a very simple linear model-- Model: y = 2*x1 - 1*x2 + 0.5*x3 + 0.25SELECT infera_predict('linear_model', 1.0, 2.0, 3.0);-- Expected output: 1.75
-- 3. Unload the model when we're done with itSELECT infera_unload_model('linear_model');
-- 4. Check the Infera versionSELECT infera_get_version();Über infera
Die Infera-Erweiterung ermöglicht es Ihnen, Machine-Learning-Modelle direkt in SQL-Abfragen zu verwenden, um Inferenz auf in DuckDB-Tabellen gespeicherten Daten auszuführen. Sie ist in Rust entwickelt und verwendet Tract als Inferenz-Engine im Backend. Infera unterstützt das Laden und Ausführen von Modellen im ONNX-Format. Eine große Sammlung einsatzbereiter Modelle für Infera finden Sie im Repository ONNX Model Zoo auf Hugging Face.
Weitere Informationen, etwa API-Referenzen und Verwendungsbeispiele, finden Sie im GitHub-Repository des Projekts.
Hinzugefügte Funktionen
| function_name | function_type | description | comment | examples |
|---|---|---|---|---|
| infera_load_model | scalar | Load an ONNX model from a local file path or a remote URL and assign it a unique name. | Supports local paths and remote URLs; caches remote models. | [select infera_load_model(‘local_model’,‘/path/to/model.onnx’);] |
| infera_unload_model | scalar | Unload a model, freeing its associated resources. | Returns true on success. | [select infera_unload_model(‘local_model’);] |
| infera_set_autoload_dir | scalar | Scan a directory for .onnx files, load them automatically, and return a JSON report. | Returns JSON with loaded models and any errors. | [select infera_set_autoload_dir(‘path/to/your/models’);] |
| infera_get_loaded_models | scalar | Return a JSON array containing the names of all currently loaded models. | JSON array of model names. | [select infera_get_loaded_models();] |
| infera_get_model_info | scalar | Return a JSON object with metadata for a specific loaded model (name, input/output shapes). | Throws an error if the model is not loaded. | [select infera_get_model_info(‘local_model’);] |
| infera_predict | scalar | Perform inference on a batch of data; returns a single float value per input row. | Features accept FLOAT, DOUBLE, INTEGER, BIGINT, DECIMAL (cast to float). | [select infera_predict(‘my_model’, 1.0, 2.5, 3.0) as prediction;] |
| infera_predict_multi | scalar | Perform inference and return all outputs as a JSON-encoded array. | Useful for models that produce multiple predictions per sample. | [select infera_predict_multi(‘multi_output_model’, 1.0, 2.0);] |
| infera_predict_multi_list | scalar | Perform inference and return outputs as a typed LIST[FLOAT]. | Avoids JSON parsing for multi-output models. | [select infera_predict_multi_list(‘multi_output_model’, 1.0, 2.0);] |
| infera_predict_from_blob | scalar | Perform inference on raw BLOB data (e.g., image tensor); returns LIST[FLOAT]. | Accepts raw tensor BLOB data from a column. | [select infera_predict_from_blob(‘my_model’, my_blob_column) from my_table;] |
| infera_is_model_loaded | scalar | Return true if the given model is currently loaded, otherwise false. | NULL | [select infera_is_model_loaded(‘squeezenet’);] |
| infera_get_version | scalar | Return a JSON object with version and build information for the Infera extension. | NULL | [select infera_get_version();] |
| infera_clear_cache | scalar | Clear the entire model cache directory to free up disk space. | Returns true on success. | [select infera_clear_cache();] |
| infera_get_cache_info | scalar | Return cache statistics: directory path, total size in bytes, file count, and configured size limit. | Returns JSON with cache fields. | [select infera_get_cache_info();] |
Überladene Funktionen
Diese Erweiterung fügt keine Funktionsüberladungen hinzu.
Hinzugefügte Typen
Diese Erweiterung fügt keine Typen hinzu.
Hinzugefügte Einstellungen
Diese Erweiterung fügt keine Einstellungen hinzu.