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