# sqlite-vec

> A small SQLite extension for vector storage and similarity search that runs anywhere SQLite runs

- Category: Retrieval & Knowledge (RAG) / Vector Databases
- Language: C
- Repository: https://github.com/asg017/sqlite-vec
- Website: https://alexgarcia.xyz/sqlite-vec/
- Canonical page: https://ai-tldr.dev/tools/sqlite-vec/

## In short

sqlite-vec is a SQLite extension, written in pure C with no dependencies, that adds vector storage and similarity search to any SQLite database. You define a vec0 virtual table, insert float, int8, or binary vectors, and run nearest-neighbor (KNN) queries directly in SQL. It is a successor to the earlier sqlite-vss project. It sits in the Vector Databases category of the Retrieval & Knowledge (RAG) tools and is open-source, written in C.

## Overview

sqlite-vec is a SQLite extension, written in pure C with no dependencies, that adds vector storage and similarity search to any SQLite database. You define a vec0 virtual table, insert float, int8, or binary vectors, and run nearest-neighbor (KNN) queries directly in SQL. It is a successor to the earlier sqlite-vss project.

Because it ships as a small C extension, it runs anywhere SQLite runs: Linux, macOS, Windows, Raspberry Pis, and the browser via WebAssembly. There are install packages for Python, Node.js, Ruby, Go, Rust, Datasette, rqlite, and sqlite-utils, so you can add vector search without standing up a separate database service.

It fits the embedded / in-process vector database category: the index lives inside your SQLite file alongside your regular tables, which suits local-first apps, edge deployments, and projects that already use SQLite. Note that sqlite-vec is pre-v1, so the project warns to expect breaking changes.

## What it does

- Stores float, int8, and binary vectors in vec0 virtual tables
- KNN similarity search expressed in plain SQL with a MATCH clause ordered by distance
- Written in pure C with no dependencies; runs on Linux, macOS, Windows, Raspberry Pi, and in the browser via WASM
- Accepts vectors as JSON arrays or a compact binary format
- Keeps non-vector data in metadata, auxiliary, or partition key columns
- Official bindings for Python, Node.js, Ruby, Go, Rust, plus Datasette, rqlite, and sqlite-utils plugins

## Getting started

Install sqlite-vec for your language, then create a vec0 virtual table and run a KNN query in SQL.

1. Install

   Add sqlite-vec with your language's package manager. The Python package is shown here; npm, gem, cargo, and go get are also available.

```bash
pip install sqlite-vec
```

2. Load the extension and create a table

   Load the vec0 extension into SQLite and create a virtual table that holds an 8-dimensional float vector column.

```sql
.load ./vec0

create virtual table vec_examples using vec0(
  sample_embedding float[8]
);
```

3. Insert vectors

   Insert rows with vectors provided as JSON. A compact binary format is also supported.

```sql
insert into vec_examples(rowid, sample_embedding)
  values
    (1, '[-0.200, 0.250, 0.341, -0.211, 0.645, 0.935, -0.316, -0.924]'),
    (2, '[0.443, -0.501, 0.355, -0.771, 0.707, -0.708, -0.185, 0.362]');
```

4. Run a KNN query

   Use a MATCH clause with order by distance and a limit to find the nearest vectors to a query vector.

```sql
select
  rowid,
  distance
from vec_examples
where sample_embedding match '[0.890, 0.544, 0.825, 0.961, 0.358, 0.0196, 0.521, 0.175]'
order by distance
limit 2;
```

## When to use it

- Add semantic search or retrieval to an app that already uses SQLite, without running a separate vector database
- Build local-first or offline AI features where the vector index ships inside the SQLite file
- Run vector search in the browser via WebAssembly or on resource-constrained hardware like a Raspberry Pi
- Power RAG retrieval at the edge by storing embeddings next to your application data
