39 lines
1.1 KiB
Java
39 lines
1.1 KiB
Java
|
package com.ai.service;
|
||
|
|
||
|
import io.milvus.client.MilvusClient;
|
||
|
import io.milvus.grpc.DataType;
|
||
|
import io.milvus.param.collection.CreateCollectionParam;
|
||
|
import io.milvus.param.collection.FieldType;
|
||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||
|
import org.springframework.stereotype.Service;
|
||
|
|
||
|
@Service
|
||
|
public class SimilarService {
|
||
|
|
||
|
@Autowired
|
||
|
private MilvusClient milvusClient;
|
||
|
|
||
|
public void createCollection(){
|
||
|
//定义字段
|
||
|
FieldType spuId = FieldType.newBuilder()
|
||
|
.withName("spu_id")
|
||
|
.withDataType(DataType.Int64)
|
||
|
.withPrimaryKey(true)
|
||
|
.build();
|
||
|
|
||
|
FieldType vectorField = FieldType.newBuilder()
|
||
|
.withName("type_vector")
|
||
|
.withDataType(DataType.FloatVector)
|
||
|
.withDimension(1536)
|
||
|
.build();
|
||
|
|
||
|
CreateCollectionParam createParam = CreateCollectionParam.newBuilder()
|
||
|
.withCollectionName("similar_collection")
|
||
|
.addFieldType(spuId)
|
||
|
.addFieldType(vectorField)
|
||
|
.build();
|
||
|
|
||
|
milvusClient.createCollection(createParam);
|
||
|
}
|
||
|
}
|