fix(config): allow Milvus vector store type in TOML configuration (#3041)

When users set `type = "milvus"` in their TOML vector storage config,
the server fails to start with:
  ValueError: Unknown type value: milvus, known types: [...]

Root causes:
1. The `StorageConfig.vector` field was annotated as `ChromaVectorConfig`
   instead of the base `VectorStoreConfig`, preventing polymorphic type
   dispatch from resolving any non-chroma vector store type correctly.
2. `milvus_store.py` imported `pymilvus` at module level. When pymilvus
   is not installed, the entire module fails to load and
   `MilvusVectorConfig` is never registered in the type registry.

Fix:
- Change the `vector` field type annotation to `VectorStoreConfig`
  (keeping `ChromaVectorConfig()` as default for backward compatibility).
- Move the top-level `pymilvus` import into the methods that actually
  use it (lazy import), matching the pattern used by all other vector
  store implementations (chroma, elasticsearch, pgvector, etc.).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
田云钊
2026-07-04 11:33:11 +08:00
parent 177bfc84f7
commit d8c2abf027
2 changed files with 12 additions and 3 deletions

View File

@@ -8,6 +8,7 @@ from dbgpt.model.parameter import (
ModelServiceConfig,
)
from dbgpt.storage.cache.manager import ModelCacheParameters
from dbgpt.storage.vector_store.base import VectorStoreConfig
from dbgpt.util.configure import HookConfig
from dbgpt.util.i18n_utils import _
from dbgpt.util.parameter_utils import BaseParameters
@@ -55,7 +56,7 @@ class SystemParameters:
class StorageConfig(BaseParameters):
__cfg_type__ = "app"
vector: Optional[ChromaVectorConfig] = field(
vector: Optional[VectorStoreConfig] = field(
default_factory=lambda: ChromaVectorConfig(),
metadata={
"help": _("default vector type"),

View File

@@ -9,8 +9,6 @@ import re
from dataclasses import dataclass, field
from typing import Any, Iterable, List, Optional
from pymilvus.milvus_client import IndexParams, MilvusClient
from dbgpt.core import Chunk, Embeddings
from dbgpt.core.awel.flow import Parameter, ResourceCategory, register_resource
from dbgpt.storage.vector_store.base import (
@@ -289,6 +287,14 @@ class MilvusStore(VectorStoreBase):
connect_kwargs["user"] = self.username
connect_kwargs["password"] = self.password
try:
from pymilvus.milvus_client import MilvusClient
except ImportError:
raise ValueError(
"Could not import pymilvus python package. "
"Please install it with `pip install pymilvus`."
)
url = f"http://{self.uri}:{self.port}"
self._milvus_client = MilvusClient(
uri=url, user=self.username, db_name="default"
@@ -374,6 +380,8 @@ class MilvusStore(VectorStoreBase):
)
schema.add_function(bm25_fn)
# Create the collection
from pymilvus.milvus_client import IndexParams
collection = Collection(collection_name, schema)
self.col = collection
index_params = IndexParams()