Insert data with nullable
field with grpc-RpcError when running milvus in local (pymilvus version 2.5.6)
#40977
Answered
by
yhmo
yrom
asked this question in
Q&A and General discussion
-
Test code: from pymilvus import DataType, MilvusClient
import random
import os
def test(test_func):
def wrapper(*args, **kwargs):
print(f"Running test: {test_func.__name__}\n")
result = test_func(*args, **kwargs)
print(f"Test {test_func.__name__} done.\n")
return result
return wrapper
DIM = 1024
client: MilvusClient = None
def init_client():
global client
# local db
client = MilvusClient(uri="./test.db", timeout=10)
# 创建schema
schema = client.create_schema(enable_dynamic_field=False, auto_id=True, description="test")
# 添加主键
schema.add_field("id", DataType.INT64, is_primary=True)
schema.add_field("text", DataType.VARCHAR, max_length=2048)
schema.add_field("meta", DataType.JSON, nullable=True)
schema.add_field("embeddings", DataType.FLOAT_VECTOR, dim=DIM)
index_params = client.prepare_index_params()
index_params.add_index(
field_name="embeddings",
index_type="IVF_FLAT",
index_name="embeddings_index",
metric_type="L2",
params={"nlist": 128},
)
# index_params.add_index(
# field_name="text",
# index_type="",
# index_name="text_index",
# )
client.create_collection(
"test_collection",
schema=schema,
index_params=index_params,
)
def create_embedding(seed: int = 42):
random.seed(seed * 3)
vector = [random.random() for _ in range(DIM)]
# normalize
norm = sum(x**2 for x in vector) ** 0.5
vector = [x / norm for x in vector]
return vector
def test_insert():
# test nullable field
data = [
{"text": "xxx", "embeddings": create_embedding(0)},
]
client.insert("test_collection", data)
init_client()
test_insert()
|
Beta Was this translation helpful? Give feedback.
Answered by
yhmo
Mar 31, 2025
Replies: 1 comment
-
You are using milvus-lite. milvus-lite is a light-weight local milvus. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
yrom
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You are using milvus-lite. milvus-lite is a light-weight local milvus.
Now the latest version of milvus-lite is v2.4.12. "Nullable" is a feature of v2.5.x, the v2.5 of milvus-lite is still in progress, not ready yet.