feat: add embedding config for rag

This commit is contained in:
shenlan 2025-08-10 10:30:06 +08:00
parent f06b46cedd
commit aa373c9c23
4 changed files with 43 additions and 0 deletions

View File

@ -60,3 +60,17 @@ psql postgres://shenlan:<密码>@127.0.0.1:5432/mydb -c "\d+ documents"
若能看到 `embedding | vector(1536)` 字段,说明 pgvector 已成功启用。
完成以上步骤后,应用即可通过连接串 `postgres://shenlan:<密码>@127.0.0.1:5432/mydb` 使用数据库。
## 6. 配置嵌入服务
`server/config/server.yaml` 中新增 `embedding` 配置,使服务端能够对问题进行向量化检索:
```yaml
global:
embedding:
base_url: http://127.0.0.1:11434
token: ""
dimension: 1536
```
其中 `dimension` 需与所使用的嵌入模型返回的向量维度一致。

View File

@ -82,6 +82,11 @@ type Runtime struct {
VectorDB VectorDB `yaml:"vectordb"`
Datasources []DataSource `yaml:"datasources"`
Proxy string `yaml:"proxy"`
Embedding struct {
BaseURL string `yaml:"base_url"`
Token string `yaml:"token"`
Dimension int `yaml:"dimension"`
} `yaml:"embedding"`
}
// ServerConfigPath points to the server configuration file.
@ -112,5 +117,8 @@ func (rt *Runtime) ToConfig() *Config {
c.Global.VectorDB = rt.VectorDB
c.Global.Datasources = rt.Datasources
c.Global.Proxy = rt.Proxy
c.Embedding.BaseURL = rt.Embedding.BaseURL
c.Embedding.Token = rt.Embedding.Token
c.Embedding.Dimension = rt.Embedding.Dimension
return &c
}

View File

@ -45,3 +45,20 @@ func TestResolveChunking(t *testing.T) {
t.Fatalf("expected default slices")
}
}
func TestRuntimeToConfigEmbedding(t *testing.T) {
rt := &Runtime{}
rt.Embedding.BaseURL = "http://localhost:8080"
rt.Embedding.Token = "tok"
rt.Embedding.Dimension = 123
cfg := rt.ToConfig()
if cfg.Embedding.BaseURL != "http://localhost:8080" {
t.Fatalf("unexpected base url %q", cfg.Embedding.BaseURL)
}
if cfg.Embedding.Token != "tok" {
t.Fatalf("unexpected token %q", cfg.Embedding.Token)
}
if cfg.Embedding.Dimension != 123 {
t.Fatalf("unexpected dimension %d", cfg.Embedding.Dimension)
}
}

View File

@ -6,6 +6,10 @@ global:
vectordb:
pgurl: postgres://user:password@127.0.0.1:5432/postgres
datasources: []
embedding:
base_url: http://127.0.0.1:11434
token: ""
dimension: 1536
api:
askai:
timeout: 100