ncruces / go-sqlite3

Go bindings to SQLite using wazero
https://pkg.go.dev/github.com/ncruces/go-sqlite3
MIT License
402 stars 12 forks source link

Bundling sqlite-vec into a go-sqlite3 build #120

Closed asg017 closed 1 month ago

asg017 commented 1 month ago

Hey Nuno! Just wanted to share something I was able to make: a WASM build of SQLite, built for go-sqlite3, with sqlite-vec builtin: https://github.com/asg017/sqlite-vec/releases/download/v0.0.1-alpha.27/sqlite-vec-0.0.1-alpha.27-ncruces-go.wasm

I have a demo here of how it works, using the sqlite3.Binary trick. And the makefile, that just downloads the WASM file.

To build it it's a bit complicated, but it works. I just git clone this repo and add this patch file: https://github.com/asg017/sqlite-vec/blob/main/bindings/go/ncruces/go-sqlite3.patch

Then I build the project, all on github actions: https://github.com/asg017/sqlite-vec/blob/main/.github/workflows/release.yaml#L211-L238

And it works well! You can ignore the "database is locked" error, that's a sqlite-vec bug I'll fix:

$ make demo; ./demo
curl -L -o sqlite3.vec.wasm https://github.com/asg017/sqlite-vec/releases/download/v0.0.1-alpha.27/sqlite-vec-0.0.1-alpha.27-ncruces-go.wasm
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 1414k  100 1414k    0     0  1149k      0  0:00:01  0:00:01 --:--:-- 4471k
go build -o demo demo.go
sqlite_version=3.46.0, vec_version=v0.0.1-alpha.27
rowid=3, distance=0.000000
rowid=4, distance=0.200000
rowid=2, distance=0.200000
2024/07/12 16:59:42 sqlite3: database is locked: unable to close due to unfinalized statements or unfinished backups

Just wanted to share to see what you think! I don't mind the build steps, but if you have an tips would love to hear it!

(Feel free to close whenever you like)