mirror of
https://gitee.com/dromara/MilvusPlus.git
synced 2025-12-06 17:08:27 +08:00
update README.cn.md.
Signed-off-by: 王麻子 <14335116+fixity@user.noreply.gitee.com>
This commit is contained in:
parent
98fce8f0fd
commit
4acf41e939
86
README.cn.md
86
README.cn.md
@ -114,43 +114,65 @@ public class FaceMilvusMapper extends MilvusMapper<Face> {
|
||||
}
|
||||
|
||||
@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<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);
|
||||
|
||||
//更新
|
||||
public void run(ApplicationArguments args){
|
||||
Face face=new Face();
|
||||
face.setFaceVector(vector);
|
||||
MilvusResp<UpsertResp> update = mapper.updateWrapper()
|
||||
.eq(Face::getPersonId, 1l)
|
||||
.update(face);
|
||||
List<Float> vector = new ArrayList<>();
|
||||
for (int i = 0; i < 128; i++) {
|
||||
vector.add((float) (Math.random() * 100)); // 这里仅作为示例使用随机数
|
||||
}
|
||||
face.setPersonId(1l);
|
||||
MilvusResp<UpsertResp> update2 = mapper.updateById(face);
|
||||
|
||||
face.setFaceVector(vector);
|
||||
//新增
|
||||
MilvusResp<InsertResp> insert = mapper.insertWrapper()
|
||||
.put(Face::getFaceVector, vector)
|
||||
.insert();
|
||||
MilvusResp<InsertResp> insert2 = mapper.insert(face);
|
||||
List<Face> faces=new ArrayList<>();
|
||||
for (int i = 1; i < 10 ;i++){
|
||||
Face face1=new 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));
|
||||
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user