Skip to content

AI-native extension for SQLite that brings on-device inference, embedding generation, and model interaction directly into your database.

License

Notifications You must be signed in to change notification settings

sqliteai/sqlite-ai

Repository files navigation

SQLite-AI

SQLite-AI is an extension for SQLite that brings artificial intelligence capabilities directly into the database. It enables developers to run, fine-tune, and serve AI models from within SQLite using simple SQL queries — ideal for on-device and edge applications where low-latency and offline inference are critical. The extension is actively developed by SQLite AI, some API and features are still evolving.

Features

  • Embedded AI Inference: Run transformer models directly from SQL queries.
  • Streaming I/O: Token-by-token streaming via SQL aggregate functions.
  • Fine-tuning & Embedding: On-device model customization and vector embedding.
  • Full On-Device Support: Works on iOS, Android, Linux, macOS, and Windows.
  • Offline-First: No server dependencies or internet connection required.
  • Composable SQL Interface: AI + relational logic in a single unified layer.
  • Supports any GGUF model: available on Huggingface; Qwen, Gemma, Llama, DeepSeek and more

SQLite-AI supports text embedding generation for search and classification, a chat-like interface with history and token streaming, and automatic context save and restore across sessions — making it ideal for building conversational agents and memory-aware assistants. Support for multimodal (sound and image understanding) is coming soon, bringing even richer on-device intelligence.

Documentation

For detailed information on all available functions, their parameters, and examples, refer to the comprehensive API Reference.

Installation

Pre-built Binaries

Download the appropriate pre-built binary for your platform from the official Releases page:

  • Linux: x86 and ARM
  • macOS: x86 and ARM
  • Windows: x86
  • Android
  • iOS

Swift Package

You can add this repository as a package dependency to your Swift project. After adding the package, you'll need to set up SQLite with extension loading by following steps 4 and 5 of this guide.

Here's an example of how to use the package:

import ai

...

var db: OpaquePointer?
sqlite3_open(":memory:", &db)
sqlite3_enable_load_extension(db, 1)
var errMsg: UnsafeMutablePointer<Int8>? = nil
sqlite3_load_extension(db, ai.path, nil, &errMsg)
var stmt: OpaquePointer?
sqlite3_prepare_v2(db, "SELECT ai_version()", -1, &stmt, nil)
defer { sqlite3_finalize(stmt) }
sqlite3_step(stmt)
log("ai_version(): \(String(cString: sqlite3_column_text(stmt, 0)))")
sqlite3_close(db)

Python Package

Python developers can quickly get started using the ready-to-use sqlite-ai package available on PyPI:

pip install sqlite-ai

For usage details and examples, see the Python package documentation.

Loading the Extension

-- In SQLite CLI
.load ./ai

-- In SQL
SELECT load_extension('./ai');

Getting Started

Here's a quick example to get started with SQLite Sync:

# Start SQLite CLI
sqlite3 myapp.db
-- Load the extension
.load ./ai

-- Load a model
SELECT llm_model_load('models/llama-2-7b.gguf', 'context_size=4096,n_gpu_layers=99');

-- Run inference
SELECT llm_text_generate('What is the most beautiful city in Italy?');

📦 Integrations

Use SQLite-AI alongside:


License

This project is licensed under the Elastic License 2.0. You can use, copy, modify, and distribute it under the terms of the license for non-production use. For production or managed service use, please contact SQLite Cloud, Inc for a commercial license.

About

AI-native extension for SQLite that brings on-device inference, embedding generation, and model interaction directly into your database.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •