mirror of https://gitee.com/godoos/godoos.git
11 changed files with 121 additions and 120 deletions
@ -1,19 +0,0 @@ |
|||||
module godovec |
|
||||
|
|
||||
go 1.23.3 |
|
||||
|
|
||||
require ( |
|
||||
github.com/asg017/sqlite-vec-go-bindings v0.1.6 |
|
||||
github.com/ncruces/go-sqlite3/gormlite v0.21.0 |
|
||||
gorm.io/gorm v1.25.12 |
|
||||
) |
|
||||
|
|
||||
require ( |
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect |
|
||||
github.com/jinzhu/now v1.1.5 // indirect |
|
||||
github.com/ncruces/go-sqlite3 v0.21.0 // indirect |
|
||||
github.com/ncruces/julianday v1.0.0 // indirect |
|
||||
github.com/tetratelabs/wazero v1.8.2 // indirect |
|
||||
golang.org/x/sys v0.28.0 // indirect |
|
||||
golang.org/x/text v0.21.0 // indirect |
|
||||
) |
|
@ -1,20 +0,0 @@ |
|||||
github.com/asg017/sqlite-vec-go-bindings v0.1.6 h1:Nx0jAzyS38XpkKznJ9xQjFXz2X9tI7KqjwVxV8RNoww= |
|
||||
github.com/asg017/sqlite-vec-go-bindings v0.1.6/go.mod h1:A8+cTt/nKFsYCQF6OgzSNpKZrzNo5gQsXBTfsXHXY0Q= |
|
||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= |
|
||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= |
|
||||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= |
|
||||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= |
|
||||
github.com/ncruces/go-sqlite3 v0.21.0 h1:EwKFoy1hHEopN4sFZarmi+McXdbCcbTuLixhEayXVbQ= |
|
||||
github.com/ncruces/go-sqlite3 v0.21.0/go.mod h1:zxMOaSG5kFYVFK4xQa0pdwIszqxqJ0W0BxBgwdrNjuA= |
|
||||
github.com/ncruces/go-sqlite3/gormlite v0.21.0 h1:9DsbvW9dS6uxXNFmbrNZixqAXKnIFnLM8oZmKqp8vcI= |
|
||||
github.com/ncruces/go-sqlite3/gormlite v0.21.0/go.mod h1:rP4JXD6jlpOSsg2Ed++kzJIAZZCIBirVYqIpwaLW88E= |
|
||||
github.com/ncruces/julianday v1.0.0 h1:fH0OKwa7NWvniGQtxdJRxAgkBMolni2BjDHaWTxqt7M= |
|
||||
github.com/ncruces/julianday v1.0.0/go.mod h1:Dusn2KvZrrovOMJuOt0TNXL6tB7U2E8kvza5fFc9G7g= |
|
||||
github.com/tetratelabs/wazero v1.8.2 h1:yIgLR/b2bN31bjxwXHD8a3d+BogigR952csSDdLYEv4= |
|
||||
github.com/tetratelabs/wazero v1.8.2/go.mod h1:yAI0XTsMBhREkM/YDAK/zNou3GoiAce1P6+rp/wQhjs= |
|
||||
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= |
|
||||
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= |
|
||||
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= |
|
||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= |
|
||||
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8= |
|
||||
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= |
|
@ -1,54 +0,0 @@ |
|||||
package godovec |
|
||||
|
|
||||
import ( |
|
||||
"fmt" |
|
||||
|
|
||||
_ "embed" |
|
||||
|
|
||||
_ "github.com/asg017/sqlite-vec-go-bindings/ncruces" |
|
||||
|
|
||||
"github.com/ncruces/go-sqlite3/gormlite" |
|
||||
"gorm.io/gorm" |
|
||||
) |
|
||||
|
|
||||
var VecDb *gorm.DB |
|
||||
|
|
||||
type VectorList struct { |
|
||||
ID int `json:"id" gorm:"primaryKey"` |
|
||||
FilePath string `json:"file_path" gorm:"not null"` |
|
||||
Engine string `json:"engine" gorm:"not null"` |
|
||||
EmbeddingModel string `json:"model" gorm:"not null"` |
|
||||
} |
|
||||
|
|
||||
type VectorDoc struct { |
|
||||
ID int `json:"id" gorm:"primaryKey"` |
|
||||
Content string `json:"content"` |
|
||||
FilePath string `json:"file_path" gorm:"not null"` |
|
||||
ListID int `json:"list_id"` |
|
||||
} |
|
||||
|
|
||||
func main() { |
|
||||
InitVector() |
|
||||
} |
|
||||
func InitVector() error { |
|
||||
|
|
||||
db, err := gorm.Open(gormlite.Open("./data.db"), &gorm.Config{}) |
|
||||
if err != nil { |
|
||||
return fmt.Errorf("failed to open vector db: %w", err) |
|
||||
} |
|
||||
|
|
||||
// Enable PRAGMAs
|
|
||||
// - busy_timeout (ms) to prevent db lockups as we're accessing the DB from multiple separate processes in otto8
|
|
||||
tx := db.Exec(` |
|
||||
PRAGMA busy_timeout = 5000; |
|
||||
`) |
|
||||
if tx.Error != nil { |
|
||||
return fmt.Errorf("failed to execute pragma busy_timeout: %w", tx.Error) |
|
||||
} |
|
||||
err = db.AutoMigrate(&VectorList{}, &VectorDoc{}) |
|
||||
if err != nil { |
|
||||
return fmt.Errorf("failed to auto migrate tables: %w", err) |
|
||||
} |
|
||||
VecDb = db |
|
||||
return nil |
|
||||
} |
|
Loading…
Reference in new issue