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.
- 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.
For detailed information on all available functions, their parameters, and examples, refer to the comprehensive API Reference.
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
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 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.
-- In SQLite CLI
.load ./ai
-- In SQL
SELECT load_extension('./ai');
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?');
Use SQLite-AI alongside:
- SQLite-Vector – vector search from SQL
- SQLite-Sync – sync on-device databases with the cloud
- SQLite-JS – define SQLite functions in JavaScript
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.