[improvement](headless) Optimize the reload embedding interface (#1655)

This commit is contained in:
lexluo09
2024-09-11 22:52:46 +08:00
committed by GitHub
parent 51e7a9bcd7
commit ff0833ddfa
3 changed files with 20 additions and 15 deletions

View File

@@ -12,4 +12,6 @@ public interface ExemplarService {
List<Text2SQLExemplar> recallExemplars(String collection, String query, int num);
List<Text2SQLExemplar> recallExemplars(String query, int num);
void loadSysExemplars();
}

View File

@@ -20,7 +20,6 @@ import org.springframework.core.annotation.Order;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
@@ -88,18 +87,18 @@ public class ExemplarServiceImpl implements ExemplarService, CommandLineRunner {
@Override
public void run(String... args) {
loadSysExemplars();
}
public void loadSysExemplars() {
try {
loadSysExemplars();
ClassPathResource resource = new ClassPathResource(SYS_EXEMPLAR_FILE);
InputStream inputStream = resource.getInputStream();
List<Text2SQLExemplar> exemplars = objectMapper.readValue(inputStream, valueTypeRef);
String collection = embeddingConfig.getText2sqlCollectionName();
exemplars.stream().forEach(e -> storeExemplar(collection, e));
} catch (Exception e) {
log.error("Failed to load system exemplars", e);
}
}
private void loadSysExemplars() throws IOException {
ClassPathResource resource = new ClassPathResource(SYS_EXEMPLAR_FILE);
InputStream inputStream = resource.getInputStream();
List<Text2SQLExemplar> exemplars = objectMapper.readValue(inputStream, valueTypeRef);
String collection = embeddingConfig.getText2sqlCollectionName();
exemplars.stream().forEach(e -> storeExemplar(collection, e));
}
}