From d8c2abf02733c8c4e08dcd5d00a5a0ea382c69de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B0=E4=BA=91=E9=92=8A?= Date: Sat, 4 Jul 2026 11:33:11 +0800 Subject: [PATCH] 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 --- packages/dbgpt-app/src/dbgpt_app/config.py | 3 ++- .../dbgpt_ext/storage/vector_store/milvus_store.py | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/dbgpt-app/src/dbgpt_app/config.py b/packages/dbgpt-app/src/dbgpt_app/config.py index c7afda253..9354fd563 100644 --- a/packages/dbgpt-app/src/dbgpt_app/config.py +++ b/packages/dbgpt-app/src/dbgpt_app/config.py @@ -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"), diff --git a/packages/dbgpt-ext/src/dbgpt_ext/storage/vector_store/milvus_store.py b/packages/dbgpt-ext/src/dbgpt_ext/storage/vector_store/milvus_store.py index 0f9093d5e..1d5ab6323 100644 --- a/packages/dbgpt-ext/src/dbgpt_ext/storage/vector_store/milvus_store.py +++ b/packages/dbgpt-ext/src/dbgpt_ext/storage/vector_store/milvus_store.py @@ -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()