milvus-io / milvus-sdk-java

Java SDK for Milvus.
https://milvus.io
Apache License 2.0
396 stars 165 forks source link

Missing element_type for Array DataType in FieldSchema for Milvus SDK 2.4.x #1148

Closed Yiling1f closed 1 month ago

Yiling1f commented 1 month ago

Issue Description In Milvus SDK 2.4.x, when defining a field with Array data type (e.g., Array), the FieldSchema does not provide direct access to the element_type information. This issue limits the ability to retrieve the full type specification (e.g., Array) programmatically, as only the base type Array is returned by field.getDataType().name().

Steps to Reproduce

  1. Define a field in Milvus with Array data type in the collection schema.
  2. Use MilvusClient.describeCollection to retrieve the collection schema.
  3. Attempt to retrieve element_type for the Array field through FieldSchema.getTypeParamsList() or any other available methods.

image

Expected Behavior The FieldSchema for Array data types should include the element_type (e.g., Int32) as part of typeParamsList or another accessible attribute, allowing users to retrieve the specific array type programmatically. image

yhmo commented 1 month ago
        List<FieldType> fieldsSchema = Arrays.asList(
                FieldType.newBuilder()
                        .withName("id")
                        .withDataType(DataType.Int64)
                        .withPrimaryKey(true)
                        .withAutoID(false)
                        .build(),
                FieldType.newBuilder()
                        .withName("vector")
                        .withDataType(DataType.FloatVector)
                        .withDimension(128)
                        .build(),
                FieldType.newBuilder()
                        .withName("title")
                        .withDataType(DataType.Array)
                        .withMaxCapacity(100)
                        .withElementType(DataType.VarChar)
                        .withMaxLength(64)
                        .build()
        );

        // Create the collection with 3 fields
        R<RpcStatus> ret = milvusClient.createCollection(CreateCollectionParam.newBuilder()
                .withCollectionName(COLLECTION_NAME)
                .withFieldTypes(fieldsSchema)
                .build());
        if (ret.getStatus() != R.Status.Success.getCode()) {
            throw new RuntimeException("Failed to create collection! Error: " + ret.getMessage());
        }

        R<DescribeCollectionResponse> response = milvusClient.describeCollection(DescribeCollectionParam.newBuilder()
                .withCollectionName(COLLECTION_NAME)
                .build());
        CommonUtils.handleResponseStatus(response);
        DescCollResponseWrapper wrapper = new DescCollResponseWrapper(response.getData());
        FieldType fieldType = wrapper.getFieldByName("title");
        System.out.println(fieldType.getDataType());
        System.out.println(fieldType.getElementType());

Output:

Array
VarChar
Yiling1f commented 1 month ago

Thanks for response! My question has been resolved.