feat: add Tencent VectorDB retriever backend

This commit is contained in:
langcaiye
2026-05-08 16:09:55 +08:00
committed by lyingbug
parent eca060f3aa
commit 74b1342440
15 changed files with 870 additions and 45 deletions
+10 -9
View File
@@ -5,15 +5,16 @@ type RetrieverEngineType string
// RetrieverEngineType constants
const (
PostgresRetrieverEngineType RetrieverEngineType = "postgres"
ElasticsearchRetrieverEngineType RetrieverEngineType = "elasticsearch"
InfinityRetrieverEngineType RetrieverEngineType = "infinity"
ElasticFaissRetrieverEngineType RetrieverEngineType = "elasticfaiss"
QdrantRetrieverEngineType RetrieverEngineType = "qdrant"
MilvusRetrieverEngineType RetrieverEngineType = "milvus"
WeaviateRetrieverEngineType RetrieverEngineType = "weaviate"
DorisRetrieverEngineType RetrieverEngineType = "doris"
SQLiteRetrieverEngineType RetrieverEngineType = "sqlite"
PostgresRetrieverEngineType RetrieverEngineType = "postgres"
ElasticsearchRetrieverEngineType RetrieverEngineType = "elasticsearch"
InfinityRetrieverEngineType RetrieverEngineType = "infinity"
ElasticFaissRetrieverEngineType RetrieverEngineType = "elasticfaiss"
QdrantRetrieverEngineType RetrieverEngineType = "qdrant"
MilvusRetrieverEngineType RetrieverEngineType = "milvus"
WeaviateRetrieverEngineType RetrieverEngineType = "weaviate"
DorisRetrieverEngineType RetrieverEngineType = "doris"
SQLiteRetrieverEngineType RetrieverEngineType = "sqlite"
TencentVectorDBRetrieverEngineType RetrieverEngineType = "tencent_vectordb"
)
// RetrieverType represents the type of retriever
+53 -14
View File
@@ -68,13 +68,14 @@ func (v *VectorStore) BeforeCreate(tx *gorm.DB) error {
// InfinityRetrieverEngineType and ElasticFaissRetrieverEngineType are legacy/experimental
// types that do not have standalone deployable instances, so they are excluded.
var validEngineTypes = map[RetrieverEngineType]bool{
PostgresRetrieverEngineType: true,
ElasticsearchRetrieverEngineType: true,
QdrantRetrieverEngineType: true,
MilvusRetrieverEngineType: true,
WeaviateRetrieverEngineType: true,
DorisRetrieverEngineType: true,
SQLiteRetrieverEngineType: true,
PostgresRetrieverEngineType: true,
ElasticsearchRetrieverEngineType: true,
QdrantRetrieverEngineType: true,
MilvusRetrieverEngineType: true,
WeaviateRetrieverEngineType: true,
DorisRetrieverEngineType: true,
SQLiteRetrieverEngineType: true,
TencentVectorDBRetrieverEngineType: true,
}
// IsValidEngineType checks whether the given engine type is valid for VectorStore.
@@ -115,14 +116,14 @@ 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 string `yaml:"database" json:"database,omitempty"`
// Postgres
UseDefaultConnection bool `yaml:"use_default_connection" json:"use_default_connection,omitempty"`
// Doris: HTTP port for Stream Load API (FE default 8030).
// Addr is reused for the MySQL protocol "host:9030"; HTTPPort + the host of Addr
// together form the FE HTTP endpoint used by Stream Load.
HTTPPort int `yaml:"http_port" json:"http_port,omitempty"`
// Doris: target database name for the Stream Load HTTP path and the MySQL DSN.
Database string `yaml:"database" json:"database,omitempty"`
// Version is the detected server version (e.g., "7.10.1", "16.2", "1.12.6").
// Auto-populated by TestConnection on successful connectivity check.
Version string `yaml:"version" json:"version,omitempty"`
@@ -175,6 +176,9 @@ func (c *ConnectionConfig) Scan(value interface{}) error {
// GetEndpoint returns a normalized endpoint string for duplicate detection.
func (c ConnectionConfig) GetEndpoint() string {
if c.Addr != "" {
if c.Database != "" {
return c.Addr + "/" + c.Database
}
return c.Addr
}
if c.Host != "" {
@@ -218,12 +222,12 @@ type IndexConfig struct {
// --- Scalability fields ---
ShardNumber int `yaml:"shard_number" json:"shard_number,omitempty"` // Qdrant: number of shards per collection
ReplicationFactor int `yaml:"replication_factor" json:"replication_factor,omitempty"` // Qdrant, Weaviate: number of replicas
ReplicationFactor int `yaml:"replication_factor" json:"replication_factor,omitempty"` // Qdrant, Weaviate: number of replicas
ShardsNum int `yaml:"shards_num" json:"shards_num,omitempty"` // Milvus: number of shards per collection (CreateCollection)
ReplicaNumber int `yaml:"replica_number" json:"replica_number,omitempty"` // Milvus: in-memory replica count (LoadCollection)
DesiredShardCount int `yaml:"desired_shard_count" json:"desired_shard_count,omitempty"` // Weaviate: number of shards per collection
BucketsNum int `yaml:"buckets_num" json:"buckets_num,omitempty"` // Doris: number of buckets per table (DISTRIBUTED BY HASH ... BUCKETS N)
ReplicationNum int `yaml:"replication_num" json:"replication_num,omitempty"` // Doris: replication_num PROPERTIES
ReplicaNumber int `yaml:"replica_number" json:"replica_number,omitempty"` // Milvus: in-memory replica count (LoadCollection)
DesiredShardCount int `yaml:"desired_shard_count" json:"desired_shard_count,omitempty"` // Weaviate: number of shards per collection
BucketsNum int `yaml:"buckets_num" json:"buckets_num,omitempty"` // Doris: number of buckets per table (DISTRIBUTED BY HASH ... BUCKETS N)
ReplicationNum int `yaml:"replication_num" json:"replication_num,omitempty"` // Doris: replication_num PROPERTIES
}
// Value implements the driver.Valuer interface.
@@ -262,6 +266,11 @@ func (c IndexConfig) GetIndexNameOrDefault(engineType RetrieverEngineType) strin
return c.CollectionName
}
return "weknora_embeddings"
case TencentVectorDBRetrieverEngineType:
if c.CollectionName != "" {
return c.CollectionName
}
return "weknora_embeddings"
case WeaviateRetrieverEngineType:
if c.CollectionPrefix != "" {
return c.CollectionPrefix
@@ -568,6 +577,21 @@ func GetVectorStoreTypes() []VectorStoreTypeInfo {
{Name: "replica_number", Type: "number", Required: false, Description: "In-memory Replicas (read HA)", Default: 1},
},
},
{
Type: "tencent_vectordb",
DisplayName: "Tencent VectorDB",
ConnectionFields: []VectorStoreFieldInfo{
{Name: "addr", Type: "string", Required: true, Description: "Address", Default: "http://localhost:8080"},
{Name: "username", Type: "string", Required: true, Description: "Username"},
{Name: "api_key", Type: "string", Required: true, Sensitive: true, Description: "API Key"},
{Name: "database", Type: "string", Required: false, Description: "Database", Default: "weknora"},
},
IndexFields: []VectorStoreFieldInfo{
{Name: "collection_name", Type: "string", Required: false, Description: "Collection Name", Default: "weknora_embeddings"},
{Name: "shards_num", Type: "number", Required: false, Description: "Shards", Default: 1},
{Name: "replica_number", Type: "number", Required: false, Description: "Replicas", Default: 1},
},
},
{
Type: "weaviate",
DisplayName: "Weaviate",
@@ -714,6 +738,21 @@ func buildEnvStoreForDriver(driver string, envLookup EnvLookupFunc) *VectorStore
Password: envLookup("MILVUS_PASSWORD"),
},
}
case "tencent_vectordb":
return &VectorStore{
ID: "__env_tencent_vectordb__",
Name: "Tencent VectorDB",
EngineType: TencentVectorDBRetrieverEngineType,
ConnectionConfig: ConnectionConfig{
Addr: envLookup("TENCENT_VECTORDB_ADDR"),
Username: envLookup("TENCENT_VECTORDB_USERNAME"),
APIKey: envLookup("TENCENT_VECTORDB_API_KEY"),
Database: envLookup("TENCENT_VECTORDB_DATABASE"),
},
IndexConfig: IndexConfig{
CollectionName: envLookup("TENCENT_VECTORDB_COLLECTION"),
},
}
case "weaviate":
return &VectorStore{
ID: "__env_weaviate__",
+49 -18
View File
@@ -43,20 +43,25 @@ func TestIsEnvStoreID(t *testing.T) {
func TestBuildEnvVectorStores(t *testing.T) {
envMap := map[string]string{
"ELASTICSEARCH_ADDR": "http://es:9200",
"ELASTICSEARCH_USERNAME": "elastic",
"ELASTICSEARCH_PASSWORD": "secret",
"ELASTICSEARCH_INDEX": "my_index",
"QDRANT_HOST": "qdrant-host",
"QDRANT_API_KEY": "qd-key",
"MILVUS_ADDRESS": "milvus:19530",
"WEAVIATE_HOST": "weaviate:8080",
"DORIS_ADDR": "doris-fe:9030",
"DORIS_HTTP_PORT": "8030",
"DORIS_DATABASE": "weknora",
"DORIS_USERNAME": "root",
"DORIS_PASSWORD": "doris-pass",
"DORIS_TABLE_PREFIX": "weknora_embeddings",
"ELASTICSEARCH_ADDR": "http://es:9200",
"ELASTICSEARCH_USERNAME": "elastic",
"ELASTICSEARCH_PASSWORD": "secret",
"ELASTICSEARCH_INDEX": "my_index",
"QDRANT_HOST": "qdrant-host",
"QDRANT_API_KEY": "qd-key",
"MILVUS_ADDRESS": "milvus:19530",
"TENCENT_VECTORDB_ADDR": "http://tencent-vdb",
"TENCENT_VECTORDB_USERNAME": "root",
"TENCENT_VECTORDB_API_KEY": "vdb-key",
"TENCENT_VECTORDB_DATABASE": "weknora",
"TENCENT_VECTORDB_COLLECTION": "weknora_embeddings",
"WEAVIATE_HOST": "weaviate:8080",
"DORIS_ADDR": "doris-fe:9030",
"DORIS_HTTP_PORT": "8030",
"DORIS_DATABASE": "weknora",
"DORIS_USERNAME": "root",
"DORIS_PASSWORD": "doris-pass",
"DORIS_TABLE_PREFIX": "weknora_embeddings",
}
lookup := mockEnvLookup(envMap)
@@ -103,8 +108,8 @@ func TestBuildEnvVectorStores(t *testing.T) {
})
t.Run("all supported drivers", func(t *testing.T) {
stores := BuildEnvVectorStores("postgres,sqlite,elasticsearch_v8,elasticsearch_v7,qdrant,milvus,weaviate,doris", lookup)
require.Len(t, stores, 8)
stores := BuildEnvVectorStores("postgres,sqlite,elasticsearch_v8,elasticsearch_v7,qdrant,milvus,weaviate,doris,tencent_vectordb", lookup)
require.Len(t, stores, 9)
ids := make([]string, len(stores))
for i, s := range stores {
@@ -118,6 +123,7 @@ func TestBuildEnvVectorStores(t *testing.T) {
assert.Contains(t, ids, "__env_milvus__")
assert.Contains(t, ids, "__env_weaviate__")
assert.Contains(t, ids, "__env_doris__")
assert.Contains(t, ids, "__env_tencent_vectordb__")
})
t.Run("qdrant env store", func(t *testing.T) {
@@ -133,6 +139,16 @@ func TestBuildEnvVectorStores(t *testing.T) {
assert.Equal(t, "milvus:19530", stores[0].ConnectionConfig.Addr)
})
t.Run("tencent vectordb env store", func(t *testing.T) {
stores := BuildEnvVectorStores("tencent_vectordb", lookup)
require.Len(t, stores, 1)
assert.Equal(t, "http://tencent-vdb", stores[0].ConnectionConfig.Addr)
assert.Equal(t, "root", stores[0].ConnectionConfig.Username)
assert.Equal(t, "vdb-key", stores[0].ConnectionConfig.APIKey)
assert.Equal(t, "weknora", stores[0].ConnectionConfig.Database)
assert.Equal(t, "weknora_embeddings", stores[0].IndexConfig.CollectionName)
})
t.Run("weaviate env store", func(t *testing.T) {
stores := BuildEnvVectorStores("weaviate", lookup)
require.Len(t, stores, 1)
@@ -229,8 +245,8 @@ func TestNewVectorStoreResponse(t *testing.T) {
func TestGetVectorStoreTypes(t *testing.T) {
types := GetVectorStoreTypes()
t.Run("returns 5 engine types (excludes postgres and sqlite)", func(t *testing.T) {
assert.Len(t, types, 5)
t.Run("returns supported external engine types (excludes postgres and sqlite)", func(t *testing.T) {
assert.Len(t, types, 6)
})
t.Run("type names match engine constants", func(t *testing.T) {
@@ -241,6 +257,7 @@ func TestGetVectorStoreTypes(t *testing.T) {
assert.Contains(t, typeNames, "elasticsearch")
assert.Contains(t, typeNames, "qdrant")
assert.Contains(t, typeNames, "milvus")
assert.Contains(t, typeNames, "tencent_vectordb")
assert.Contains(t, typeNames, "weaviate")
assert.Contains(t, typeNames, "doris")
assert.NotContains(t, typeNames, "postgres")
@@ -369,6 +386,7 @@ func TestIsValidEngineType(t *testing.T) {
MilvusRetrieverEngineType,
WeaviateRetrieverEngineType,
SQLiteRetrieverEngineType,
TencentVectorDBRetrieverEngineType,
}
for _, et := range validTypes {
t.Run("valid: "+string(et), func(t *testing.T) {
@@ -659,6 +677,19 @@ func TestIndexConfig_GetIndexNameOrDefault(t *testing.T) {
engineType: MilvusRetrieverEngineType,
expected: "weknora_embeddings",
},
// Tencent VectorDB
{
name: "tencent vectordb with custom collection name",
config: IndexConfig{CollectionName: "custom_collection"},
engineType: TencentVectorDBRetrieverEngineType,
expected: "custom_collection",
},
{
name: "tencent vectordb default",
config: IndexConfig{},
engineType: TencentVectorDBRetrieverEngineType,
expected: "weknora_embeddings",
},
// Weaviate
{
name: "weaviate with custom prefix",