I am creating a simple Milvus collection with the Python MilvusClient API. The collection has one dense vector field.
from pymilvus import MilvusClient, DataType
client = MilvusClient(
uri="http://localhost:19530"
)
schema = client.create_schema(
auto_id=True,
enable_dynamic_fields=True,
)
schema.add_field(
field_name="pk",
datatype=DataType.VARCHAR,
is_primary=True,
max_length=100,
)
schema.add_field(
field_name="dense_vector",
datatype=DataType.FLOAT_VECTOR,
dim=4,
)
index_params = client.prepare_index_params()
index_params.add_index(
field_name="dense_vector",
index_name="dense_vector_index",
index_type="AUTOINDEX",
metric_type="IP",
)
client.create_collection(
collection_name="my_collection",
schema=schema,
index_params=index_params,
)
Then I insert rows like this:
data = [
{
"dense_vector": [0.1, 0.2, 0.3, 0.4],
"text": "first document",
},
{
"dense_vector": [0.2, 0.3, 0.4],
"text": "second document",
},
]
client.insert(
collection_name="my_collection",
data=data,
)
The first row has a 4-dimensional vector, but the second row only has 3 values. I expected Milvus to either reject only the bad row or give me a clear validation error before writing anything.
Instead, the insert fails because the vector length does not match the field dimension.
In my actual application, embeddings come from an external model, and I want to validate the data before calling client.insert(). The schema has dim=4 in this example, but in production it is dim=768.
When using MilvusClient.insert() with a FLOAT_VECTOR field, is the vector length required to exactly match the field dim for every row in the batch, and is there a recommended way to check this before insert?