modified internal/ml/embed.go +7 -2
| @@ -1,10 +1,11 @@ |
| 1 | 1 | package ml |
| 2 | 2 | |
| 3 | 3 | import ( |
| 4 | + "bytes" |
| 4 | 5 | "context" |
| 6 | + "encoding/binary" |
| 5 | 7 | "unsafe" |
| 6 | 8 | |
| 7 | | - vec "github.com/asg017/sqlite-vec-go-bindings/cgo" |
| 8 | 9 | "github.com/openai/openai-go" |
| 9 | 10 | "github.com/openai/openai-go/option" |
| 10 | 11 | ) |
| @@ -93,7 +94,11 @@ func AvgEmbeddings(blobs [][]byte, dim int) ([]byte, error) { |
| 93 | 94 | for j := range sum { |
| 94 | 95 | sum[j] /= float32(count) |
| 95 | 96 | } |
| 96 | | - return vec.SerializeFloat32(sum) |
| 97 | + buf := new(bytes.Buffer) |
| 98 | + if err := binary.Write(buf, binary.LittleEndian, sum); err != nil { |
| 99 | + return nil, err |
| 100 | + } |
| 101 | + return buf.Bytes(), nil |
| 97 | 102 | } |
| 98 | 103 | |
| 99 | 104 | func BytesToFloat32s(data []byte, expectedDim int) []float32 { |
| @@ -1,10 +1,11 @@ |
| 1 | package ml | 1 | package ml |
| 2 | | 2 | |
| 3 | import ( | 3 | import ( |
| | 4 | + "bytes" |
| 4 | "context" | 5 | "context" |
| | 6 | + "encoding/binary" |
| 5 | "unsafe" | 7 | "unsafe" |
| 6 | | 8 | |
| 7 | - vec "github.com/asg017/sqlite-vec-go-bindings/cgo" | | |
| 8 | "github.com/openai/openai-go" | 9 | "github.com/openai/openai-go" |
| 9 | "github.com/openai/openai-go/option" | 10 | "github.com/openai/openai-go/option" |
| 10 | ) | 11 | ) |
| @@ -93,7 +94,11 @@ func AvgEmbeddings(blobs [][]byte, dim int) ([]byte, error) { |
| 93 | for j := range sum { | 94 | for j := range sum { |
| 94 | sum[j] /= float32(count) | 95 | sum[j] /= float32(count) |
| 95 | } | 96 | } |
| 96 | - return vec.SerializeFloat32(sum) | 97 | + buf := new(bytes.Buffer) |
| | 98 | + if err := binary.Write(buf, binary.LittleEndian, sum); err != nil { |
| | 99 | + return nil, err |
| | 100 | + } |
| | 101 | + return buf.Bytes(), nil |
| 97 | } | 102 | } |
| 98 | | 103 | |
| 99 | func BytesToFloat32s(data []byte, expectedDim int) []float32 { | 104 | func BytesToFloat32s(data []byte, expectedDim int) []float32 { |