Browse Source

fix: 存入向量库数据存在ID字段引起报错问题

zhongwei
haungxing 3 months ago
parent
commit
663bb18677
  1. 13
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/service/WeaviateService.java

13
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/service/WeaviateService.java

@ -92,7 +92,10 @@ public class WeaviateService {
// log.info("vector:{}",JSON.toJSONString(vector.get(i)));
Map<String, Object> properties = this.objectToMap(entities.get(i));
log.info("properties:{}",JSON.toJSONString(properties));
creator.withProperties(properties).withVectors(vector.get(i)).run();
Result<WeaviateObject> run = creator.withProperties(properties).withVectors(vector.get(i)).run();
if(run.hasErrors()) {
log.error("保存失败!,保存结果为:{}",JSON.toJSONString(run));
}
}
} else {
entities.forEach(entity -> creator.withProperties(this.objectToMap(entity)).run());
@ -104,7 +107,13 @@ public class WeaviateService {
private Map<String,Object> objectToMap(Object object) {
JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(object));
Map<String,Object> properties = new HashMap<>();
jsonObject.forEach((k,v) -> properties.put(k,v));
jsonObject.forEach((k,v) -> {
if("id".equalsIgnoreCase(k)) {
properties.put("id_",v);
} else {
properties.put(k,v);
}
});
return properties;
}

Loading…
Cancel
Save