feat: support Milvus database selection for vector stores
This commit is contained in:
@@ -189,7 +189,16 @@ func createQdrantEngine(store types.VectorStore) (interfaces.RetrieveEngineServi
|
||||
}
|
||||
|
||||
func createMilvusEngine(ctx context.Context, store types.VectorStore) (interfaces.RetrieveEngineService, error) {
|
||||
cc := store.ConnectionConfig
|
||||
milvusCfg := buildMilvusClientConfig(store.ConnectionConfig)
|
||||
client, err := milvusclient.New(ctx, &milvusCfg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create milvus client: %w", err)
|
||||
}
|
||||
repo := milvusRepo.NewMilvusRetrieveEngineRepository(client, &store.IndexConfig)
|
||||
return retriever.NewKVHybridRetrieveEngine(repo, types.MilvusRetrieverEngineType), nil
|
||||
}
|
||||
|
||||
func buildMilvusClientConfig(cc types.ConnectionConfig) milvusclient.ClientConfig {
|
||||
addr := cc.Addr
|
||||
if addr == "" {
|
||||
addr = "localhost:19530"
|
||||
@@ -205,15 +214,10 @@ func createMilvusEngine(ctx context.Context, store types.VectorStore) (interface
|
||||
if cc.Password != "" {
|
||||
milvusCfg.Password = cc.Password
|
||||
}
|
||||
// NOTE: Milvus DBName is not yet in ConnectionConfig.
|
||||
// Phase 1 limitation — only the default database is used.
|
||||
|
||||
client, err := milvusclient.New(ctx, &milvusCfg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create milvus client: %w", err)
|
||||
if cc.Database != "" {
|
||||
milvusCfg.DBName = cc.Database
|
||||
}
|
||||
repo := milvusRepo.NewMilvusRetrieveEngineRepository(client, &store.IndexConfig)
|
||||
return retriever.NewKVHybridRetrieveEngine(repo, types.MilvusRetrieverEngineType), nil
|
||||
return milvusCfg
|
||||
}
|
||||
|
||||
func createWeaviateEngine(store types.VectorStore) (interfaces.RetrieveEngineService, error) {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package container
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
)
|
||||
|
||||
func TestBuildMilvusClientConfig_UsesDatabaseName(t *testing.T) {
|
||||
cfg := buildMilvusClientConfig(types.ConnectionConfig{
|
||||
Addr: "milvus.example.com:19530",
|
||||
Username: "tester",
|
||||
Password: "secret",
|
||||
Database: "regdi_ram_haom1",
|
||||
})
|
||||
|
||||
if cfg.Address != "milvus.example.com:19530" {
|
||||
t.Fatalf("expected address to be preserved, got %q", cfg.Address)
|
||||
}
|
||||
if cfg.Username != "tester" {
|
||||
t.Fatalf("expected username to be preserved, got %q", cfg.Username)
|
||||
}
|
||||
if cfg.Password != "secret" {
|
||||
t.Fatalf("expected password to be preserved, got %q", cfg.Password)
|
||||
}
|
||||
if cfg.DBName != "regdi_ram_haom1" {
|
||||
t.Fatalf("expected DBName to be propagated, got %q", cfg.DBName)
|
||||
}
|
||||
if len(cfg.DialOptions) != 1 {
|
||||
t.Fatalf("expected one dial option, got %d", len(cfg.DialOptions))
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildMilvusClientConfig_DefaultsAddressWhenMissing(t *testing.T) {
|
||||
cfg := buildMilvusClientConfig(types.ConnectionConfig{})
|
||||
|
||||
if cfg.Address != "localhost:19530" {
|
||||
t.Fatalf("expected default address localhost:19530, got %q", cfg.Address)
|
||||
}
|
||||
if cfg.DBName != "" {
|
||||
t.Fatalf("expected empty DBName by default, got %q", cfg.DBName)
|
||||
}
|
||||
if len(cfg.DialOptions) != 1 {
|
||||
t.Fatalf("expected one dial option, got %d", len(cfg.DialOptions))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user