mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-14 13:47:09 +00:00
(improvement)(Headless) Periodically refresh embedding metadata in full and optimize the code. (#917)
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
package com.tencent.supersonic.common.util.embedding;
|
||||
|
||||
import com.tencent.supersonic.common.util.ComponentFactory;
|
||||
import javax.annotation.PreDestroy;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class EmbeddingPersistentTask {
|
||||
|
||||
private S2EmbeddingStore s2EmbeddingStore = ComponentFactory.getS2EmbeddingStore();
|
||||
|
||||
@PreDestroy
|
||||
public void onShutdown() {
|
||||
embeddingStorePersistentToFile();
|
||||
}
|
||||
|
||||
private void embeddingStorePersistentToFile() {
|
||||
if (s2EmbeddingStore instanceof InMemoryS2EmbeddingStore) {
|
||||
log.info("start persistentToFile");
|
||||
((InMemoryS2EmbeddingStore) s2EmbeddingStore).persistentToFile();
|
||||
log.info("end persistentToFile");
|
||||
}
|
||||
}
|
||||
|
||||
@Scheduled(cron = "${inMemoryEmbeddingStore.persistent.cron:0 0 * * * ?}")
|
||||
public void executeTask() {
|
||||
embeddingStorePersistentToFile();
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.tencent.supersonic.common.util.embedding;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.tencent.supersonic.common.pojo.DataItem;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Data
|
||||
public class EmbeddingQuery {
|
||||
@@ -17,4 +20,17 @@ public class EmbeddingQuery {
|
||||
|
||||
private List<Double> queryEmbedding;
|
||||
|
||||
public static List<EmbeddingQuery> convertToEmbedding(List<DataItem> dataItems) {
|
||||
return dataItems.stream().map(dataItem -> {
|
||||
EmbeddingQuery embeddingQuery = new EmbeddingQuery();
|
||||
embeddingQuery.setQueryId(
|
||||
dataItem.getId() + dataItem.getType().name().toLowerCase());
|
||||
embeddingQuery.setQuery(dataItem.getName());
|
||||
Map meta = JSONObject.parseObject(JSONObject.toJSONString(dataItem), Map.class);
|
||||
embeddingQuery.setMetadata(meta);
|
||||
embeddingQuery.setQueryEmbedding(null);
|
||||
return embeddingQuery;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user