2024-04-20 13:38:58 -07:00
# `sqlite-vec`
2024-08-01 02:45:36 -07:00
[](https://discord.gg/Ve7WeCJFXk)
2024-06-12 00:08:53 -07:00
2024-04-20 13:38:58 -07:00
An extremely small, "fast enough" vector search SQLite extension that runs
2024-08-01 02:45:36 -07:00
anywhere! A successor to [`sqlite-vss` ](https://github.com/asg017/sqlite-vss )
2024-04-20 13:38:58 -07:00
2024-06-12 00:13:56 -07:00
<!-- deno - fmt - ignore - start -->
> [!IMPORTANT]
2024-08-01 02:45:36 -07:00
> _`sqlite-vec` is a pre-v1, so expect breaking changes!_
2024-06-12 00:13:56 -07:00
<!-- deno - fmt - ignore - end -->
2024-04-20 13:38:58 -07:00
- Store and query float, int8, and binary vectors in `vec0` virtual tables
2024-06-12 00:13:56 -07:00
- Written in pure C, no dependencies, runs anywhere SQLite runs
(Linux/MacOS/Windows, in the browser with WASM, Raspberry Pis, etc.)
2024-08-01 02:45:36 -07:00
- Pre-filter vectors with `rowid IN (...)` subqueries
2024-04-20 13:38:58 -07:00
2024-06-12 00:08:53 -07:00
< p align = "center" >
2024-06-25 08:41:42 -07:00
< a href = "https://hacks.mozilla.org/2024/06/sponsoring-sqlite-vec-to-enable-more-powerful-local-ai-applications/" >
2024-06-12 13:48:34 -07:00
< picture >
< source media = "(prefers-color-scheme: dark)" srcset = "./.github/logos/mozilla.dark.svg" >
< source media = "(prefers-color-scheme: light)" srcset = "./.github/logos/mozilla.svg" >
< img alt = "Mozilla Builders logo" width = 400 >
< / picture >
2024-06-25 08:41:42 -07:00
< / a >
2024-06-12 00:08:53 -07:00
< / p >
< p align = "center" >
< i >
< code > sqlite-vec< / code > is a
2024-06-25 08:41:42 -07:00
< a href = "https://hacks.mozilla.org/2024/06/sponsoring-sqlite-vec-to-enable-more-powerful-local-ai-applications/" > Mozilla Builders project< / a > ,
2024-06-12 00:08:53 -07:00
with additional sponsorship from
< a href = "https://fly.io/" > < img width = 14px src = "./.github/logos/flyio.small.ico" / > Fly.io < / a > ,
2024-08-05 14:14:40 -04:00
< a href = "https://tur.so/sqlite-vec" > < img width = 14px src = "./.github/logos/turso.small.ico" / > Turso< / a > , and
2024-06-12 00:08:53 -07:00
< a href = "https://sqlitecloud.io/" > < img width = 14px src = "./.github/logos/sqlitecloud.small.svg" / > SQLite Cloud< / a > .
See < a href = " #sponsors " > the Sponsors section</ a > for more details.
< / i >
< / p >
2024-06-22 16:46:33 -07:00
## Installing
2024-08-08 02:10:56 +02:00
See [Installing `sqlite-vec` ](https://alexgarcia.xyz/sqlite-vec/installation.html )
2024-06-22 16:46:33 -07:00
for more details.
| Language | Install | More Info | |
| -------------- | ---------------------------------------------------- | ------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Python | `pip install sqlite-vec` | [`sqlite-vec` with Python ](https://alexgarcia.xyz/sqlite-vec/python.html ) | [](https://pypi.org/project/sqlite-vec/) |
2024-08-08 08:10:31 +08:00
| Node.js | `npm install sqlite-vec` | [`sqlite-vec` with Node.js ](https://alexgarcia.xyz/sqlite-vec/js.html ) | [](https://www.npmjs.com/package/sqlite-vec) |
2024-08-01 02:45:36 -07:00
| Ruby | `gem install sqlite-vec` | [`sqlite-vec` with Ruby ](https://alexgarcia.xyz/sqlite-vec/ruby.html ) |  |
| Go | `go get -u github.com/asg017/sqlite-vec/bindings/go` | [`sqlite-vec` with Go ](https://alexgarcia.xyz/sqlite-vec/go.html ) | [](https://pkg.go.dev/github.com/asg017/asg017/sqlite-vec-go-bindings/cgo) |
2024-06-22 16:46:33 -07:00
| Rust | `cargo add sqlite-vec` | [`sqlite-vec` with Rust ](https://alexgarcia.xyz/sqlite-vec/rust.html ) | [](https://crates.io/crates/sqlite-vec) |
| Datasette | `datasette install datasette-sqlite-vec` | [`sqlite-vec` with Datasette ](https://alexgarcia.xyz/sqlite-vec/datasette.html ) | [](https://datasette.io/plugins/datasette-sqlite-vec) |
| `sqlite-utils` | `sqlite-utils install sqlite-utils-sqlite-vec` | [`sqlite-vec` with sqlite-utils ](https://alexgarcia.xyz/sqlite-vec/sqlite-utils.html ) | [](https://datasette.io/plugins/datasette-sqlite-vec) |
| Github Release | | |  |
2024-04-20 13:38:58 -07:00
## Sample usage
```sql
.load ./vec0
create virtual table vec_examples using vec0(
sample_embedding float[8]
);
-- vectors can be provided as JSON or in a compact binary format
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]'),
(3, '[0.716, -0.927, 0.134, 0.052, -0.669, 0.793, -0.634, -0.162]'),
(4, '[-0.710, 0.330, 0.656, 0.041, -0.990, 0.726, 0.385, -0.958]');
2024-08-01 02:45:36 -07:00
-- KNN style query
2024-04-20 13:38:58 -07:00
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;
/*
┌───────┬──────────────────┐
│ rowid │ distance │
├───────┼──────────────────┤
│ 2 │ 2.38687372207642 │
│ 1 │ 2.38978505134583 │
└───────┴──────────────────┘
*/
```
2024-06-12 10:45:59 -07:00
## Sponsors
2024-06-12 00:08:53 -07:00
2024-06-12 00:13:56 -07:00
Development of `sqlite-vec` is supported by multiple generous sponsors! Mozilla
is the main sponsor through the new Builders project.
2024-06-12 00:08:53 -07:00
< p align = "center" >
2024-06-25 08:41:42 -07:00
< a href = "https://hacks.mozilla.org/2024/06/sponsoring-sqlite-vec-to-enable-more-powerful-local-ai-applications/" >
2024-06-12 13:48:02 -07:00
< picture >
< source media = "(prefers-color-scheme: dark)" srcset = "./.github/logos/mozilla.dark.svg" >
< source media = "(prefers-color-scheme: light)" srcset = "./.github/logos/mozilla.svg" >
< img alt = "Mozilla Builders logo" width = 400 >
< / picture >
2024-06-25 08:41:42 -07:00
< / a >
2024-06-12 00:08:53 -07:00
< / p >
`sqlite-vec` is also sponsored by the following companies:
2024-06-12 00:23:45 -07:00
< a href = "https://fly.io/" >
2024-06-12 00:27:15 -07:00
< picture >
< source media = "(prefers-color-scheme: dark)" srcset = "./.github/logos/flyio.dark.svg" >
< source media = "(prefers-color-scheme: light)" srcset = "./.github/logos/flyio.svg" >
2024-06-12 13:48:02 -07:00
< img alt = "Fly.io logo" src = "./.github/logos/flyio.svg" width = "32%" >
2024-06-12 00:27:15 -07:00
< / picture >
2024-06-12 00:23:45 -07:00
< / a >
2024-06-12 00:27:15 -07:00
2024-08-05 14:14:40 -04:00
< a href = "https://tur.so/sqlite-vec" >
2024-06-12 00:27:15 -07:00
< picture >
2024-06-12 00:30:10 -07:00
< source media = "(prefers-color-scheme: dark)" srcset = "./.github/logos/turso.svg" >
< source media = "(prefers-color-scheme: light)" srcset = "./.github/logos/turso.svg" >
2024-06-12 13:48:02 -07:00
< img alt = "Turso logo" src = "./.github/logos/turso.svg" width = "32%" >
2024-06-12 00:27:15 -07:00
< / picture >
2024-06-12 00:23:45 -07:00
< / a >
2024-06-12 00:27:15 -07:00
2024-06-12 00:23:45 -07:00
< a href = "https://sqlitecloud.io/" >
2024-06-12 00:27:15 -07:00
< picture >
< source media = "(prefers-color-scheme: dark)" srcset = "./.github/logos/sqlitecloud.dark.svg" >
< source media = "(prefers-color-scheme: light)" srcset = "./.github/logos/sqlitecloud.svg" >
2024-06-12 13:48:02 -07:00
< img alt = "SQLite Cloud logo" src = "./.github/logos/flyio.svg" width = "32%" >
2024-06-12 00:27:15 -07:00
< / picture >
2024-06-12 00:13:56 -07:00
< / a >
2024-06-12 00:08:53 -07:00
2024-06-12 00:13:56 -07:00
As well as multiple individual supporters on
[Github sponsors ](https://github.com/sponsors/asg017/ )!
2024-06-12 00:08:53 -07:00
2024-06-12 00:13:56 -07:00
If your company interested in sponsoring `sqlite-vec` development, send me an
email to get more info: https://alexgarcia.xyz
2024-04-20 13:38:58 -07:00
2024-06-12 00:08:53 -07:00
## See Also
2024-04-20 13:38:58 -07:00
2024-06-12 00:13:56 -07:00
- [**`sqlite-ecosystem`** ](https://github.com/asg017/sqlite-ecosystem ), Maybe
more 3rd party SQLite extensions I've developed
- [**`sqlite-rembed`** ](https://github.com/asg017/sqlite-rembed ), Generate text
embeddings from remote APIs like OpenAI/Nomic/Ollama, meant for testing and
SQL scripts
- [**`sqlite-lembed`** ](https://github.com/asg017/sqlite-lembed ), Generate text
embeddings locally from embedding models in the `.gguf` format