Getting Started with SQLite AI

Overview

SQLite AI is a local-first stack of SQLite extensions for building AI-enabled applications close to the data. It keeps inference, retrieval, memory, analytics, sync, and custom logic inside the same SQLite workflow, so applications can run offline, preserve privacy, and still connect to SQLite Cloud when they need managed sync, auth, or shared infrastructure.

Extension Stack

  • SQLite-AI runs local LLM inference, embeddings, chat, audio transcription, and multimodal image analysis from SQL.
  • SQLite-Memory adds persistent, searchable memory for AI agents with markdown-aware chunking, hybrid vector and FTS search, and optional sync.
  • SQLite-Vector stores embeddings in ordinary SQLite tables and performs fast nearest-neighbor search with quantization support.
  • SQLite-Sync keeps local SQLite databases synchronized across devices and users with CRDT-based conflict resolution.
  • SQLite-Columnar adds column-oriented virtual tables and analytical helpers for fast local OLAP-style queries.
  • SQLite-JS lets you define scalar, aggregate, window, and collation functions in JavaScript.

Common Workflows

Local RAG

-- Generate embeddings with SQLite-AI.
SELECT llm_model_load('./models/nomic-embed-text-v1.5-Q8_0.gguf', 'gpu_layers=99');
SELECT llm_context_create_embedding('embedding_type=FLOAT32');

CREATE TABLE documents (
  id INTEGER PRIMARY KEY,
  body TEXT,
  embedding BLOB
);

INSERT INTO documents (body, embedding)
VALUES (
  'SQLite stores data in a single portable database file.',
  llm_embed_generate('SQLite stores data in a single portable database file.')
);

-- Search them with SQLite-Vector.
SELECT vector_init('documents', 'embedding', 'type=FLOAT32,dimension=768,distance=COSINE');
SELECT vector_quantize('documents', 'embedding');

Agent Memory

SELECT memory_set_model('local', './models/nomic-embed-text-v1.5.Q8_0.gguf');
SELECT memory_add_text('The user prefers concise Python examples.', 'conversation');

SELECT path, snippet, ranking
FROM memory_search
WHERE query = 'what style should I use for code examples?'
ORDER BY ranking DESC;

Offline-First AI Apps

CREATE TABLE notes (
  id TEXT PRIMARY KEY NOT NULL,
  body TEXT NOT NULL DEFAULT ''
);

SELECT cloudsync_init('notes');
INSERT INTO notes VALUES (cloudsync_uuid(), 'Draft generated locally');
SELECT cloudsync_network_sync();

Tools

  • MCP Server connects AI agents and MCP-compatible clients to SQLite Cloud databases.
  • AI-Powered Docs Search shows how to build semantic documentation search with GitHub Actions, SQLite Cloud, and an Edge Function.