Skip to content

Commit 8e08cb0

Browse files
committed
rebase
1 parent db32740 commit 8e08cb0

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

vector-stores/spring-ai-elasticsearch-store/src/main/java/org/springframework/ai/vectorstore/ElasticsearchVectorStore.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
/**
4949
* @author Jemin Huh
5050
* @author Wei Jiang
51+
* @author Laura Trotta
5152
* @since 1.0.0
5253
*/
5354
public class ElasticsearchVectorStore implements VectorStore, InitializingBean {
@@ -62,8 +63,6 @@ public class ElasticsearchVectorStore implements VectorStore, InitializingBean {
6263

6364
private final FilterExpressionConverter filterExpressionConverter;
6465

65-
private String similarityFunction;
66-
6766
private final boolean initializeSchema;
6867

6968
public ElasticsearchVectorStore(RestClient restClient, EmbeddingModel embeddingModel, boolean initializeSchema) {
@@ -134,7 +133,7 @@ public List<Document> similaritySearch(SearchRequest searchRequest) {
134133
threshold = 1 - threshold;
135134
}
136135
final float finalThreshold = threshold;
137-
List<Float> vectors = this.embeddingClient.embed(searchRequest.getQuery())
136+
List<Float> vectors = this.embeddingModel.embed(searchRequest.getQuery())
138137
.stream()
139138
.map(Double::floatValue)
140139
.toList();
@@ -151,7 +150,6 @@ public List<Document> similaritySearch(SearchRequest searchRequest) {
151150
Document.class);
152151

153152
return res.hits().hits().stream().map(this::toDocument).collect(Collectors.toList());
154-
155153
}
156154
catch (IOException e) {
157155
throw new RuntimeException(e);
@@ -219,4 +217,4 @@ public void afterPropertiesSet() {
219217
}
220218
}
221219

222-
}
220+
}

vector-stores/spring-ai-elasticsearch-store/src/main/java/org/springframework/ai/vectorstore/SimilarityFunction.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package org.springframework.ai.vectorstore;
22

3-
/*
4-
https://www.elastic.co/guide/en/elasticsearch/reference/master/dense-vector.html
5-
max_inner_product is currently not supported because the distance value is not
6-
normalized and would not comply with the requirement of being between 0 and 1
7-
*/
3+
/**
4+
* https://www.elastic.co/guide/en/elasticsearch/reference/master/dense-vector.html
5+
* max_inner_product is currently not supported because the distance value is not
6+
* normalized and would not comply with the requirement of being between 0 and 1
7+
*
8+
* @author Laura Trotta
9+
* @since 1.0.0
10+
*/
811
public enum SimilarityFunction {
912

1013
l2_norm, dot_product, cosine

vector-stores/spring-ai-elasticsearch-store/src/test/java/org/springframework/ai/vectorstore/ElasticsearchVectorStoreIT.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class ElasticsearchVectorStoreIT {
6464

6565
@Container
6666
private static final ElasticsearchContainer elasticsearchContainer = new ElasticsearchContainer(
67-
"docker.elastic.co/elasticsearch/elasticsearch:8.12.2")
67+
"docker.elastic.co/elasticsearch/elasticsearch:8.13.3")
6868
.withEnv("xpack.security.enabled", "false");
6969

7070
private final List<Document> documents = List.of(
@@ -338,24 +338,24 @@ public void searchThresholdTest(String similarityFunction) {
338338
public static class TestApplication {
339339

340340
@Bean("vectorStore_cosine")
341-
public ElasticsearchVectorStore vectorStoreDefault(EmbeddingClient embeddingClient, RestClient restClient) {
342-
return new ElasticsearchVectorStore(restClient, embeddingClient);
341+
public ElasticsearchVectorStore vectorStoreDefault(EmbeddingModel embeddingModel, RestClient restClient) {
342+
return new ElasticsearchVectorStore(restClient, embeddingModel, true);
343343
}
344344

345345
@Bean("vectorStore_l2_norm")
346-
public ElasticsearchVectorStore vectorStoreL2(EmbeddingClient embeddingClient, RestClient restClient) {
346+
public ElasticsearchVectorStore vectorStoreL2(EmbeddingModel embeddingModel, RestClient restClient) {
347347
ElasticsearchVectorStoreOptions options = new ElasticsearchVectorStoreOptions();
348348
options.setIndexName("index_l2");
349349
options.setSimilarity(SimilarityFunction.l2_norm);
350-
return new ElasticsearchVectorStore(options, restClient, embeddingClient);
350+
return new ElasticsearchVectorStore(options, restClient, embeddingModel,true);
351351
}
352352

353353
@Bean("vectorStore_dot_product")
354-
public ElasticsearchVectorStore vectorStoreDotProduct(EmbeddingClient embeddingClient, RestClient restClient) {
354+
public ElasticsearchVectorStore vectorStoreDotProduct(EmbeddingModel embeddingModel, RestClient restClient) {
355355
ElasticsearchVectorStoreOptions options = new ElasticsearchVectorStoreOptions();
356356
options.setIndexName("index_dot_product");
357357
options.setSimilarity(SimilarityFunction.dot_product);
358-
return new ElasticsearchVectorStore(options, restClient, embeddingClient);
358+
return new ElasticsearchVectorStore(options, restClient, embeddingModel,true);
359359
}
360360

361361
@Bean

0 commit comments

Comments
 (0)