-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
65 lines (51 loc) · 1.5 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"flag"
"github.com/alash3al/vecdb/internals/config"
"github.com/alash3al/vecdb/internals/embeddings"
"github.com/alash3al/vecdb/internals/http"
"github.com/alash3al/vecdb/internals/store"
"github.com/go-playground/validator/v10"
"github.com/gofiber/fiber/v2"
"log"
// embedder drivers
_ "github.com/alash3al/vecdb/internals/embeddings/drivers/gemini"
// store drivers
_ "github.com/alash3al/vecdb/internals/store/drivers/bolt"
)
var (
flagConfigFilename = flag.String("config", "./config.yml", "the configuration filename")
)
func main() {
flag.Parse()
var cfg *config.Config
var db store.Driver
var embedder embeddings.Driver
var err error
{
cfg, err = config.NewFromFile(*flagConfigFilename)
if err != nil {
log.Fatal(err.Error())
}
}
{
db, err = store.Open(cfg.Store.Driver, cfg.Store.Args)
if err != nil {
log.Fatal(err.Error())
}
}
if cfg.Embedder.Enabled {
embedder, err = embeddings.Open(cfg.Embedder.Driver, cfg.Embedder.Args)
if err != nil {
log.Fatal(err.Error())
}
}
validate := validator.New(validator.WithRequiredStructEnabled())
app := fiber.New()
app.Get("/", http.Home())
app.Post("/v1/vectors/write", http.VectorWrite(validate, db))
app.Post("/v1/vectors/search", http.VectorSearch(validate, db))
app.Post("/v1/embeddings/text/write", http.EmbeddingsTextWrite(validate, embedder, db))
app.Post("/v1/embeddings/text/search", http.EmbeddingsTextSearch(validate, embedder, db))
log.Fatal(app.Listen(cfg.Server.ListenAddr))
}