update go demos

This commit is contained in:
Alex Garcia 2024-07-16 23:11:26 -07:00
parent e507bc0230
commit 6eb2397537
6 changed files with 14 additions and 25 deletions

View file

@ -1,26 +1,13 @@
package main package main
import ( import (
"bytes"
_ "embed" _ "embed"
"encoding/binary"
"log" "log"
_ "github.com/asg017/sqlite-vec-ncruces-bindings" sqlite_vec "github.com/asg017/sqlite-vec-go-bindings/ncruces"
"github.com/ncruces/go-sqlite3" "github.com/ncruces/go-sqlite3"
) )
func serializeFloat32(vector []float32) ([]byte, error) {
buf := new(bytes.Buffer)
err := binary.Write(buf, binary.LittleEndian, vector)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}
func main() { func main() {
db, err := sqlite3.Open(":memory:") db, err := sqlite3.Open(":memory:")
if err != nil { if err != nil {
@ -56,7 +43,7 @@ func main() {
} }
for id, values := range items { for id, values := range items {
v, err := serializeFloat32(values) v, err := sqlite_vec.SerializeFloat32(values)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -86,7 +73,7 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
query, err := serializeFloat32(q) query, err := sqlite_vec.SerializeFloat32(q)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View file

@ -2,10 +2,12 @@ module asg017.com/ex1
go 1.22.5 go 1.22.5
require github.com/ncruces/go-sqlite3 v0.17.2-0.20240711235451-21de85e849b7 require (
github.com/asg017/sqlite-vec-go-bindings v0.0.1-alpha.36
github.com/ncruces/go-sqlite3 v0.17.2-0.20240711235451-21de85e849b7
)
require ( require (
github.com/asg017/sqlite-vec-ncruces-bindings v0.0.1-alpha.33 // indirect
github.com/ncruces/julianday v1.0.0 // indirect github.com/ncruces/julianday v1.0.0 // indirect
github.com/tetratelabs/wazero v1.7.3 // indirect github.com/tetratelabs/wazero v1.7.3 // indirect
golang.org/x/sys v0.22.0 // indirect golang.org/x/sys v0.22.0 // indirect

View file

@ -1,5 +1,5 @@
github.com/asg017/sqlite-vec-ncruces-bindings v0.0.1-alpha.33 h1:Nrzcj5C3Ex64pWvfV6XMgc8KoMfnKoMmibjXJHTdbbY= github.com/asg017/sqlite-vec-go-bindings v0.0.1-alpha.36 h1:FMGkKAA7nZL8gr/dvIx1uc54J3v2gbLVa+mLqZDCvjk=
github.com/asg017/sqlite-vec-ncruces-bindings v0.0.1-alpha.33/go.mod h1:2ji5nzTNgmzsJaKEnxLNRbsMHF17Bv9EbVEf0jQTAyA= github.com/asg017/sqlite-vec-go-bindings v0.0.1-alpha.36/go.mod h1:A8+cTt/nKFsYCQF6OgzSNpKZrzNo5gQsXBTfsXHXY0Q=
github.com/ncruces/go-sqlite3 v0.17.2-0.20240711235451-21de85e849b7 h1:ssM02uUFDfz0V2TMg2du2BjbW9cpOhFJK0kpDN+X768= github.com/ncruces/go-sqlite3 v0.17.2-0.20240711235451-21de85e849b7 h1:ssM02uUFDfz0V2TMg2du2BjbW9cpOhFJK0kpDN+X768=
github.com/ncruces/go-sqlite3 v0.17.2-0.20240711235451-21de85e849b7/go.mod h1:FnCyui8SlDoL0mQZ5dTouNo7s7jXS0kJv9lBt1GlM9w= github.com/ncruces/go-sqlite3 v0.17.2-0.20240711235451-21de85e849b7/go.mod h1:FnCyui8SlDoL0mQZ5dTouNo7s7jXS0kJv9lBt1GlM9w=
github.com/ncruces/julianday v1.0.0 h1:fH0OKwa7NWvniGQtxdJRxAgkBMolni2BjDHaWTxqt7M= github.com/ncruces/julianday v1.0.0 h1:fH0OKwa7NWvniGQtxdJRxAgkBMolni2BjDHaWTxqt7M=

View file

@ -7,12 +7,10 @@ import (
"fmt" "fmt"
"log" "log"
sqlite_vec "github.com/asg017/sqlite-vec/bindings/go/cgo" sqlite_vec "github.com/asg017/sqlite-vec-go-bindings/cgo"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
) )
// #cgo LDFLAGS: -L../../dist
import "C"
func serializeFloat32(vector []float32) ([]byte, error) { func serializeFloat32(vector []float32) ([]byte, error) {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)

View file

@ -1,7 +1,7 @@
module github.com/asg017/sqlite-vec/examples/go module github.com/asg017/sqlite-vec/examples/go
go 1.20 go 1.22.5
require github.com/mattn/go-sqlite3 v1.14.22 require github.com/mattn/go-sqlite3 v1.14.22
require github.com/asg017/sqlite-vec/bindings/go/cgo v0.0.0-20240511043328-3d763f499859 // indirect require github.com/asg017/sqlite-vec-go-bindings v0.0.1-alpha.36 // indirect

View file

@ -1,3 +1,5 @@
github.com/asg017/sqlite-vec-go-bindings v0.0.1-alpha.36 h1:FMGkKAA7nZL8gr/dvIx1uc54J3v2gbLVa+mLqZDCvjk=
github.com/asg017/sqlite-vec-go-bindings v0.0.1-alpha.36/go.mod h1:A8+cTt/nKFsYCQF6OgzSNpKZrzNo5gQsXBTfsXHXY0Q=
github.com/asg017/sqlite-vec/bindings/go/cgo v0.0.0-20240511043328-3d763f499859 h1:6jeFy/tSnyNJUrTHoIaFTYkjrHtwVAojvCGkr9G8d4o= github.com/asg017/sqlite-vec/bindings/go/cgo v0.0.0-20240511043328-3d763f499859 h1:6jeFy/tSnyNJUrTHoIaFTYkjrHtwVAojvCGkr9G8d4o=
github.com/asg017/sqlite-vec/bindings/go/cgo v0.0.0-20240511043328-3d763f499859/go.mod h1:Go89G54PaautWRwxvAa1fmKeYoSuUyIvSYpvlfXQaNU= github.com/asg017/sqlite-vec/bindings/go/cgo v0.0.0-20240511043328-3d763f499859/go.mod h1:Go89G54PaautWRwxvAa1fmKeYoSuUyIvSYpvlfXQaNU=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=