Skip to content

Commit 1ffca81

Browse files
authored
Add sqlite-vec extension
1 parent 6bab179 commit 1ffca81

7 files changed

Lines changed: 25 additions & 3 deletions

File tree

Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ EXTENSION_FUNCTIONS = extension-functions.c
66
EXTENSION_FUNCTIONS_URL = https://www.sqlite.org/contrib/download/extension-functions.c?get=25
77
EXTENSION_FUNCTIONS_SHA3 = ee39ddf5eaa21e1d0ebcbceeab42822dd0c4f82d8039ce173fd4814807faabfa
88

9+
# sqlite-vec extension
10+
# https://github.com/asg017/sqlite-vec
11+
EXTENSION_VEC=sqlite-vec.c
12+
EXTENSION_VEC_VERSION=0.1.6
13+
EXTENSION_VEC_DIR=sqlite-vec-v${EXTENSION_VEC_VERSION}
14+
EXTENSION_VEC_URL=https://github.com/team-reflect/sqlite-vec/releases/download/v${EXTENSION_VEC_VERSION}/sqlite-vec-${EXTENSION_VEC_VERSION}-amalgamation.tar.gz
15+
916
# sqlite-better-trigram extension
1017
# https://github.com/streetwriters/sqlite-better-trigram
1118
EXTENSION_BETTER_TRIGRAM=better-trigram.c
@@ -23,6 +30,7 @@ CFILES = \
2330
libprogress.c \
2431
libvfs.c \
2532
${EXTENSION_FUNCTIONS} \
33+
${EXTENSION_VEC} \
2634
${EXTENSION_BETTER_TRIGRAM} \
2735
$(CFILES_EXTRA)
2836

@@ -36,6 +44,7 @@ JSFILES = \
3644
vpath %.c src
3745
vpath %.c deps
3846
vpath %.c deps/$(SQLITE_VERSION)
47+
vpath %.c deps/$(EXTENSION_VEC_DIR)
3948
vpath %.c deps/$(EXTENSION_BETTER_TRIGRAM_DIR)
4049

4150
EXPORTED_FUNCTIONS = src/exported_functions.json
@@ -54,6 +63,7 @@ CFLAGS_COMMON = \
5463
-I'deps/$(SQLITE_VERSION)' \
5564
-I'cache/$(SQLITE_VERSION)/ext/fts5' \
5665
-Wno-non-literal-null-conversion \
66+
-DSQLITE_VEC_ENABLE_WASM_SIMD -msimd128 \
5767
$(CFLAGS_EXTRA)
5868
CFLAGS_DEBUG = -g $(CFLAGS_COMMON)
5969
CFLAGS_DIST = -Oz -flto $(CFLAGS_COMMON)
@@ -163,6 +173,10 @@ deps/$(EXTENSION_FUNCTIONS): cache/$(EXTENSION_FUNCTIONS)
163173
rm -rf deps/sha3 $@
164174
cp 'cache/$(EXTENSION_FUNCTIONS)' $@
165175

176+
deps/${EXTENSION_VEC_DIR}/sqlite-vec.h deps/${EXTENSION_VEC_DIR}/sqlite-vec.c:
177+
mkdir -p deps/${EXTENSION_VEC_DIR}
178+
curl -LsS ${EXTENSION_VEC_URL} | tar -xzf - -C deps/${EXTENSION_VEC_DIR}/
179+
166180
deps/${EXTENSION_BETTER_TRIGRAM_DIR}/better-trigram.h deps/${EXTENSION_BETTER_TRIGRAM_DIR}/better-trigram.c:
167181
mkdir -p deps/${EXTENSION_BETTER_TRIGRAM_DIR}
168182
curl -LsS ${EXTENSION_BETTER_TRIGRAM_URL} | tar -xzf - -C deps/${EXTENSION_BETTER_TRIGRAM_DIR}/ --strip-components=1
@@ -180,6 +194,12 @@ tmp/obj/dist/%.o: %.c
180194
mkdir -p tmp/obj/dist
181195
$(EMCC) $(CFLAGS_DIST) $(WASQLITE_DEFINES) $^ -c -o $@
182196

197+
tmp/obj/debug/sqlite-vec.o: deps/${EXTENSION_VEC_DIR}/sqlite-vec.c
198+
mkdir -p tmp/obj/debug
199+
$(EMCC) $(CFLAGS_DEBUG) $(WASQLITE_DEFINES) $^ -c -o $@
200+
201+
tmp/obj/dist/sqlite-vec.o: deps/${EXTENSION_VEC_DIR}/sqlite-vec.c
202+
183203
tmp/obj/debug/better-trigram.o: deps/${EXTENSION_BETTER_TRIGRAM_DIR}/better-trigram.c
184204
mkdir -p tmp/obj/debug
185205
$(EMCC) $(CFLAGS_DEBUG) $(WASQLITE_DEFINES) $^ -c -o $@

dist/wa-sqlite-async.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/wa-sqlite-async.wasm

128 KB
Binary file not shown.

dist/wa-sqlite-jspi.wasm

71.6 KB
Binary file not shown.

dist/wa-sqlite.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/wa-sqlite.wasm

71.6 KB
Binary file not shown.

src/main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <emscripten.h>
33
#include <sqlite3.h>
44

5+
extern void sqlite3_vec_init(void);
56
extern void sqlite3_bettertrigram_init();
67

78
// Some SQLite API functions take a pointer to a function that frees
@@ -15,6 +16,7 @@ void* EMSCRIPTEN_KEEPALIVE getSqliteFree() {
1516

1617
int main() {
1718
sqlite3_initialize();
19+
sqlite3_auto_extension(&sqlite3_vec_init);
1820
sqlite3_auto_extension(&sqlite3_bettertrigram_init);
1921
return 0;
20-
}
22+
}

0 commit comments

Comments
 (0)