|
|
|
@ -90,19 +90,24 @@ public class WeaviateService {
|
|
|
|
|
List<Map<String, Float[]>> vector = this.splitVector(entities.size(), attrsMap, vectors); |
|
|
|
|
for(int i = 0; i < entities.size(); i++) { |
|
|
|
|
// log.info("vector:{}",JSON.toJSONString(vector.get(i)));
|
|
|
|
|
JSONObject object = JSONObject.parseObject(JSON.toJSONString(entities.get(i))); |
|
|
|
|
Map<String,Object> properties = new HashMap<>(); |
|
|
|
|
object.forEach((k,v) -> properties.put(k,v)); |
|
|
|
|
Map<String, Object> properties = this.objectToMap(entities.get(i)); |
|
|
|
|
log.info("properties:{}",JSON.toJSONString(properties)); |
|
|
|
|
creator.withProperties(properties).withVectors(vector.get(i)).run(); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
entities.forEach(entity -> creator.withProperties(BeanUtil.toMap(entity)).run()); |
|
|
|
|
entities.forEach(entity -> creator.withProperties(this.objectToMap(entity)).run()); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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)); |
|
|
|
|
return properties; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 删除向量数据库(表名) |
|
|
|
|
* @param className 表名 |
|
|
|
@ -204,16 +209,8 @@ public class WeaviateService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String getFieldValue(String fields,Object object) { |
|
|
|
|
Class clazz = object.getClass(); |
|
|
|
|
return Func.toStrList(",", fields).stream().map(field -> { |
|
|
|
|
try { |
|
|
|
|
Field declaredField = clazz.getDeclaredField(field); |
|
|
|
|
declaredField.setAccessible(true); |
|
|
|
|
return declaredField.get(object).toString(); |
|
|
|
|
} catch (NoSuchFieldException | IllegalAccessException e) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
}).collect(Collectors.joining(" ")); |
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(object)); |
|
|
|
|
return Func.toStrList(",", fields).stream().map(field -> jsonObject.getString(field)).collect(Collectors.joining(" ")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|