@photostructure/sqlite-vec 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +415 -0
- package/dist/.build/shell-new.c +33888 -0
- package/dist/.libs/shell.a +0 -0
- package/dist/.libs/sqlite-vec.a +0 -0
- package/dist/.libs/sqlite3.a +0 -0
- package/dist/.objs/shell.o +0 -0
- package/dist/.objs/sqlite-vec.o +0 -0
- package/dist/.objs/sqlite3.o +0 -0
- package/dist/memory-test +0 -0
- package/dist/sqlite3 +0 -0
- package/dist/test-unit +0 -0
- package/dist/vec0.so +0 -0
- package/index.cjs +74 -0
- package/index.d.ts +13 -0
- package/index.mjs +75 -0
- package/package.json +56 -0
package/README.md
ADDED
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
# `sqlite-vec`
|
|
2
|
+
|
|
3
|
+
[](https://discord.gg/Ve7WeCJFXk)
|
|
4
|
+
|
|
5
|
+
> [!NOTE]
|
|
6
|
+
> **PhotoStructure's Production Fork:** This is [PhotoStructure](https://photostructure.com)'s actively maintained fork of [`asg017/sqlite-vec`](https://github.com/asg017/sqlite-vec), optimized for production use with additional features, comprehensive testing, and ongoing maintenance funded by PhotoStructure Inc.
|
|
7
|
+
>
|
|
8
|
+
> **Credits:** [Alex Garcia](https://github.com/asg017) (original implementation), [Vlad Lasky](https://github.com/vlasky) (community fork with 15+ merged upstream PRs), PhotoStructure Inc. (ongoing maintenance and improvements).
|
|
9
|
+
>
|
|
10
|
+
> **Why this fork exists:**
|
|
11
|
+
> - PhotoStructure depends on sqlite-vec for production vector search in our photo management platform
|
|
12
|
+
> - We've added production-critical features, security hardening, and comprehensive testing
|
|
13
|
+
> - We're committed to maintaining this for as long as PhotoStructure exists
|
|
14
|
+
> - All improvements remain open source (MIT/Apache-2.0) for the community
|
|
15
|
+
>
|
|
16
|
+
> **Fork improvements:**
|
|
17
|
+
> - **Testing:** AddressSanitizer/Valgrind/UBSan integration, 30+ error path tests, memory leak fixes
|
|
18
|
+
> - **Security:** Safe integer parsing, vendor checksum validation, pinned CI actions, OIDC releases
|
|
19
|
+
> - **Node.js:** Alpine/musl + Windows ARM64 prebuilds, bundled binaries (no post-install scripts)
|
|
20
|
+
> - **Features:** Distance constraints, OPTIMIZE command, ALTER TABLE RENAME, GLOB/LIKE operators
|
|
21
|
+
> - **Documentation:** Comprehensive error path coverage, KNN filtering behavior, production deployment guides
|
|
22
|
+
>
|
|
23
|
+
> Maintained by PhotoStructure Inc. Contributions welcome. See [CHANGELOG-mceachen.md](CHANGELOG-mceachen.md) for detailed changes.
|
|
24
|
+
|
|
25
|
+
An extremely small, "fast enough" vector search SQLite extension that runs
|
|
26
|
+
anywhere! A successor to [`sqlite-vss`](https://github.com/asg017/sqlite-vss)
|
|
27
|
+
|
|
28
|
+
<!-- deno-fmt-ignore-start -->
|
|
29
|
+
|
|
30
|
+
> [!IMPORTANT]
|
|
31
|
+
> _`sqlite-vec` is a pre-v1, so expect breaking changes!_
|
|
32
|
+
|
|
33
|
+
<!-- deno-fmt-ignore-end -->
|
|
34
|
+
|
|
35
|
+
- Store and query float, int8, and binary vectors in `vec0` virtual tables
|
|
36
|
+
- Written in pure C, no dependencies, runs anywhere SQLite runs
|
|
37
|
+
(Linux/MacOS/Windows, in the browser with WASM, Raspberry Pis, etc.)
|
|
38
|
+
- Store non-vector data in metadata, auxiliary, or partition key columns
|
|
39
|
+
|
|
40
|
+
<p align="center">
|
|
41
|
+
<a href="https://hacks.mozilla.org/2024/06/sponsoring-sqlite-vec-to-enable-more-powerful-local-ai-applications/">
|
|
42
|
+
<picture>
|
|
43
|
+
<source media="(prefers-color-scheme: dark)" srcset="./.github/logos/mozilla.dark.svg">
|
|
44
|
+
<source media="(prefers-color-scheme: light)" srcset="./.github/logos/mozilla.svg">
|
|
45
|
+
<img alt="Mozilla Builders logo" width=400>
|
|
46
|
+
</picture>
|
|
47
|
+
</a>
|
|
48
|
+
</p>
|
|
49
|
+
|
|
50
|
+
<p align="center">
|
|
51
|
+
<i>
|
|
52
|
+
<code>sqlite-vec</code> is a
|
|
53
|
+
<a href="https://hacks.mozilla.org/2024/06/sponsoring-sqlite-vec-to-enable-more-powerful-local-ai-applications/">Mozilla Builders project</a>,
|
|
54
|
+
with additional sponsorship from
|
|
55
|
+
<a href="https://fly.io/"><img width=14px src="./.github/logos/flyio.small.ico"/> Fly.io </a>,
|
|
56
|
+
<a href="https://tur.so/sqlite-vec"><img width=14px src="./.github/logos/turso.small.ico"/> Turso</a>,
|
|
57
|
+
<a href="https://sqlitecloud.io/"><img width=14px src="./.github/logos/sqlitecloud.small.svg"/> SQLite Cloud</a>, and
|
|
58
|
+
<a href="https://shinkai.com/"><img width=14px src="./.github/logos/shinkai.small.svg"/> Shinkai</a>.
|
|
59
|
+
See <a href="#sponsors">the Sponsors section</a> for more details.
|
|
60
|
+
</i>
|
|
61
|
+
</p>
|
|
62
|
+
|
|
63
|
+
## Installing
|
|
64
|
+
|
|
65
|
+
### From Original Package Registries
|
|
66
|
+
|
|
67
|
+
The original packages on PyPI, npm, RubyGems, and crates.io are maintained by the original author.
|
|
68
|
+
For the latest features from this fork, see "Installing from This Fork" below.
|
|
69
|
+
|
|
70
|
+
| Language | Install | More Info | |
|
|
71
|
+
| -------------- | ---------------------------------------------------- | ------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
72
|
+
| Python | `pip install sqlite-vec` | [`sqlite-vec` with Python](https://alexgarcia.xyz/sqlite-vec/python.html) | [](https://pypi.org/project/sqlite-vec/) |
|
|
73
|
+
| 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) |
|
|
74
|
+
| Ruby | `gem install sqlite-vec` | [`sqlite-vec` with Ruby](https://alexgarcia.xyz/sqlite-vec/ruby.html) |  |
|
|
75
|
+
| Rust | `cargo add sqlite-vec` | [`sqlite-vec` with Rust](https://alexgarcia.xyz/sqlite-vec/rust.html) | [](https://crates.io/crates/sqlite-vec) |
|
|
76
|
+
| Datasette | `datasette install datasette-sqlite-vec` | [`sqlite-vec` with Datasette](https://alexgarcia.xyz/sqlite-vec/datasette.html) | [](https://datasette.io/plugins/datasette-sqlite-vec) |
|
|
77
|
+
| rqlite | `rqlited -extensions-path=sqlite-vec.tar.gz` | [`sqlite-vec` with rqlite](https://alexgarcia.xyz/sqlite-vec/rqlite.html) | [](https://rqlite.io/docs/guides/extensions/) |
|
|
78
|
+
| `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) |
|
|
79
|
+
|
|
80
|
+
### Installing from PhotoStructure's Fork
|
|
81
|
+
|
|
82
|
+
Install directly from npm or GitHub to get PhotoStructure's production-ready fork with additional features and comprehensive testing.
|
|
83
|
+
|
|
84
|
+
#### Node.js (Recommended)
|
|
85
|
+
|
|
86
|
+
PhotoStructure publishes prebuilt binaries to npm for all major platforms:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
npm install @photostructure/sqlite-vec
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
[](https://www.npmjs.com/package/@photostructure/sqlite-vec)
|
|
93
|
+
|
|
94
|
+
**Supported platforms:** Linux (x64, ARM64, musl), macOS (x64, ARM64), Windows (x64, ARM64)
|
|
95
|
+
|
|
96
|
+
#### Other Languages (Build from Source)
|
|
97
|
+
|
|
98
|
+
| Language | Install Latest (main branch) | Install Specific Version |
|
|
99
|
+
|----------|------------------------------|--------------------------|
|
|
100
|
+
| **Go** | `go get github.com/photostructure/sqlite-vec/bindings/go/cgo@main` | `go get github.com/photostructure/sqlite-vec/bindings/go/cgo@v0.4.1` |
|
|
101
|
+
| **Lua** | `luarocks install lsqlite3` then copy [`sqlite_vec.lua`](bindings/lua/) to your project. See [Lua example](/examples/simple-lua/) | Download [`sqlite_vec.lua` at v0.4.1](https://github.com/photostructure/sqlite-vec/blob/v0.4.1/bindings/lua/sqlite_vec.lua) |
|
|
102
|
+
| **Python** | `pip install git+https://github.com/photostructure/sqlite-vec.git` | `pip install git+https://github.com/photostructure/sqlite-vec.git@v0.4.1` |
|
|
103
|
+
| **Ruby** | `gem 'sqlite-vec', git: 'https://github.com/photostructure/sqlite-vec'` | `gem 'sqlite-vec', git: 'https://github.com/photostructure/sqlite-vec', tag: 'v0.4.1'` |
|
|
104
|
+
| **Rust** | `cargo add sqlite-vec --git https://github.com/photostructure/sqlite-vec` | `cargo add sqlite-vec --git https://github.com/photostructure/sqlite-vec --tag v0.4.1` |
|
|
105
|
+
|
|
106
|
+
**Python Note:** Requires Python built with loadable extension support (`--enable-loadable-sqlite-extensions`). If you encounter errors:
|
|
107
|
+
- Use `uv` to create virtual environments (uses system Python with extension support)
|
|
108
|
+
- Or use system Python instead of pyenv/custom builds
|
|
109
|
+
- Or rebuild your Python with `./configure --enable-loadable-sqlite-extensions`
|
|
110
|
+
|
|
111
|
+
**Available version tags:** See [Releases](https://github.com/photostructure/sqlite-vec/releases)
|
|
112
|
+
|
|
113
|
+
#### Build from Source
|
|
114
|
+
|
|
115
|
+
For direct C usage or other languages:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
git clone https://github.com/vlasky/sqlite-vec.git
|
|
119
|
+
cd sqlite-vec
|
|
120
|
+
./scripts/vendor.sh # Download vendored dependencies
|
|
121
|
+
make loadable # Builds dist/vec0.so (or .dylib/.dll)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
#### Not Yet Available
|
|
125
|
+
|
|
126
|
+
- Pre-built binaries via GitHub Releases
|
|
127
|
+
- Package registry publications (PyPI, npm, RubyGems, crates.io)
|
|
128
|
+
- Datasette/sqlite-utils plugins
|
|
129
|
+
|
|
130
|
+
For these, use the original packages until this fork's CI/CD is configured.
|
|
131
|
+
|
|
132
|
+
See the [original documentation](https://alexgarcia.xyz/sqlite-vec/installation.html) for detailed usage information.
|
|
133
|
+
|
|
134
|
+
## Electron
|
|
135
|
+
|
|
136
|
+
The native extension is automatically resolved from `app.asar.unpacked` when running inside a packaged Electron app. You need to configure your build tool to unpack the extension binaries:
|
|
137
|
+
|
|
138
|
+
**electron-builder:**
|
|
139
|
+
|
|
140
|
+
```json
|
|
141
|
+
{
|
|
142
|
+
"asarUnpack": ["node_modules/@mceachen/sqlite-vec/**/*.{so,dylib,dll}"]
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**electron-forge:**
|
|
147
|
+
|
|
148
|
+
```js
|
|
149
|
+
packagerConfig: {
|
|
150
|
+
asar: {
|
|
151
|
+
unpack: "*.{so,dylib,dll}"
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## What's New
|
|
157
|
+
|
|
158
|
+
See [CHANGELOG.md](CHANGELOG.md) for a complete list of improvements, bug fixes, and merged upstream PRs.
|
|
159
|
+
|
|
160
|
+
## Basic Usage
|
|
161
|
+
|
|
162
|
+
**Vector types:** `sqlite-vec` supports three vector types with different trade-offs:
|
|
163
|
+
|
|
164
|
+
```sql
|
|
165
|
+
-- Float vectors (32-bit floating point, most common)
|
|
166
|
+
CREATE VIRTUAL TABLE vec_floats USING vec0(embedding float[384]);
|
|
167
|
+
|
|
168
|
+
-- Int8 vectors (8-bit integers, smaller memory footprint)
|
|
169
|
+
CREATE VIRTUAL TABLE vec_int8 USING vec0(embedding int8[384]);
|
|
170
|
+
|
|
171
|
+
-- Binary vectors (1 bit per dimension, maximum compression)
|
|
172
|
+
CREATE VIRTUAL TABLE vec_binary USING vec0(embedding bit[384]);
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
**Usage example:**
|
|
176
|
+
|
|
177
|
+
```sql
|
|
178
|
+
.load ./vec0
|
|
179
|
+
|
|
180
|
+
create virtual table vec_examples using vec0(
|
|
181
|
+
sample_embedding float[8]
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
-- vectors can be provided as JSON or in a compact binary format
|
|
185
|
+
insert into vec_examples(rowid, sample_embedding)
|
|
186
|
+
values
|
|
187
|
+
(1, '[0.279, -0.95, -0.45, -0.554, 0.473, 0.353, 0.784, -0.826]'),
|
|
188
|
+
(2, '[-0.156, -0.94, -0.563, 0.011, -0.947, -0.602, 0.3, 0.09]'),
|
|
189
|
+
(3, '[-0.559, 0.179, 0.619, -0.987, 0.612, 0.396, -0.319, -0.689]'),
|
|
190
|
+
(4, '[0.914, -0.327, -0.815, -0.807, 0.695, 0.207, 0.614, 0.459]'),
|
|
191
|
+
(5, '[0.072, 0.946, -0.243, 0.104, 0.659, 0.237, 0.723, 0.155]'),
|
|
192
|
+
(6, '[0.409, -0.908, -0.544, -0.421, -0.84, -0.534, -0.798, -0.444]'),
|
|
193
|
+
(7, '[0.271, -0.27, -0.26, -0.581, -0.466, 0.873, 0.296, 0.218]'),
|
|
194
|
+
(8, '[-0.658, 0.458, -0.673, -0.241, 0.979, 0.28, 0.114, 0.369]'),
|
|
195
|
+
(9, '[0.686, 0.552, -0.542, -0.936, -0.369, -0.465, -0.578, 0.886]'),
|
|
196
|
+
(10, '[0.753, -0.371, 0.311, -0.209, 0.829, -0.082, -0.47, -0.507]'),
|
|
197
|
+
(11, '[0.123, -0.475, 0.169, 0.796, -0.201, -0.561, 0.995, 0.019]'),
|
|
198
|
+
(12, '[-0.818, -0.906, -0.781, 0.255, 0.584, -0.156, -0.873, -0.237]'),
|
|
199
|
+
(13, '[0.992, 0.058, 0.942, 0.722, -0.977, 0.441, 0.363, 0.074]'),
|
|
200
|
+
(14, '[-0.466, 0.282, -0.777, -0.13, -0.093, 0.908, 0.752, -0.473]'),
|
|
201
|
+
(15, '[0.001, -0.643, 0.825, 0.741, -0.403, 0.278, 0.218, -0.694]'),
|
|
202
|
+
(16, '[0.525, 0.079, 0.557, 0.061, -0.999, -0.352, -0.961, 0.858]'),
|
|
203
|
+
(17, '[0.757, 0.663, -0.385, -0.884, 0.756, 0.894, -0.829, -0.028]'),
|
|
204
|
+
(18, '[-0.862, 0.521, 0.532, -0.743, -0.049, 0.1, -0.47, 0.745]'),
|
|
205
|
+
(19, '[-0.154, -0.576, 0.079, 0.46, -0.598, -0.377, 0.99, 0.3]'),
|
|
206
|
+
(20, '[-0.124, 0.035, -0.758, -0.551, -0.324, 0.177, -0.54, -0.56]');
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
-- Find 3 nearest neighbors using LIMIT
|
|
210
|
+
select
|
|
211
|
+
rowid,
|
|
212
|
+
distance
|
|
213
|
+
from vec_examples
|
|
214
|
+
where sample_embedding match '[0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5]'
|
|
215
|
+
order by distance
|
|
216
|
+
limit 3;
|
|
217
|
+
/*
|
|
218
|
+
┌───────┬──────────────────┐
|
|
219
|
+
│ rowid │ distance │
|
|
220
|
+
├───────┼──────────────────┤
|
|
221
|
+
│ 5 │ 1.16368770599365 │
|
|
222
|
+
│ 13 │ 1.75137972831726 │
|
|
223
|
+
│ 11 │ 1.83941268920898 │
|
|
224
|
+
└───────┴──────────────────┘
|
|
225
|
+
*/
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
**How vector search works:** The `MATCH` operator finds vectors similar to your query vector. In the example above, `sample_embedding MATCH '[0.5, ...]'` searches for vectors closest to `[0.5, ...]` and returns them ordered by distance (smallest = most similar).
|
|
229
|
+
|
|
230
|
+
**Note:** All vector similarity queries require `LIMIT` or `k = ?` (where k is the number of nearest neighbors to return). This prevents accidentally returning too many results on large datasets, since finding all vectors within a distance threshold requires calculating distance to every vector in the table.
|
|
231
|
+
|
|
232
|
+
## Advanced Usage
|
|
233
|
+
|
|
234
|
+
This fork adds several powerful features for production use:
|
|
235
|
+
|
|
236
|
+
### Distance Constraints for KNN Queries
|
|
237
|
+
|
|
238
|
+
Filter results by distance thresholds using `>`, `>=`, `<`, `<=` operators on the `distance` column:
|
|
239
|
+
|
|
240
|
+
```sql
|
|
241
|
+
-- KNN query with distance constraint
|
|
242
|
+
-- Requests k=10 neighbors, but only returns those with distance < 1.5
|
|
243
|
+
select rowid, distance
|
|
244
|
+
from vec_examples
|
|
245
|
+
where sample_embedding match '[0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5]'
|
|
246
|
+
and k = 10
|
|
247
|
+
and distance < 1.5
|
|
248
|
+
order by distance;
|
|
249
|
+
/*
|
|
250
|
+
┌───────┬──────────────────┐
|
|
251
|
+
│ rowid │ distance │
|
|
252
|
+
├───────┼──────────────────┤
|
|
253
|
+
│ 5 │ 1.16368770599365 │
|
|
254
|
+
└───────┴──────────────────┘
|
|
255
|
+
*/
|
|
256
|
+
|
|
257
|
+
-- KNN query with range constraint: find vectors in a specific distance range
|
|
258
|
+
select rowid, distance
|
|
259
|
+
from vec_examples
|
|
260
|
+
where sample_embedding match '[0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5]'
|
|
261
|
+
and k = 20
|
|
262
|
+
and distance between 1.5 and 2.0
|
|
263
|
+
order by distance;
|
|
264
|
+
/*
|
|
265
|
+
┌───────┬──────────────────┐
|
|
266
|
+
│ rowid │ distance │
|
|
267
|
+
├───────┼──────────────────┤
|
|
268
|
+
│ 13 │ 1.75137972831726 │
|
|
269
|
+
│ 11 │ 1.83941268920898 │
|
|
270
|
+
│ 7 │ 1.89339029788971 │
|
|
271
|
+
│ 8 │ 1.92658650875092 │
|
|
272
|
+
│ 10 │ 1.93983662128448 │
|
|
273
|
+
└───────┴──────────────────┘
|
|
274
|
+
*/
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Cursor-based Pagination
|
|
278
|
+
|
|
279
|
+
Instead of using `OFFSET` (which is slow for large datasets), you can use the last result's distance value as a 'cursor' to fetch the next page. This is more efficient because you're filtering directly rather than skipping rows.
|
|
280
|
+
|
|
281
|
+
```sql
|
|
282
|
+
-- First page: get initial results
|
|
283
|
+
select rowid, distance
|
|
284
|
+
from vec_examples
|
|
285
|
+
where sample_embedding match '[0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5]'
|
|
286
|
+
and k = 3
|
|
287
|
+
order by distance;
|
|
288
|
+
/*
|
|
289
|
+
┌───────┬──────────────────┐
|
|
290
|
+
│ rowid │ distance │
|
|
291
|
+
├───────┼──────────────────┤
|
|
292
|
+
│ 5 │ 1.16368770599365 │
|
|
293
|
+
│ 13 │ 1.75137972831726 │
|
|
294
|
+
│ 11 │ 1.83941268920898 │
|
|
295
|
+
└───────┴──────────────────┘
|
|
296
|
+
*/
|
|
297
|
+
|
|
298
|
+
-- Next page: use last distance as cursor (distance > 1.83941268920898)
|
|
299
|
+
select rowid, distance
|
|
300
|
+
from vec_examples
|
|
301
|
+
where sample_embedding match '[0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5]'
|
|
302
|
+
and k = 3
|
|
303
|
+
and distance > 1.83941268920898
|
|
304
|
+
order by distance;
|
|
305
|
+
/*
|
|
306
|
+
┌───────┬──────────────────┐
|
|
307
|
+
│ rowid │ distance │
|
|
308
|
+
├───────┼──────────────────┤
|
|
309
|
+
│ 7 │ 1.89339029788971 │
|
|
310
|
+
│ 8 │ 1.92658650875092 │
|
|
311
|
+
│ 10 │ 1.93983662128448 │
|
|
312
|
+
└───────┴──────────────────┘
|
|
313
|
+
*/
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### Space Reclamation with Optimize
|
|
317
|
+
|
|
318
|
+
`optimize` compacts vec shadow tables. To shrink the database file:
|
|
319
|
+
|
|
320
|
+
```sql
|
|
321
|
+
-- Before creating vec tables: enable autovacuum and apply it (recommended)
|
|
322
|
+
PRAGMA auto_vacuum = FULL; -- or INCREMENTAL
|
|
323
|
+
VACUUM; -- activates the setting
|
|
324
|
+
|
|
325
|
+
-- Use WAL for better concurrency
|
|
326
|
+
PRAGMA journal_mode = WAL;
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
After deletes, reclaim space:
|
|
330
|
+
|
|
331
|
+
```sql
|
|
332
|
+
-- Compact shadow tables
|
|
333
|
+
INSERT INTO vec_examples(vec_examples) VALUES('optimize');
|
|
334
|
+
|
|
335
|
+
- Flush WAL
|
|
336
|
+
PRAGMA wal_checkpoint(TRUNCATE);
|
|
337
|
+
|
|
338
|
+
-- Reclaim freed pages (if using auto_vacuum=INCREMENTAL)
|
|
339
|
+
PRAGMA incremental_vacuum;
|
|
340
|
+
|
|
341
|
+
-- If you did NOT enable autovacuum, run VACUUM (after checkpoint) to shrink the file.
|
|
342
|
+
-- With autovacuum on, VACUUM is optional.
|
|
343
|
+
VACUUM;
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
`VACUUM` should not corrupt vec tables; a checkpoint first is recommended when
|
|
347
|
+
using WAL so the rewrite starts from a clean state.
|
|
348
|
+
|
|
349
|
+
## Sponsors
|
|
350
|
+
|
|
351
|
+
> [!NOTE]
|
|
352
|
+
> The sponsors listed below support the original [`asg017/sqlite-vec`](https://github.com/asg017/sqlite-vec) project by Alex Garcia, not this community fork.
|
|
353
|
+
|
|
354
|
+
Development of the original `sqlite-vec` is supported by multiple generous sponsors! Mozilla
|
|
355
|
+
is the main sponsor through the new Builders project.
|
|
356
|
+
<p align="center">
|
|
357
|
+
<a href="https://hacks.mozilla.org/2024/06/sponsoring-sqlite-vec-to-enable-more-powerful-local-ai-applications/">
|
|
358
|
+
<picture>
|
|
359
|
+
<source media="(prefers-color-scheme: dark)" srcset="./.github/logos/mozilla.dark.svg">
|
|
360
|
+
<source media="(prefers-color-scheme: light)" srcset="./.github/logos/mozilla.svg">
|
|
361
|
+
<img alt="Mozilla Builders logo" width=400>
|
|
362
|
+
</picture>
|
|
363
|
+
</a>
|
|
364
|
+
</p>
|
|
365
|
+
|
|
366
|
+
`sqlite-vec` is also sponsored by the following companies:
|
|
367
|
+
|
|
368
|
+
<a href="https://fly.io/">
|
|
369
|
+
<picture>
|
|
370
|
+
<source media="(prefers-color-scheme: dark)" srcset="./.github/logos/flyio.dark.svg">
|
|
371
|
+
<source media="(prefers-color-scheme: light)" srcset="./.github/logos/flyio.svg">
|
|
372
|
+
<img alt="Fly.io logo" src="./.github/logos/flyio.svg" width="48%">
|
|
373
|
+
</picture>
|
|
374
|
+
</a>
|
|
375
|
+
|
|
376
|
+
<a href="https://tur.so/sqlite-vec">
|
|
377
|
+
<picture>
|
|
378
|
+
<source media="(prefers-color-scheme: dark)" srcset="./.github/logos/turso.svg">
|
|
379
|
+
<source media="(prefers-color-scheme: light)" srcset="./.github/logos/turso.svg">
|
|
380
|
+
<img alt="Turso logo" src="./.github/logos/turso.svg" width="48%">
|
|
381
|
+
</picture>
|
|
382
|
+
</a>
|
|
383
|
+
|
|
384
|
+
<a href="https://sqlitecloud.io/">
|
|
385
|
+
<picture>
|
|
386
|
+
<source media="(prefers-color-scheme: dark)" srcset="./.github/logos/sqlitecloud.dark.svg">
|
|
387
|
+
<source media="(prefers-color-scheme: light)" srcset="./.github/logos/sqlitecloud.svg">
|
|
388
|
+
<img alt="SQLite Cloud logo" src="./.github/logos/flyio.svg" width="48%">
|
|
389
|
+
</picture>
|
|
390
|
+
</a>
|
|
391
|
+
|
|
392
|
+
<a href="https://shinkai.com">
|
|
393
|
+
<picture>
|
|
394
|
+
<source media="(prefers-color-scheme: dark)" srcset="./.github/logos/shinkai.dark.svg">
|
|
395
|
+
<source media="(prefers-color-scheme: light)" srcset="./.github/logos/shinkai.svg">
|
|
396
|
+
|
|
397
|
+
<img alt="Shinkai logo" src="./.github/logos/shinkai.svg" width="48%">
|
|
398
|
+
</picture>
|
|
399
|
+
</a>
|
|
400
|
+
|
|
401
|
+
As well as multiple individual supporters on
|
|
402
|
+
[Github sponsors](https://github.com/sponsors/asg017/)!
|
|
403
|
+
|
|
404
|
+
If your company interested in sponsoring `sqlite-vec` development, send me an
|
|
405
|
+
email to get more info: https://alexgarcia.xyz
|
|
406
|
+
|
|
407
|
+
## See Also
|
|
408
|
+
|
|
409
|
+
- [**`sqlite-ecosystem`**](https://github.com/asg017/sqlite-ecosystem), Maybe
|
|
410
|
+
more 3rd party SQLite extensions I've developed
|
|
411
|
+
- [**`sqlite-rembed`**](https://github.com/asg017/sqlite-rembed), Generate text
|
|
412
|
+
embeddings from remote APIs like OpenAI/Nomic/Ollama, meant for testing and
|
|
413
|
+
SQL scripts
|
|
414
|
+
- [**`sqlite-lembed`**](https://github.com/asg017/sqlite-lembed), Generate text
|
|
415
|
+
embeddings locally from embedding models in the `.gguf` format
|