diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index 6a6eae9a..869c5684 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -1365,6 +1365,7 @@ export default { use_tls: 'Use TLS', scheme: 'Scheme', grpc_address: 'gRPC Address', + database: 'Database Name', use_default_connection: 'Use Default Connection', index_name: 'Index Name', number_of_shards: 'Shards', diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts index 59c34a0e..b27a8544 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -1223,6 +1223,7 @@ export default { use_tls: "TLS 사용", scheme: "프로토콜", grpc_address: "gRPC 주소", + database: "데이터베이스 이름", use_default_connection: "기본 연결 사용", index_name: "인덱스 이름", number_of_shards: "샤드 수", diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts index de44d938..41a592eb 100755 --- a/frontend/src/i18n/locales/ru-RU.ts +++ b/frontend/src/i18n/locales/ru-RU.ts @@ -1277,6 +1277,7 @@ export default { use_tls: 'Использовать TLS', scheme: 'Схема', grpc_address: 'gRPC адрес', + database: 'Имя базы данных', use_default_connection: 'Использовать подключение по умолчанию', index_name: 'Имя индекса', number_of_shards: 'Шарды', diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index fa2b9ab3..f118a911 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -1231,6 +1231,7 @@ export default { use_tls: "使用 TLS", scheme: "协议", grpc_address: "gRPC 地址", + database: "数据库名", use_default_connection: "使用默认连接", index_name: "索引名称", number_of_shards: "分片数", diff --git a/internal/container/engine_factory.go b/internal/container/engine_factory.go index 2e09f15a..1567a8b7 100644 --- a/internal/container/engine_factory.go +++ b/internal/container/engine_factory.go @@ -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) { diff --git a/internal/container/engine_factory_test.go b/internal/container/engine_factory_test.go new file mode 100644 index 00000000..bd61c418 --- /dev/null +++ b/internal/container/engine_factory_test.go @@ -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)) + } +} diff --git a/internal/types/vectorstore.go b/internal/types/vectorstore.go index ae970490..0c758dbe 100644 --- a/internal/types/vectorstore.go +++ b/internal/types/vectorstore.go @@ -137,7 +137,8 @@ type ConnectionConfig struct { // Weaviate GrpcAddress string `yaml:"grpc_address" json:"grpc_address,omitempty"` Scheme string `yaml:"scheme" json:"scheme,omitempty"` - // Tencent VectorDB and Doris database name. + // Database name used by engines that support database-level namespaces + // (currently Milvus, Tencent VectorDB, and Doris). Database string `yaml:"database" json:"database,omitempty"` // Postgres UseDefaultConnection bool `yaml:"use_default_connection" json:"use_default_connection,omitempty"` @@ -681,6 +682,7 @@ func GetVectorStoreTypes() []VectorStoreTypeInfo { DisplayName: "Milvus", ConnectionFields: []VectorStoreFieldInfo{ {Name: "addr", Type: "string", Required: true, Description: "Address", Default: "localhost:19530"}, + {Name: "database", Type: "string", Required: false, Description: "Database Name"}, {Name: "username", Type: "string", Required: false, Description: "Username", Default: "root"}, {Name: "password", Type: "string", Required: false, Sensitive: true, Description: "Password"}, }, diff --git a/internal/types/vectorstore_test.go b/internal/types/vectorstore_test.go index ff66c424..5a943383 100644 --- a/internal/types/vectorstore_test.go +++ b/internal/types/vectorstore_test.go @@ -286,6 +286,25 @@ func TestGetVectorStoreTypes(t *testing.T) { assert.True(t, seen["password"].Sensitive) }) + t.Run("milvus exposes optional database connection field", func(t *testing.T) { + var milvusType VectorStoreTypeInfo + for _, typ := range types { + if typ.Type == "milvus" { + milvusType = typ + break + } + } + require.NotEmpty(t, milvusType.ConnectionFields) + + seen := map[string]VectorStoreFieldInfo{} + for _, f := range milvusType.ConnectionFields { + seen[f.Name] = f + } + require.Contains(t, seen, "database") + assert.False(t, seen["database"].Required) + assert.Equal(t, "string", seen["database"].Type) + }) + t.Run("elasticsearch has connection and index fields", func(t *testing.T) { var esType VectorStoreTypeInfo for _, typ := range types {