Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support array #70

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Python >= 3.8.5
#### Install from PyPI (Recommended)

Run `pip install pymilvus==2.3.4`
Run `pip install milvus-cli==0.4.1`
Run `pip install milvus-cli==0.4.2`

#### Install from a tarball

Expand Down
32 changes: 28 additions & 4 deletions milvus_cli/Collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,44 @@ def create_collection(
):
fieldList = []
for field in fields:
[fieldName, fieldType, fieldData] = field.split(":")
[fieldName, fieldType, *restData] = field.split(":")
upperFieldType = fieldType.upper()
if upperFieldType in ["BINARY_VECTOR", "FLOAT_VECTOR"]:
fieldList.append(
FieldSchema(
name=fieldName,
dtype=DataType[upperFieldType],
dim=int(fieldData),
dim=int(restData[0]),
)
)
elif upperFieldType == "VARCHAR":
fieldList.append(
FieldSchema(
name=fieldName,
dtype=DataType[upperFieldType],
max_length=fieldData,
max_length=restData[0],
)
)
elif upperFieldType == "ARRAY":
upperElementType = restData[1].upper()
max_capacity = restData[0]
maxLength = restData[2] if len(restData) == 3 else None
fieldList.append(
FieldSchema(
name=fieldName,
dtype=DataType[upperFieldType],
element_type=DataType[upperElementType],
max_capacity=max_capacity,
max_length=maxLength,
)
)

else:
fieldList.append(
FieldSchema(
name=fieldName,
dtype=DataType[upperFieldType],
description=fieldData,
description=restData[0],
)
)
schema = CollectionSchema(
Expand Down Expand Up @@ -147,11 +161,21 @@ def get_collection_details(self, collectionName="", collection=None):
fieldSchemaDetails = ""
for fieldSchema in schema.fields:
_name = f"{'*' if fieldSchema.is_primary else ''}{fieldSchema.name}"

_type = DataTypeByNum[fieldSchema.dtype]
_desc = fieldSchema.description
_params = fieldSchema.params
_dim = _params.get("dim")
_params_desc = f"dim: {_dim}" if _dim else ""
if fieldSchema.dtype == DataType.ARRAY:
_max_length = _params.get("max_length")
_element_type = fieldSchema.element_type
_max_capacity = _params.get("max_capacity")
_params_desc = (
f"max_capacity: {_max_capacity},element_type: {_element_type}"
)
_params_desc += f",max_length: {_max_length}" if _max_length else ""

fieldSchemaDetails += f"\n - {_name} {_type} {_params_desc} {_desc}"
schemaDetails = """Description: {}\n\nAuto ID: {}\n\nFields(* is the primary field):{}""".format(
schema.description, schema.auto_id, fieldSchemaDetails
Expand Down
2 changes: 2 additions & 0 deletions milvus_cli/Types.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __str__(self):
"BINARY_VECTOR",
"FLOAT_VECTOR",
"JSON",
"ARRAY",
]

IndexTypes = [
Expand Down Expand Up @@ -144,6 +145,7 @@ def __str__(self):
11: "DOUBLE",
20: "STRING",
21: "VARCHAR",
22: "ARRAY",
23: "JSON",
100: "BINARY_VECTOR",
101: "FLOAT_VECTOR",
Expand Down
8 changes: 4 additions & 4 deletions milvus_cli/Validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ def validateCollectionParameter(collectionName, primaryField, fields):
fieldNames = []
for field in fields:
fieldList = field.split(":")
if not (len(fieldList) == 3):
if len(fieldList) < 3:
raise ParameterException(
'Field should contain three parameters concatenated by ":".'
'Field should contain three parameters(array field need more) concatenated by ":".'
)
[fieldName, fieldType, fieldData] = fieldList
[fieldName, fieldType, *restData] = fieldList
upperFieldType = fieldType.upper()
fieldNames.append(fieldName)
if upperFieldType not in FiledDataTypes:
Expand All @@ -42,7 +42,7 @@ def validateCollectionParameter(collectionName, primaryField, fields):
)
if upperFieldType in ["BINARY_VECTOR", "FLOAT_VECTOR"]:
try:
int(fieldData)
int(restData[0])
except ValueError as e:
raise ParameterException("""Vector's dim should be int.""")
# Dedup field name.
Expand Down
4 changes: 2 additions & 2 deletions milvus_cli/scripts/collection_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"-f",
"--schema-field",
"fields",
help='[Multiple] - FieldSchema. Usage is "<Name>:<DataType>:<Dim(if vector) or Description>"',
help='[Multiple] - FieldSchema. Usage is "<Name>:<DataType>:<Dim(if vector) or Description>", Array Type is <Name>:<DataType>:<MaxCapacity>:<ElementDataType>(:<MaxLength>if Varchar)',
default=None,
multiple=True,
)
Expand Down Expand Up @@ -85,7 +85,7 @@ def create_collection(

Example:

create collection -c car -f id:INT64:primary_field -f vector:FLOAT_VECTOR:128 -f color:INT64:color -f brand:INT64:brand -p id -A -d 'car_collection'
create collection -c car -f id:INT64:primary_field -f vector:FLOAT_VECTOR:128 -f color:INT64:color -f brand:ARRAY:64:VARCHAR:128 -p id -A -d 'car_collection'
"""
try:
validateCollectionParameter(
Expand Down