一段milvus java sdk创建collection的示例

        //创建collection
        FieldType primaryKey = FieldType.newBuilder()
                .withName(ID)
                .withPrimaryKey(true)
                .withDataType(DataType.VarChar)
                .withMaxLength(20)
                .withDescription("pk")
                .build();
        //向量数据
        FieldType vectorKey = FieldType.newBuilder()
                .withName(VECTOR)
                .withDataType(DataType.FloatVector)
                .withDimension(this.dbPrivateDimension)
                .withDescription("vector")
                .build();
        //原始数据
        FieldType rawKey = FieldType.newBuilder()
                .withName(RAW)
                .withDataType(DataType.VarChar)
                .withMaxLength(2048)
                .withDescription("Raw data")
                .build();

        CollectionSchemaParam schemaParam = CollectionSchemaParam.newBuilder()
                .withFieldTypes(Arrays.asList(primaryKey, vectorKey, rawKey))
                .withEnableDynamicField(true)
                .build();
        CreateCollectionParam param = CreateCollectionParam.newBuilder()
                .withCollectionName(collectionName)
                .withDescription(collectionName + " desc...")
                .withSchema(schemaParam)
                .withConsistencyLevel(ConsistencyLevelEnum.BOUNDED)
                .build();
        R<RpcStatus> createStatus =milvusServiceClient.createCollection(param);

使用milvus java sdk 版本:2.3.5。

Leave a Comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.