## Summary
Fixes#3041
When users set `type = "milvus"` in their TOML vector storage config,
the server fails to start with:
```
ValueError: Invalid data for ChromaVectorConfig: Unknown type value: milvus,
known types: ['chroma', 'elasticsearch', 'pgvector', 'weaviate', 'oceanbase']
```
### Root Causes
1. **Wrong type annotation** — `StorageConfig.vector` was annotated as
`ChromaVectorConfig` instead of the polymorphic base class
`VectorStoreConfig`, preventing the config parser from dispatching to
non-chroma vector store types.
2. **Top-level `pymilvus` import** — `milvus_store.py` imported
`pymilvus` at module level (line 12). When `pymilvus` is not installed,
the entire module fails to load and `MilvusVectorConfig` is never
registered in the type registry.
### Fix
- **`packages/dbgpt-app/src/dbgpt_app/config.py`**: Change the `vector`
field type annotation from `ChromaVectorConfig` to `VectorStoreConfig`
(keeping `ChromaVectorConfig()` as the default value for backward
compatibility).
-
**`packages/dbgpt-ext/src/dbgpt_ext/storage/vector_store/milvus_store.py`**:
Move the top-level `from pymilvus.milvus_client import IndexParams,
MilvusClient` into the methods that actually use them (lazy import),
matching the pattern used by all other vector store implementations
(chroma, elasticsearch, pgvector, weaviate, etc.).
### Verification
Tested with `pymilvus` **not installed** (same environment as the bug
reporter):
**Before fix** — loading a TOML config with `type = "milvus"`:
```
Error scanning module dbgpt_ext.storage.vector_store.milvus_store: No module named 'pymilvus'
ValueError: Invalid data for ChromaVectorConfig: Unknown type value: milvus
```
**After fix** — same config loads successfully:
```
✅ vector type: MilvusVectorConfig (uri=localhost, port=19530)
```
- `MilvusVectorConfig` registers in the type registry even without
`pymilvus` installed
- `VectorStoreConfig.get_subclass("milvus")` correctly resolves to
`MilvusVectorConfig`
- When actually creating a `MilvusStore` without `pymilvus`, a clear
error message is shown: `"Please install it with pip install pymilvus"`
- All 26 existing storage unit tests pass
- `ruff` lint and format checks pass
Made with [Cursor](https://cursor.com)
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>