Skip to content
This repository was archived by the owner on Nov 23, 2025. It is now read-only.
/ local-inference Public archive

A reference implementation of a local-first, AI-powered semantic layer built on DuckDB and Rust. Run zero-shot tabular predictions directly in SQL, providing an open-source blueprint for in-database machine learning.

Notifications You must be signed in to change notification settings

sbdk-dev/local-inference

Repository files navigation

Mallard

🦆 Local-First Semantic Layer for AI-Powered Analytics 🚀

Snowflake Cortex for Local-First Databases.
Run powerful, zero-shot tabular predictions directly in your database with simple SQL.
No data movement, no complex pipelines—just ML-powered insights right where your data lives.

License Status Version


Note: This project is archived as of November 2025 as a complete reference implementation. It demonstrates best practices for building a local-first semantic layer for AI analytics, but it is not under active development.

The Vision: Zero-Shot Tabular Predictions via SQL

Imagine running churn predictions on your customer data with a single line of SQL:

-- The entire vision in one line:
SELECT customer_id, predict_churn(*) FROM customers;

Mallard makes this a reality by leveraging foundation models that adapt to any tabular schema, enabling zero-shot predictions without the need for model training or complex feature engineering. It's designed for data engineers, BI analysts, and developers who need to integrate ML insights into their workflows with minimal friction.

Key Features

  • 🎯 Zero-Shot Predictions: Use powerful foundation models (TabPFN, FT-Transformer) for classification and regression on any tabular dataset, without training.
  • 🤖 Simple SQL Interface: All functionality is exposed through declarative SQL UDFs. If you know SQL, you know Mallard.
  • ⚡ High-Performance & Local-First: Built in Rust 🦀 as a DuckDB extension. All processing happens in-database, eliminating data transfer overhead and ensuring privacy.
  • 🔮 Automatic Feature Engineering: Mallard introspects your table schema and automatically selects and preprocesses features for inference.
  • ✨ Embeddings & Explainability: Generate dense vector embeddings for semantic search and get feature importance explanations for every prediction.
  • 📦 ONNX-Native: Load and manage any ONNX-compatible model directly from SQL.

Architecture

Mallard is built on a modern, high-performance, local-first stack. It integrates directly into DuckDB as an extension.

┌───────────────────┐      ┌────────────────────────┐      ┌──────────────────────┐
│                   │      │                        │      │                      │
│   SQL Interface   ├─────►│  Mallard DuckDB Ext.   ├─────►│  ONNX Runtime (C-API)│
│    (DuckDB)       │      │        (Rust)          │      │                      │
│                   │      │                        │      │                      │
└───────────────────┘      └──────────┬─────────────┘      └──────────┬───────────┘
                                      │                               │
                                      │                               │
                                      ▼                               ▼
                           ┌───────────────────┐           ┌──────────────────────┐
                           │                   │           │                      │
                           │ Schema Introspection &      │  Foundation Models   │
                           │  Auto-Preprocessing        │  (TabPFN, FT-Transformer)    │
                           │                   │           │                      │
                           └───────────────────┘           └──────────────────────┘

Quick Start

Get up and running with Mallard in just a few steps.

Prerequisites:

  • Rust (stable toolchain)
  • Python 3.9+ (uv package manager recommended)
  • A C/C++ compiler toolchain
  1. Clone the Repository:

    git clone https://github.com/sbdk-dev/local-inference.git
    cd local-inference
  2. Build the DuckDB Extension:

    cd mallard-core
    cargo build --release

    The compiled extension will be at target/release/libmallard_core.so (or .dll/.dylib).

  3. Run an Example Query: Start DuckDB and load the Mallard extension to run a prediction.

    duckdb
    
    # Load the extension (use the correct path)
    D LOAD './mallard-core/target/release/libmallard_core.so';
    
    # Run a zero-shot classification on the Iris dataset
    D SELECT predict_classification('tabpfn', *) FROM 'data/iris.csv';

Example Usage

Mallard's SQL API is designed to be intuitive and composable.

Basic Prediction

Get churn predictions for customers, letting Mallard automatically select the relevant features.

SELECT
    customer_id,
    predict_classification('churn_model', *) AS churn_probability
FROM customers
WHERE churn_probability > 0.8;

Generating Embeddings

Create embeddings for semantic search or downstream AI tasks.

ALTER TABLE customers ADD COLUMN embedding FLOAT[256];

UPDATE customers
SET embedding = embed_tabular('customer_encoder', *);

Getting Explanations

Understand why a model made a certain prediction with feature importance scores.

SELECT
    customer_id,
    predict_classification('churn_model', *) AS churn_prob,
    explain_prediction('churn_model', *) AS explanation
FROM customers;

Contributing

This project is archived, so we are not accepting contributions. However, you are welcome to fork the repository and build upon it for your own use cases.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

A reference implementation of a local-first, AI-powered semantic layer built on DuckDB and Rust. Run zero-shot tabular predictions directly in SQL, providing an open-source blueprint for in-database machine learning.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published