Vector
Milvus implementation of vector similarity search capability.
This module provides a Milvus implementation of the VectorCapability protocol for vector-based semantic similarity search operations. Encryption and batching are handled by the base class.
MilvusVectorCapability(collection_name, client, uri, em_invoker, dimension, distance_metric='L2', vector_field='dense_vector', id_max_length=100, content_max_length=65535, encryption=None, default_batch_size=None)
Bases: BaseVectorCapability
Milvus implementation of VectorCapability protocol.
This class provides vector similarity search operations using Milvus. Encryption and batching are handled by the base class.
Attributes:
| Name | Type | Description |
|---|---|---|
collection_name |
str
|
The name of the Milvus collection. |
client |
AsyncMilvusClient
|
Async Milvus client instance. |
dimension |
int
|
Vector dimension. |
distance_metric |
str
|
Distance metric ("L2", "IP", "COSINE"). |
vector_field |
str
|
Field name for dense vectors. |
id_max_length |
int
|
Maximum length for ID field. |
content_max_length |
int
|
Maximum length for content field. |
Initialize the Milvus vector capability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection_name
|
str
|
The name of the Milvus collection. |
required |
client
|
AsyncMilvusClient
|
The async Milvus client instance. |
required |
uri
|
str
|
Milvus URI for creating sync client to prepare index params. |
required |
em_invoker
|
BaseEMInvoker
|
The embedding model invoker. |
required |
dimension
|
int
|
Vector dimension. |
required |
distance_metric
|
str
|
Distance metric. Defaults to "L2". Supported: "L2", "IP", "COSINE". |
'L2'
|
vector_field
|
str
|
Field name for dense vectors. Defaults to "dense_vector". |
'dense_vector'
|
id_max_length
|
int
|
Maximum length for ID field. Defaults to 100. |
100
|
content_max_length
|
int
|
Maximum length for content field. Defaults to 65535. |
65535
|
encryption
|
EncryptionCapability | None
|
Encryption capability. Defaults to None. |
None
|
default_batch_size
|
int | None
|
Default batch size for create/update. Defaults to None. |
None
|
ensure_index(index_type='IVF_FLAT', index_params=None, query_field='content', **kwargs)
async
Ensure collection and vector index exist, creating them if necessary.
This method is idempotent - if the collection and index already exist, it will skip creation and return early. Uses a lock to prevent race conditions when called concurrently from multiple coroutines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index_type
|
str
|
Index type. Defaults to "IVF_FLAT". Supported: "IVF_FLAT", "HNSW". |
'IVF_FLAT'
|
index_params
|
dict[str, Any] | None
|
Index-specific parameters. Defaults to None, in which case default parameters are used. |
None
|
query_field
|
str
|
Field name for text content. Defaults to "content". |
'content'
|
**kwargs
|
Any
|
Additional parameters (e.g. from base capability interface); ignored. |
{}
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If collection or index creation fails. |