Skip to content

Commit

Permalink
Merge pull request #70 from zilliztech/support-array
Browse files Browse the repository at this point in the history
Support array
  • Loading branch information
shanghaikid authored Jan 18, 2024
2 parents 02ccd2f + 54048ca commit aaa2e48
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
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

0 comments on commit aaa2e48

Please sign in to comment.