Merge pull request #74 from svc-design/codex/update-server.yaml-for-vectordb-coexistence

feat: add vectordb postgres config fields
This commit is contained in:
shenlan 2025-08-07 13:33:13 +08:00 committed by GitHub
commit 9db57a2dc8
2 changed files with 42 additions and 6 deletions

View File

@ -20,12 +20,16 @@ var ragSvc = initRAG()
// initRAG attempts to construct a RAG service from server configuration.
func initRAG() *rag.Service {
cfg, err := rconfig.LoadServer()
if err != nil || cfg.VectorDB.PGURL == "" {
if err != nil {
return nil
}
dsn := cfg.VectorDB.DSN()
if dsn == "" {
return nil
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
st, err := store.New(ctx, cfg.VectorDB.PGURL)
st, err := store.New(ctx, dsn)
if err != nil {
return nil
}

View File

@ -1,6 +1,7 @@
package config
import (
"fmt"
"os"
"path/filepath"
@ -19,13 +20,44 @@ type Runtime struct {
Addr string `yaml:"addr"`
Password string `yaml:"password"`
} `yaml:"redis"`
Module string `yaml:"module"`
VectorDB struct {
PGURL string `yaml:"pgurl"`
} `yaml:"vectordb"`
Module string `yaml:"module"`
VectorDB VectorDB `yaml:"vectordb"`
Datasources []Datasource `yaml:"datasources"`
}
// VectorDB holds configuration for the PostgreSQL vector store.
type VectorDB struct {
PGURL string `yaml:"pgurl"`
PGHost string `yaml:"pg_host"`
PGPort int `yaml:"pg_port"`
PGUser string `yaml:"pg_user"`
PGPassword string `yaml:"pg_password"`
PGDBName string `yaml:"pg_db_name"`
PGSSLMode string `yaml:"pg_sslmode"`
}
// DSN returns the connection string for the database.
// If PGURL is provided it is used, otherwise a DSN is constructed
// from individual fields. When insufficient fields are provided it
// returns an empty string.
func (v VectorDB) DSN() string {
if v.PGURL != "" {
return v.PGURL
}
if v.PGHost == "" || v.PGUser == "" || v.PGDBName == "" {
return ""
}
port := v.PGPort
if port == 0 {
port = 5432
}
ssl := v.PGSSLMode
if ssl == "" {
ssl = "require"
}
return fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=%s", v.PGUser, v.PGPassword, v.PGHost, port, v.PGDBName, ssl)
}
// LoadServer loads RAG configuration from server/config/server.yaml.
func LoadServer() (*Runtime, error) {
path := filepath.Join("server", "config", "server.yaml")