(improvement)(common) Upgraded langchain4j to version 0.31. (#1174)

This commit is contained in:
lexluo09
2024-06-20 17:31:19 +08:00
committed by GitHub
parent 1df1fe5ad6
commit 92db381b6f
37 changed files with 241 additions and 888 deletions

View File

@@ -86,7 +86,7 @@ public class InMemoryS2EmbeddingStore implements S2EmbeddingStore {
@Override
public void addQuery(String collectionName, List<EmbeddingQuery> queries) {
InMemoryEmbeddingStore<EmbeddingQuery> embeddingStore = getEmbeddingStore(collectionName);
EmbeddingModel embeddingModel = ContextUtils.getBean(EmbeddingModel.class);
EmbeddingModel embeddingModel = getEmbeddingModel();
for (EmbeddingQuery query : queries) {
String question = query.getQuery();
Embedding embedding = embeddingModel.embed(question).content();
@@ -94,6 +94,10 @@ public class InMemoryS2EmbeddingStore implements S2EmbeddingStore {
}
}
private static EmbeddingModel getEmbeddingModel() {
return ContextUtils.getBean(EmbeddingModel.class);
}
private InMemoryEmbeddingStore<EmbeddingQuery> getEmbeddingStore(String collectionName) {
InMemoryEmbeddingStore<EmbeddingQuery> embeddingStore = collectionNameToStore.get(collectionName);
if (Objects.isNull(embeddingStore)) {
@@ -113,7 +117,7 @@ public class InMemoryS2EmbeddingStore implements S2EmbeddingStore {
@Override
public List<RetrieveQueryResult> retrieveQuery(String collectionName, RetrieveQuery retrieveQuery, int num) {
InMemoryEmbeddingStore<EmbeddingQuery> embeddingStore = getEmbeddingStore(collectionName);
EmbeddingModel embeddingModel = ContextUtils.getBean(EmbeddingModel.class);
EmbeddingModel embeddingModel = getEmbeddingModel();
List<RetrieveQueryResult> results = new ArrayList<>();