update README.cn.md.

Signed-off-by: 王麻子 <14335116+fixity@user.noreply.gitee.com>
This commit is contained in:
王麻子 2024-05-15 02:32:33 +00:00 committed by Gitee
parent 98fce8f0fd
commit 4acf41e939
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -114,43 +114,65 @@ public class FaceMilvusMapper extends MilvusMapper<Face> {
} }
@Component @Component
@Slf4j
public class ApplicationRunnerTest implements ApplicationRunner { public class ApplicationRunnerTest implements ApplicationRunner {
@Autowired private final FaceMilvusMapper mapper;
private FaceMilvusMapper mapper;
public ApplicationRunnerTest(FaceMilvusMapper mapper) {
this.mapper = mapper;
}
@Override @Override
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args){
List<Float> vector = Lists.newArrayList(0.1f,0.2f,0.3f);
//查询
MilvusResp<MilvusResultVo<Face>> query = mapper.queryWrapper()
.eq(Face::getPersonId, 1l)
.vector(Face::getFaceVector,vector)
.limit(100l)
.query();
MilvusResp<List<Face>> query2 = mapper.getById(1l);
//删除
MilvusResp<DeleteResp> remove= mapper.deleteWrapper()
.eq(Face::getPersonId, 1l)
.id(111)
.remove();
MilvusResp<DeleteResp> remove2 = mapper.removeById(1l);
//更新
Face face=new Face(); Face face=new Face();
face.setFaceVector(vector); List<Float> vector = new ArrayList<>();
MilvusResp<UpsertResp> update = mapper.updateWrapper() for (int i = 0; i < 128; i++) {
.eq(Face::getPersonId, 1l) vector.add((float) (Math.random() * 100)); // 这里仅作为示例使用随机数
.update(face); }
face.setPersonId(1l); face.setPersonId(1l);
MilvusResp<UpsertResp> update2 = mapper.updateById(face); face.setFaceVector(vector);
//新增 //新增
MilvusResp<InsertResp> insert = mapper.insertWrapper() List<Face> faces=new ArrayList<>();
.put(Face::getFaceVector, vector) for (int i = 1; i < 10 ;i++){
.insert(); Face face1=new Face();
MilvusResp<InsertResp> insert2 = mapper.insert(face); face1.setPersonId(Long.valueOf(i));
List<Float> vector1 = new ArrayList<>();
for (int j = 0; j < 128; j++) {
vector1.add((float) (Math.random() * 100)); // 这里仅作为示例使用随机数
}
face1.setFaceVector(vector1);
faces.add(face1);
}
MilvusResp<InsertResp> insert = mapper.insert(faces.toArray(faces.toArray(new Face[0]))); log.info("insert--{}", JSONObject.toJSONString(insert));
//id查询
MilvusResp<List<MilvusResult<Face>>> query = mapper.getById(9l);
log.info("query--getById---{}", JSONObject.toJSONString(query));
//向量查询
MilvusResp<List<MilvusResult<Face>>> query1 = mapper.queryWrapper()
.vector(Face::getFaceVector, vector)
.ne(Face::getPersonId, 1L)
.topK(3)
.query();
log.info("向量查询 query--queryWrapper---{}", JSONObject.toJSONString(query1));
//标量查询
MilvusResp<List<MilvusResult<Face>>> query2 = mapper.queryWrapper()
.eq(Face::getPersonId, 2L)
.limit(3)
.query();
log.info("标量查询 query--queryWrapper---{}", JSONObject.toJSONString(query2));
//更新
vector.clear();
for (int i = 0; i < 128; i++) {
vector.add((float) (Math.random() * 100)); // 这里仅作为示例使用随机数
}
MilvusResp<UpsertResp> update = mapper.updateById(face);log.info("update--{}", JSONObject.toJSONString(update));
//id查询
MilvusResp<List<MilvusResult<Face>>> query3 = mapper.getById(1L);log.info("query--getById---{}", JSONObject.toJSONString(query3));
//删除
MilvusResp<DeleteResp> remove = mapper.removeById(1L);log.info("remove--{}", JSONObject.toJSONString(remove));
//查询
MilvusResp<List<MilvusResult<Face>>> query4 = mapper.getById(1L);log.info("query--{}", JSONObject.toJSONString(query4));
} }
} }
``` ```