org.springframework.ai
diff --git a/vector-stores/spring-ai-oracle-store/src/main/java/org/springframework/ai/vectorstore/OracleVectorStore.java b/vector-stores/spring-ai-oracle-store/src/main/java/org/springframework/ai/vectorstore/OracleVectorStore.java
index a32a904eb87..a9e3b63eb79 100644
--- a/vector-stores/spring-ai-oracle-store/src/main/java/org/springframework/ai/vectorstore/OracleVectorStore.java
+++ b/vector-stores/spring-ai-oracle-store/src/main/java/org/springframework/ai/vectorstore/OracleVectorStore.java
@@ -56,9 +56,6 @@
import org.springframework.jdbc.core.RowMapper;
import org.springframework.util.StringUtils;
-import static org.springframework.ai.vectorstore.OracleVectorStore.OracleVectorStoreDistanceType.DOT;
-import static org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue;
-
/**
*
* Integration of Oracle database 23ai as a Vector Store.
@@ -217,10 +214,13 @@ public void setValues(PreparedStatement ps, int i) throws SQLException {
final byte[] json = toJson(document.getMetadata());
final VECTOR embeddingVector = toVECTOR(document.getEmbedding());
- setParameterValue(ps, 1, Types.VARCHAR, document.getId());
- setParameterValue(ps, 2, Types.VARCHAR, content);
- setParameterValue(ps, 3, OracleType.JSON.getVendorTypeNumber(), json);
- setParameterValue(ps, 4, OracleType.VECTOR.getVendorTypeNumber(), embeddingVector);
+ org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(ps, 1, Types.VARCHAR,
+ document.getId());
+ org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(ps, 2, Types.VARCHAR, content);
+ org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(ps, 3,
+ OracleType.JSON.getVendorTypeNumber(), json);
+ org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(ps, 4,
+ OracleType.VECTOR.getVendorTypeNumber(), embeddingVector);
}
@Override
@@ -357,7 +357,8 @@ public List doSimilaritySearch(SearchRequest request) {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
- setParameterValue(ps, 1, OracleType.VECTOR.getVendorTypeNumber(), embeddingVector);
+ org.springframework.jdbc.core.StatementCreatorUtils.setParameterValue(ps, 1,
+ OracleType.VECTOR.getVendorTypeNumber(), embeddingVector);
}
@Override
@@ -381,17 +382,25 @@ public int getBatchSize() {
select id, content, metadata, embedding, %sVECTOR_DISTANCE(embedding, ?, %s)%s as distance
from %s
%sorder by distance
- fetch first %d rows only""", this.distanceType == DOT ? "(1+" : "", this.distanceType.name(),
- this.distanceType == DOT ? ")/2" : "", this.tableName, jsonPathFilter, request.getTopK())
+ fetch first %d rows only""",
+ this.distanceType == org.springframework.ai.vectorstore.OracleVectorStore.OracleVectorStoreDistanceType.DOT
+ ? "(1+" : "",
+ this.distanceType.name(),
+ this.distanceType == org.springframework.ai.vectorstore.OracleVectorStore.OracleVectorStoreDistanceType.DOT
+ ? ")/2" : "",
+ this.tableName, jsonPathFilter, request.getTopK())
: String.format(
"""
select id, content, metadata, embedding, %sVECTOR_DISTANCE(embedding, ?, %s)%s as distance
from %s
%sorder by distance
fetch APPROXIMATE first %d rows only WITH TARGET ACCURACY %d""",
- this.distanceType == DOT ? "(1+" : "", this.distanceType.name(),
- this.distanceType == DOT ? ")/2" : "", this.tableName, jsonPathFilter,
- request.getTopK(), this.searchAccuracy);
+ this.distanceType == org.springframework.ai.vectorstore.OracleVectorStore.OracleVectorStoreDistanceType.DOT
+ ? "(1+" : "",
+ this.distanceType.name(),
+ this.distanceType == org.springframework.ai.vectorstore.OracleVectorStore.OracleVectorStoreDistanceType.DOT
+ ? ")/2" : "",
+ this.tableName, jsonPathFilter, request.getTopK(), this.searchAccuracy);
logger.debug("SQL query: " + sql);
@@ -406,60 +415,69 @@ else if (request.getSimilarityThreshold() == SIMILARITY_THRESHOLD_EXACT_MATCH) {
select id, content, metadata, embedding, %sVECTOR_DISTANCE(embedding, ?, %s)%s as distance
from %s
%sorder by distance
- fetch EXACT first %d rows only""", this.distanceType == DOT ? "(1+" : "",
- this.distanceType.name(), this.distanceType == DOT ? ")/2" : "", this.tableName, jsonPathFilter,
- request.getTopK());
+ fetch EXACT first %d rows only""",
+ this.distanceType == org.springframework.ai.vectorstore.OracleVectorStore.OracleVectorStoreDistanceType.DOT
+ ? "(1+" : "",
+ this.distanceType.name(),
+ this.distanceType == org.springframework.ai.vectorstore.OracleVectorStore.OracleVectorStoreDistanceType.DOT
+ ? ")/2" : "",
+ this.tableName, jsonPathFilter, request.getTopK());
logger.debug("SQL query: " + sql);
return this.jdbcTemplate.query(sql, new DocumentRowMapper(), embeddingVector);
}
else {
- if (!this.forcedNormalization
- || (this.distanceType != OracleVectorStoreDistanceType.COSINE && this.distanceType != DOT)) {
+ if (!this.forcedNormalization || (this.distanceType != OracleVectorStoreDistanceType.COSINE
+ && this.distanceType != org.springframework.ai.vectorstore.OracleVectorStore.OracleVectorStoreDistanceType.DOT)) {
throw new RuntimeException(
"Similarity threshold filtering requires all vectors to be normalized, see the forcedNormalization parameter for this Vector store. Also only COSINE and DOT distance types are supported.");
}
- final double distance = this.distanceType == DOT ? (1d - request.getSimilarityThreshold()) * 2d - 1d
- : 1d - request.getSimilarityThreshold();
+ final double distance = this.distanceType == org.springframework.ai.vectorstore.OracleVectorStore.OracleVectorStoreDistanceType.DOT
+ ? (1d - request.getSimilarityThreshold()) * 2d - 1d : 1d - request.getSimilarityThreshold();
if (StringUtils.hasText(nativeFilterExpression)) {
jsonPathFilter = String.format(" and JSON_EXISTS( metadata, '%s' )", nativeFilterExpression);
}
- final String sql = this.distanceType == DOT ? (this.searchAccuracy == DEFAULT_SEARCH_ACCURACY
- ? String.format(
- """
- select id, content, metadata, embedding, (1+VECTOR_DISTANCE(embedding, ?, DOT))/2 as distance
- from %s
- where VECTOR_DISTANCE(embedding, ?, DOT) <= ?%s
- order by distance
- fetch first %d rows only""",
- this.tableName, jsonPathFilter, request.getTopK())
- : String.format(
- """
- select id, content, metadata, embedding, (1+VECTOR_DISTANCE(embedding, ?, DOT))/2 as distance
- from %s
- where VECTOR_DISTANCE(embedding, ?, DOT) <= ?%s
- order by distance
- fetch APPROXIMATE first %d rows only WITH TARGET ACCURACY %d""",
- this.tableName, jsonPathFilter, request.getTopK(), this.searchAccuracy)
-
- ) : (this.searchAccuracy == DEFAULT_SEARCH_ACCURACY ? String.format("""
- select id, content, metadata, embedding, VECTOR_DISTANCE(embedding, ?, COSINE) as distance
- from %s
- where VECTOR_DISTANCE(embedding, ?, COSINE) <= ?%s
- order by distance
- fetch first %d rows only""", this.tableName, jsonPathFilter, request.getTopK())
- : String.format(
- """
- select id, content, metadata, embedding, VECTOR_DISTANCE(embedding, ?, COSINE) as distance
- from %s
- where VECTOR_DISTANCE(embedding, ?, COSINE) <= ?%s
- order by distance
- fetch APPROXIMATE first %d rows only WITH TARGET ACCURACY %d""",
- this.tableName, jsonPathFilter, request.getTopK(), this.searchAccuracy));
+ final String sql = this.distanceType == org.springframework.ai.vectorstore.OracleVectorStore.OracleVectorStoreDistanceType.DOT
+ ? (this.searchAccuracy == DEFAULT_SEARCH_ACCURACY
+ ? String.format(
+ """
+ select id, content, metadata, embedding, (1+VECTOR_DISTANCE(embedding, ?, DOT))/2 as distance
+ from %s
+ where VECTOR_DISTANCE(embedding, ?, DOT) <= ?%s
+ order by distance
+ fetch first %d rows only""",
+ this.tableName, jsonPathFilter, request.getTopK())
+ : String.format(
+ """
+ select id, content, metadata, embedding, (1+VECTOR_DISTANCE(embedding, ?, DOT))/2 as distance
+ from %s
+ where VECTOR_DISTANCE(embedding, ?, DOT) <= ?%s
+ order by distance
+ fetch APPROXIMATE first %d rows only WITH TARGET ACCURACY %d""",
+ this.tableName, jsonPathFilter, request.getTopK(), this.searchAccuracy)
+
+ )
+ : (this.searchAccuracy == DEFAULT_SEARCH_ACCURACY
+ ? String.format(
+ """
+ select id, content, metadata, embedding, VECTOR_DISTANCE(embedding, ?, COSINE) as distance
+ from %s
+ where VECTOR_DISTANCE(embedding, ?, COSINE) <= ?%s
+ order by distance
+ fetch first %d rows only""",
+ this.tableName, jsonPathFilter, request.getTopK())
+ : String.format(
+ """
+ select id, content, metadata, embedding, VECTOR_DISTANCE(embedding, ?, COSINE) as distance
+ from %s
+ where VECTOR_DISTANCE(embedding, ?, COSINE) <= ?%s
+ order by distance
+ fetch APPROXIMATE first %d rows only WITH TARGET ACCURACY %d""",
+ this.tableName, jsonPathFilter, request.getTopK(), this.searchAccuracy));
logger.debug("SQL query: " + sql);
@@ -503,10 +521,10 @@ embedding vector(%s,FLOAT64) annotations(Distance '%s')
this.jdbcTemplate.execute(String.format("""
create vector index if not exists vector_index_%s on %s (embedding)
organization neighbor partitions
- distance %s
- with target accuracy %d
- parameters (type IVF, neighbor partitions 10)""", this.tableName,
- this.tableName, this.distanceType.name(),
+ distance %s
+ with target accuracy %d
+ parameters (type IVF, neighbor partitions 10)""", this.tableName, this.tableName,
+ this.distanceType.name(),
this.searchAccuracy == DEFAULT_SEARCH_ACCURACY ? 95 : this.searchAccuracy));
break;
@@ -585,7 +603,7 @@ public enum OracleVectorStoreIndexType {
* "https://docs.oracle.com/en/database/oracle/oracle-database/23/vecse/understand-inverted-file-flat-vector-indexes.html">Oracle
* Database documentation
*/
- IVF;
+ IVF
}
diff --git a/vector-stores/spring-ai-oracle-store/src/test/java/org/springframework/ai/vectorstore/OracleImage.java b/vector-stores/spring-ai-oracle-store/src/test/java/org/springframework/ai/vectorstore/OracleImage.java
index 6955a660680..85816879f4d 100644
--- a/vector-stores/spring-ai-oracle-store/src/test/java/org/springframework/ai/vectorstore/OracleImage.java
+++ b/vector-stores/spring-ai-oracle-store/src/test/java/org/springframework/ai/vectorstore/OracleImage.java
@@ -21,8 +21,12 @@
/**
* @author Thomas Vitale
*/
-public class OracleImage {
+public final class OracleImage {
public static final DockerImageName DEFAULT_IMAGE = DockerImageName.parse("gvenzl/oracle-free:23-slim");
+ private OracleImage() {
+
+ }
+
}
diff --git a/vector-stores/spring-ai-oracle-store/src/test/java/org/springframework/ai/vectorstore/OracleVectorStoreIT.java b/vector-stores/spring-ai-oracle-store/src/test/java/org/springframework/ai/vectorstore/OracleVectorStoreIT.java
index 638db84b57f..00c9a4302d0 100644
--- a/vector-stores/spring-ai-oracle-store/src/test/java/org/springframework/ai/vectorstore/OracleVectorStoreIT.java
+++ b/vector-stores/spring-ai-oracle-store/src/test/java/org/springframework/ai/vectorstore/OracleVectorStoreIT.java
@@ -55,7 +55,6 @@
import org.springframework.util.CollectionUtils;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.springframework.ai.vectorstore.OracleVectorStore.DEFAULT_SEARCH_ACCURACY;
@Testcontainers
public class OracleVectorStoreIT {
@@ -119,7 +118,8 @@ private static boolean isSortedByDistance(final List documents) {
@ValueSource(strings = { "COSINE", "DOT", "EUCLIDEAN", "EUCLIDEAN_SQUARED", "MANHATTAN" })
public void addAndSearch(String distanceType) {
this.contextRunner.withPropertyValues("test.spring.ai.vectorstore.oracle.distanceType=" + distanceType)
- .withPropertyValues("test.spring.ai.vectorstore.oracle.searchAccuracy=" + DEFAULT_SEARCH_ACCURACY)
+ .withPropertyValues("test.spring.ai.vectorstore.oracle.searchAccuracy="
+ + org.springframework.ai.vectorstore.OracleVectorStore.DEFAULT_SEARCH_ACCURACY)
.run(context -> {
VectorStore vectorStore = context.getBean(VectorStore.class);
@@ -224,7 +224,8 @@ public void searchWithFilters(String distanceType, int searchAccuracy) {
@ValueSource(strings = { "COSINE", "DOT", "EUCLIDEAN", "EUCLIDEAN_SQUARED", "MANHATTAN" })
public void documentUpdate(String distanceType) {
this.contextRunner.withPropertyValues("test.spring.ai.vectorstore.oracle.distanceType=" + distanceType)
- .withPropertyValues("test.spring.ai.vectorstore.oracle.searchAccuracy=" + DEFAULT_SEARCH_ACCURACY)
+ .withPropertyValues("test.spring.ai.vectorstore.oracle.searchAccuracy="
+ + org.springframework.ai.vectorstore.OracleVectorStore.DEFAULT_SEARCH_ACCURACY)
.run(context -> {
VectorStore vectorStore = context.getBean(VectorStore.class);
@@ -263,7 +264,8 @@ public void documentUpdate(String distanceType) {
@ValueSource(strings = { "COSINE", "DOT" })
public void searchWithThreshold(String distanceType) {
this.contextRunner.withPropertyValues("test.spring.ai.vectorstore.oracle.distanceType=" + distanceType)
- .withPropertyValues("test.spring.ai.vectorstore.oracle.searchAccuracy=" + DEFAULT_SEARCH_ACCURACY)
+ .withPropertyValues("test.spring.ai.vectorstore.oracle.searchAccuracy="
+ + org.springframework.ai.vectorstore.OracleVectorStore.DEFAULT_SEARCH_ACCURACY)
.run(context -> {
VectorStore vectorStore = context.getBean(VectorStore.class);
diff --git a/vector-stores/spring-ai-pgvector-store/pom.xml b/vector-stores/spring-ai-pgvector-store/pom.xml
index 7f3f5341623..c36221d7e49 100644
--- a/vector-stores/spring-ai-pgvector-store/pom.xml
+++ b/vector-stores/spring-ai-pgvector-store/pom.xml
@@ -36,6 +36,12 @@
git@github.com:spring-projects/spring-ai.git
+
+ 17
+ 17
+ false
+
+
org.springframework.ai
diff --git a/vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/PgVectorFilterExpressionConverter.java b/vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/PgVectorFilterExpressionConverter.java
index 06db63670c7..814de5b4c49 100644
--- a/vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/PgVectorFilterExpressionConverter.java
+++ b/vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/PgVectorFilterExpressionConverter.java
@@ -115,4 +115,4 @@ protected void doEndGroup(Group group, StringBuilder context) {
context.append(")");
}
-}
\ No newline at end of file
+}
diff --git a/vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/PgVectorStore.java b/vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/PgVectorStore.java
index 56bb866e61b..69cd79b41c4 100644
--- a/vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/PgVectorStore.java
+++ b/vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/PgVectorStore.java
@@ -489,7 +489,7 @@ private static class DocumentRowMapper implements RowMapper {
private final ObjectMapper objectMapper;
- public DocumentRowMapper(ObjectMapper objectMapper) {
+ DocumentRowMapper(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
}
diff --git a/vector-stores/spring-ai-pgvector-store/src/test/java/org/springframework/ai/vectorstore/PgVectorEmbeddingDimensionsTests.java b/vector-stores/spring-ai-pgvector-store/src/test/java/org/springframework/ai/vectorstore/PgVectorEmbeddingDimensionsTests.java
index efef6d9135e..587b2cb8e02 100644
--- a/vector-stores/spring-ai-pgvector-store/src/test/java/org/springframework/ai/vectorstore/PgVectorEmbeddingDimensionsTests.java
+++ b/vector-stores/spring-ai-pgvector-store/src/test/java/org/springframework/ai/vectorstore/PgVectorEmbeddingDimensionsTests.java
@@ -25,10 +25,10 @@
import org.springframework.jdbc.core.JdbcTemplate;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.only;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
/**
* @author Christian Tzolov
@@ -55,7 +55,7 @@ public void explicitlySetDimensions() {
@Test
public void embeddingModelDimensions() {
- when(this.embeddingModel.dimensions()).thenReturn(969);
+ given(this.embeddingModel.dimensions()).willReturn(969);
var dim = new PgVectorStore(this.jdbcTemplate, this.embeddingModel).embeddingDimensions();
@@ -67,7 +67,7 @@ public void embeddingModelDimensions() {
@Test
public void fallBackToDefaultDimensions() {
- when(this.embeddingModel.dimensions()).thenThrow(new RuntimeException());
+ given(this.embeddingModel.dimensions()).willThrow(new RuntimeException());
var dim = new PgVectorStore(this.jdbcTemplate, this.embeddingModel).embeddingDimensions();
diff --git a/vector-stores/spring-ai-pgvector-store/src/test/java/org/springframework/ai/vectorstore/PgVectorImage.java b/vector-stores/spring-ai-pgvector-store/src/test/java/org/springframework/ai/vectorstore/PgVectorImage.java
index 0df031e63cd..2dead75a532 100644
--- a/vector-stores/spring-ai-pgvector-store/src/test/java/org/springframework/ai/vectorstore/PgVectorImage.java
+++ b/vector-stores/spring-ai-pgvector-store/src/test/java/org/springframework/ai/vectorstore/PgVectorImage.java
@@ -21,8 +21,12 @@
/**
* @author Thomas Vitale
*/
-public class PgVectorImage {
+public final class PgVectorImage {
public static final DockerImageName DEFAULT_IMAGE = DockerImageName.parse("pgvector/pgvector:pg17");
+ private PgVectorImage() {
+
+ }
+
}
diff --git a/vector-stores/spring-ai-pgvector-store/src/test/java/org/springframework/ai/vectorstore/PgVectorStoreIT.java b/vector-stores/spring-ai-pgvector-store/src/test/java/org/springframework/ai/vectorstore/PgVectorStoreIT.java
index 8405d32337f..3366c88296b 100644
--- a/vector-stores/spring-ai-pgvector-store/src/test/java/org/springframework/ai/vectorstore/PgVectorStoreIT.java
+++ b/vector-stores/spring-ai-pgvector-store/src/test/java/org/springframework/ai/vectorstore/PgVectorStoreIT.java
@@ -122,7 +122,8 @@ private static boolean isSortedByDistance(List docs) {
}
Iterator iter = distances.iterator();
- Float current, previous = iter.next();
+ Float current;
+ Float previous = iter.next();
while (iter.hasNext()) {
current = iter.next();
if (previous > current) {
diff --git a/vector-stores/spring-ai-pgvector-store/src/test/java/org/springframework/ai/vectorstore/PgVectorStoreWithChatMemoryAdvisorIT.java b/vector-stores/spring-ai-pgvector-store/src/test/java/org/springframework/ai/vectorstore/PgVectorStoreWithChatMemoryAdvisorIT.java
index abde63cfe84..9a66e35518b 100644
--- a/vector-stores/spring-ai-pgvector-store/src/test/java/org/springframework/ai/vectorstore/PgVectorStoreWithChatMemoryAdvisorIT.java
+++ b/vector-stores/spring-ai-pgvector-store/src/test/java/org/springframework/ai/vectorstore/PgVectorStoreWithChatMemoryAdvisorIT.java
@@ -44,9 +44,9 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
/**
* @author Fabian Krüger
@@ -71,7 +71,7 @@ class PgVectorStoreWithChatMemoryAdvisorIT {
Why don't scientists trust atoms?
Because they make up everything!
"""))));
- when(chatModel.call(argumentCaptor.capture())).thenReturn(chatResponse);
+ given(chatModel.call(argumentCaptor.capture())).willReturn(chatResponse);
return chatModel;
}
@@ -153,7 +153,7 @@ void advisedChatShouldHaveSimilarMessagesFromVectorStore() throws Exception {
documents.forEach(d -> d.setEmbedding(this.embed));
return List.of(this.embed, this.embed);
}).when(embeddingModel).embed(ArgumentMatchers.any(), any(), any());
- when(embeddingModel.embed(any(String.class))).thenReturn(this.embed);
+ given(embeddingModel.embed(any(String.class))).willReturn(this.embed);
return embeddingModel;
}
diff --git a/vector-stores/spring-ai-pinecone-store/pom.xml b/vector-stores/spring-ai-pinecone-store/pom.xml
index 87b2722c561..8603595fb88 100644
--- a/vector-stores/spring-ai-pinecone-store/pom.xml
+++ b/vector-stores/spring-ai-pinecone-store/pom.xml
@@ -38,6 +38,7 @@
17
17
+ false
diff --git a/vector-stores/spring-ai-pinecone-store/src/main/java/org/springframework/ai/vectorstore/PineconeVectorStore.java b/vector-stores/spring-ai-pinecone-store/src/main/java/org/springframework/ai/vectorstore/PineconeVectorStore.java
index f4243653b07..42413456095 100644
--- a/vector-stores/spring-ai-pinecone-store/src/main/java/org/springframework/ai/vectorstore/PineconeVectorStore.java
+++ b/vector-stores/spring-ai-pinecone-store/src/main/java/org/springframework/ai/vectorstore/PineconeVectorStore.java
@@ -343,7 +343,7 @@ public static PineconeVectorStoreConfig defaultConfig() {
return builder().build();
}
- public static class Builder {
+ public static final class Builder {
private String apiKey;
diff --git a/vector-stores/spring-ai-pinecone-store/src/test/java/org/springframework/ai/vectorstore/PineconeVectorStoreIT.java b/vector-stores/spring-ai-pinecone-store/src/test/java/org/springframework/ai/vectorstore/PineconeVectorStoreIT.java
index 917abaf4745..6e1eddc5f32 100644
--- a/vector-stores/spring-ai-pinecone-store/src/test/java/org/springframework/ai/vectorstore/PineconeVectorStoreIT.java
+++ b/vector-stores/spring-ai-pinecone-store/src/test/java/org/springframework/ai/vectorstore/PineconeVectorStoreIT.java
@@ -97,9 +97,9 @@ public void addAndSearchTest() {
vectorStore.add(this.documents);
- Awaitility.await().until(() -> {
- return vectorStore.similaritySearch(SearchRequest.query("Great Depression").withTopK(1));
- }, hasSize(1));
+ Awaitility.await()
+ .until(() -> vectorStore.similaritySearch(SearchRequest.query("Great Depression").withTopK(1)),
+ hasSize(1));
List results = vectorStore.similaritySearch(SearchRequest.query("Great Depression").withTopK(1));
@@ -114,9 +114,8 @@ public void addAndSearchTest() {
// Remove all documents from the store
vectorStore.delete(this.documents.stream().map(doc -> doc.getId()).toList());
- Awaitility.await().until(() -> {
- return vectorStore.similaritySearch(SearchRequest.query("Hello").withTopK(1));
- }, hasSize(0));
+ Awaitility.await()
+ .until(() -> vectorStore.similaritySearch(SearchRequest.query("Hello").withTopK(1)), hasSize(0));
});
}
@@ -139,9 +138,7 @@ public void addAndSearchWithFilters() {
SearchRequest searchRequest = SearchRequest.query("The World");
- Awaitility.await().until(() -> {
- return vectorStore.similaritySearch(searchRequest.withTopK(1));
- }, hasSize(1));
+ Awaitility.await().until(() -> vectorStore.similaritySearch(searchRequest.withTopK(1)), hasSize(1));
List results = vectorStore.similaritySearch(searchRequest.withTopK(5));
assertThat(results).hasSize(2);
@@ -168,9 +165,7 @@ public void addAndSearchWithFilters() {
// Remove all documents from the store
vectorStore.delete(List.of(bgDocument, nlDocument).stream().map(doc -> doc.getId()).toList());
- Awaitility.await().until(() -> {
- return vectorStore.similaritySearch(searchRequest.withTopK(1));
- }, hasSize(0));
+ Awaitility.await().until(() -> vectorStore.similaritySearch(searchRequest.withTopK(1)), hasSize(0));
});
}
@@ -189,9 +184,7 @@ public void documentUpdateTest() {
SearchRequest springSearchRequest = SearchRequest.query("Spring").withTopK(5);
- Awaitility.await().until(() -> {
- return vectorStore.similaritySearch(springSearchRequest);
- }, hasSize(1));
+ Awaitility.await().until(() -> vectorStore.similaritySearch(springSearchRequest), hasSize(1));
List results = vectorStore.similaritySearch(springSearchRequest);
@@ -210,9 +203,9 @@ public void documentUpdateTest() {
SearchRequest fooBarSearchRequest = SearchRequest.query("FooBar").withTopK(5);
- Awaitility.await().until(() -> {
- return vectorStore.similaritySearch(fooBarSearchRequest).get(0).getContent();
- }, equalTo("The World is Big and Salvation Lurks Around the Corner"));
+ Awaitility.await()
+ .until(() -> vectorStore.similaritySearch(fooBarSearchRequest).get(0).getContent(),
+ equalTo("The World is Big and Salvation Lurks Around the Corner"));
results = vectorStore.similaritySearch(fooBarSearchRequest);
@@ -225,9 +218,7 @@ public void documentUpdateTest() {
// Remove all documents from the store
vectorStore.delete(List.of(document.getId()));
- Awaitility.await().until(() -> {
- return vectorStore.similaritySearch(fooBarSearchRequest);
- }, hasSize(0));
+ Awaitility.await().until(() -> vectorStore.similaritySearch(fooBarSearchRequest), hasSize(0));
});
}
@@ -241,10 +232,10 @@ public void searchThresholdTest() {
vectorStore.add(this.documents);
- Awaitility.await().until(() -> {
- return vectorStore
- .similaritySearch(SearchRequest.query("Depression").withTopK(50).withSimilarityThresholdAll());
- }, hasSize(3));
+ Awaitility.await()
+ .until(() -> vectorStore
+ .similaritySearch(SearchRequest.query("Depression").withTopK(50).withSimilarityThresholdAll()),
+ hasSize(3));
List fullResult = vectorStore
.similaritySearch(SearchRequest.query("Depression").withTopK(5).withSimilarityThresholdAll());
@@ -267,9 +258,8 @@ public void searchThresholdTest() {
// Remove all documents from the store
vectorStore.delete(this.documents.stream().map(doc -> doc.getId()).toList());
- Awaitility.await().until(() -> {
- return vectorStore.similaritySearch(SearchRequest.query("Hello").withTopK(1));
- }, hasSize(0));
+ Awaitility.await()
+ .until(() -> vectorStore.similaritySearch(SearchRequest.query("Hello").withTopK(1)), hasSize(0));
});
}
diff --git a/vector-stores/spring-ai-pinecone-store/src/test/java/org/springframework/ai/vectorstore/PineconeVectorStoreObservationIT.java b/vector-stores/spring-ai-pinecone-store/src/test/java/org/springframework/ai/vectorstore/PineconeVectorStoreObservationIT.java
index b8a84de02c4..53ced5aa0b1 100644
--- a/vector-stores/spring-ai-pinecone-store/src/test/java/org/springframework/ai/vectorstore/PineconeVectorStoreObservationIT.java
+++ b/vector-stores/spring-ai-pinecone-store/src/test/java/org/springframework/ai/vectorstore/PineconeVectorStoreObservationIT.java
@@ -128,9 +128,9 @@ void observationVectorStoreAddAndQueryOperations() {
.hasBeenStarted()
.hasBeenStopped();
- Awaitility.await().until(() -> {
- return vectorStore.similaritySearch(SearchRequest.query("What is Great Depression").withTopK(1));
- }, hasSize(1));
+ Awaitility.await()
+ .until(() -> vectorStore.similaritySearch(SearchRequest.query("What is Great Depression").withTopK(1)),
+ hasSize(1));
observationRegistry.clear();
@@ -168,9 +168,8 @@ void observationVectorStoreAddAndQueryOperations() {
// Remove all documents from the store
vectorStore.delete(this.documents.stream().map(doc -> doc.getId()).toList());
- Awaitility.await().until(() -> {
- return vectorStore.similaritySearch(SearchRequest.query("Hello").withTopK(1));
- }, hasSize(0));
+ Awaitility.await()
+ .until(() -> vectorStore.similaritySearch(SearchRequest.query("Hello").withTopK(1)), hasSize(0));
});
}
diff --git a/vector-stores/spring-ai-qdrant-store/pom.xml b/vector-stores/spring-ai-qdrant-store/pom.xml
index 2d9c598e529..d2938dcb53d 100644
--- a/vector-stores/spring-ai-qdrant-store/pom.xml
+++ b/vector-stores/spring-ai-qdrant-store/pom.xml
@@ -39,6 +39,7 @@
17
17
+ false
diff --git a/vector-stores/spring-ai-qdrant-store/src/main/java/org/springframework/ai/vectorstore/qdrant/QdrantFilterExpressionConverter.java b/vector-stores/spring-ai-qdrant-store/src/main/java/org/springframework/ai/vectorstore/qdrant/QdrantFilterExpressionConverter.java
index 1870a37aabe..944b67ede7d 100644
--- a/vector-stores/spring-ai-qdrant-store/src/main/java/org/springframework/ai/vectorstore/qdrant/QdrantFilterExpressionConverter.java
+++ b/vector-stores/spring-ai-qdrant-store/src/main/java/org/springframework/ai/vectorstore/qdrant/QdrantFilterExpressionConverter.java
@@ -30,15 +30,6 @@
import org.springframework.ai.vectorstore.filter.Filter.Operand;
import org.springframework.ai.vectorstore.filter.Filter.Value;
-import static io.qdrant.client.ConditionFactory.filter;
-import static io.qdrant.client.ConditionFactory.match;
-import static io.qdrant.client.ConditionFactory.matchExceptKeywords;
-import static io.qdrant.client.ConditionFactory.matchExceptValues;
-import static io.qdrant.client.ConditionFactory.matchKeyword;
-import static io.qdrant.client.ConditionFactory.matchKeywords;
-import static io.qdrant.client.ConditionFactory.matchValues;
-import static io.qdrant.client.ConditionFactory.range;
-
/**
* @author Anush Shetty
* @since 0.8.1
@@ -57,15 +48,15 @@ protected Filter convertOperand(Operand operand) {
if (operand instanceof Expression expression) {
if (expression.type() == ExpressionType.NOT && expression.left() instanceof Group group) {
- mustNotClauses.add(filter(convertOperand(group.content())));
+ mustNotClauses.add(io.qdrant.client.ConditionFactory.filter(convertOperand(group.content())));
}
else if (expression.type() == ExpressionType.AND) {
- mustClauses.add(filter(convertOperand(expression.left())));
- mustClauses.add(filter(convertOperand(expression.right())));
+ mustClauses.add(io.qdrant.client.ConditionFactory.filter(convertOperand(expression.left())));
+ mustClauses.add(io.qdrant.client.ConditionFactory.filter(convertOperand(expression.right())));
}
else if (expression.type() == ExpressionType.OR) {
- shouldClauses.add(filter(convertOperand(expression.left())));
- shouldClauses.add(filter(convertOperand(expression.right())));
+ shouldClauses.add(io.qdrant.client.ConditionFactory.filter(convertOperand(expression.left())));
+ shouldClauses.add(io.qdrant.client.ConditionFactory.filter(convertOperand(expression.right())));
}
else {
if (!(expression.right() instanceof Value)) {
@@ -83,44 +74,35 @@ protected Condition parseComparison(Key key, Value value, Expression exp) {
ExpressionType type = exp.type();
switch (type) {
- case EQ: {
+ case EQ:
return buildEqCondition(key, value);
- }
- case NE: {
+ case NE:
return buildNeCondition(key, value);
- }
- case GT: {
+ case GT:
return buildGtCondition(key, value);
- }
- case GTE: {
+ case GTE:
return buildGteCondition(key, value);
- }
- case LT: {
+ case LT:
return buildLtCondition(key, value);
- }
- case LTE: {
+ case LTE:
return buildLteCondition(key, value);
- }
- case IN: {
+ case IN:
return buildInCondition(key, value);
- }
- case NIN: {
+ case NIN:
return buildNInCondition(key, value);
- }
- default: {
+ default:
throw new RuntimeException("Unsupported expression type: " + type);
- }
}
}
protected Condition buildEqCondition(Key key, Value value) {
String identifier = doKey(key);
if (value.value() instanceof String valueStr) {
- return matchKeyword(identifier, valueStr);
+ return io.qdrant.client.ConditionFactory.matchKeyword(identifier, valueStr);
}
else if (value.value() instanceof Number valueNum) {
long lValue = Long.parseLong(valueNum.toString());
- return match(identifier, lValue);
+ return io.qdrant.client.ConditionFactory.match(identifier, lValue);
}
throw new IllegalArgumentException("Invalid value type for EQ. Can either be a string or Number");
@@ -130,12 +112,14 @@ else if (value.value() instanceof Number valueNum) {
protected Condition buildNeCondition(Key key, Value value) {
String identifier = doKey(key);
if (value.value() instanceof String valueStr) {
- return filter(Filter.newBuilder().addMustNot(matchKeyword(identifier, valueStr)).build());
+ return io.qdrant.client.ConditionFactory.filter(Filter.newBuilder()
+ .addMustNot(io.qdrant.client.ConditionFactory.matchKeyword(identifier, valueStr))
+ .build());
}
else if (value.value() instanceof Number valueNum) {
long lValue = Long.parseLong(valueNum.toString());
- Condition condition = match(identifier, lValue);
- return filter(Filter.newBuilder().addMustNot(condition).build());
+ Condition condition = io.qdrant.client.ConditionFactory.match(identifier, lValue);
+ return io.qdrant.client.ConditionFactory.filter(Filter.newBuilder().addMustNot(condition).build());
}
throw new IllegalArgumentException("Invalid value type for NEQ. Can either be a string or Number");
@@ -146,7 +130,7 @@ protected Condition buildGtCondition(Key key, Value value) {
String identifier = doKey(key);
if (value.value() instanceof Number valueNum) {
Double dvalue = Double.parseDouble(valueNum.toString());
- return range(identifier, Range.newBuilder().setGt(dvalue).build());
+ return io.qdrant.client.ConditionFactory.range(identifier, Range.newBuilder().setGt(dvalue).build());
}
throw new RuntimeException("Unsupported value type for GT condition. Only supports Number");
@@ -156,7 +140,7 @@ protected Condition buildLtCondition(Key key, Value value) {
String identifier = doKey(key);
if (value.value() instanceof Number valueNum) {
Double dvalue = Double.parseDouble(valueNum.toString());
- return range(identifier, Range.newBuilder().setLt(dvalue).build());
+ return io.qdrant.client.ConditionFactory.range(identifier, Range.newBuilder().setLt(dvalue).build());
}
throw new RuntimeException("Unsupported value type for LT condition. Only supports Number");
@@ -166,7 +150,7 @@ protected Condition buildGteCondition(Key key, Value value) {
String identifier = doKey(key);
if (value.value() instanceof Number valueNum) {
Double dvalue = Double.parseDouble(valueNum.toString());
- return range(identifier, Range.newBuilder().setGte(dvalue).build());
+ return io.qdrant.client.ConditionFactory.range(identifier, Range.newBuilder().setGte(dvalue).build());
}
throw new RuntimeException("Unsupported value type for GTE condition. Only supports Number");
@@ -176,7 +160,7 @@ protected Condition buildLteCondition(Key key, Value value) {
String identifier = doKey(key);
if (value.value() instanceof Number valueNum) {
Double dvalue = Double.parseDouble(valueNum.toString());
- return range(identifier, Range.newBuilder().setLte(dvalue).build());
+ return io.qdrant.client.ConditionFactory.range(identifier, Range.newBuilder().setLte(dvalue).build());
}
throw new RuntimeException("Unsupported value type for LTE condition. Only supports Number");
@@ -193,7 +177,7 @@ protected Condition buildInCondition(Key key, Value value) {
for (Object valueObj : valueList) {
stringValues.add(valueObj.toString());
}
- return matchKeywords(identifier, stringValues);
+ return io.qdrant.client.ConditionFactory.matchKeywords(identifier, stringValues);
}
else if (firstValue instanceof Number) {
// If the first value is a number, then all values should be numbers
@@ -202,7 +186,7 @@ else if (firstValue instanceof Number) {
Long longValue = Long.parseLong(valueObj.toString());
longValues.add(longValue);
}
- return matchValues(identifier, longValues);
+ return io.qdrant.client.ConditionFactory.matchValues(identifier, longValues);
}
else {
throw new RuntimeException("Unsupported value in IN value list. Only supports String or Number");
@@ -224,7 +208,7 @@ protected Condition buildNInCondition(Key key, Value value) {
for (Object valueObj : valueList) {
stringValues.add(valueObj.toString());
}
- return matchExceptKeywords(identifier, stringValues);
+ return io.qdrant.client.ConditionFactory.matchExceptKeywords(identifier, stringValues);
}
else if (firstValue instanceof Number) {
// If the first value is a number, then all values should be numbers
@@ -233,7 +217,7 @@ else if (firstValue instanceof Number) {
Long longValue = Long.parseLong(valueObj.toString());
longValues.add(longValue);
}
- return matchExceptValues(identifier, longValues);
+ return io.qdrant.client.ConditionFactory.matchExceptValues(identifier, longValues);
}
else {
throw new RuntimeException("Unsupported value in NIN value list. Only supports String or Number");
diff --git a/vector-stores/spring-ai-qdrant-store/src/main/java/org/springframework/ai/vectorstore/qdrant/QdrantObjectFactory.java b/vector-stores/spring-ai-qdrant-store/src/main/java/org/springframework/ai/vectorstore/qdrant/QdrantObjectFactory.java
index 00ad1e518cc..08220a53c19 100644
--- a/vector-stores/spring-ai-qdrant-store/src/main/java/org/springframework/ai/vectorstore/qdrant/QdrantObjectFactory.java
+++ b/vector-stores/spring-ai-qdrant-store/src/main/java/org/springframework/ai/vectorstore/qdrant/QdrantObjectFactory.java
@@ -32,7 +32,7 @@
* @author Anush Shetty
* @since 0.8.1
*/
-class QdrantObjectFactory {
+final class QdrantObjectFactory {
private static final Log logger = LogFactory.getLog(QdrantObjectFactory.class);
diff --git a/vector-stores/spring-ai-qdrant-store/src/main/java/org/springframework/ai/vectorstore/qdrant/QdrantValueFactory.java b/vector-stores/spring-ai-qdrant-store/src/main/java/org/springframework/ai/vectorstore/qdrant/QdrantValueFactory.java
index 13862abc068..336384ae66b 100644
--- a/vector-stores/spring-ai-qdrant-store/src/main/java/org/springframework/ai/vectorstore/qdrant/QdrantValueFactory.java
+++ b/vector-stores/spring-ai-qdrant-store/src/main/java/org/springframework/ai/vectorstore/qdrant/QdrantValueFactory.java
@@ -34,7 +34,7 @@
* @author Anush Shetty
* @since 0.8.1
*/
-class QdrantValueFactory {
+final class QdrantValueFactory {
private QdrantValueFactory() {
}
@@ -98,4 +98,4 @@ private static Value value(Map inputMap) {
return Value.newBuilder().setStructValue(structBuilder).build();
}
-}
\ No newline at end of file
+}
diff --git a/vector-stores/spring-ai-qdrant-store/src/main/java/org/springframework/ai/vectorstore/qdrant/QdrantVectorStore.java b/vector-stores/spring-ai-qdrant-store/src/main/java/org/springframework/ai/vectorstore/qdrant/QdrantVectorStore.java
index 8fadc237ac6..679707038ac 100644
--- a/vector-stores/spring-ai-qdrant-store/src/main/java/org/springframework/ai/vectorstore/qdrant/QdrantVectorStore.java
+++ b/vector-stores/spring-ai-qdrant-store/src/main/java/org/springframework/ai/vectorstore/qdrant/QdrantVectorStore.java
@@ -48,11 +48,6 @@
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
-import static io.qdrant.client.PointIdFactory.id;
-import static io.qdrant.client.ValueFactory.value;
-import static io.qdrant.client.VectorsFactory.vectors;
-import static io.qdrant.client.WithPayloadSelectorFactory.enable;
-
/**
* Qdrant vectorStore implementation. This store supports creating, updating, deleting,
* and similarity searching of documents in a Qdrant collection.
@@ -148,8 +143,8 @@ public void doAdd(List documents) {
List points = documents.stream()
.map(document -> PointStruct.newBuilder()
- .setId(id(UUID.fromString(document.getId())))
- .setVectors(vectors(document.getEmbedding()))
+ .setId(io.qdrant.client.PointIdFactory.id(UUID.fromString(document.getId())))
+ .setVectors(io.qdrant.client.VectorsFactory.vectors(document.getEmbedding()))
.putAllPayload(toPayload(document))
.build())
.toList();
@@ -169,7 +164,9 @@ public void doAdd(List documents) {
@Override
public Optional doDelete(List documentIds) {
try {
- List ids = documentIds.stream().map(id -> id(UUID.fromString(id))).toList();
+ List ids = documentIds.stream()
+ .map(id -> io.qdrant.client.PointIdFactory.id(UUID.fromString(id)))
+ .toList();
var result = this.qdrantClient.deleteAsync(this.collectionName, ids)
.get()
.getStatus() == UpdateStatus.Completed;
@@ -198,7 +195,7 @@ public List doSimilaritySearch(SearchRequest request) {
var searchPoints = SearchPoints.newBuilder()
.setCollectionName(this.collectionName)
.setLimit(request.getTopK())
- .setWithPayload(enable(true))
+ .setWithPayload(io.qdrant.client.WithPayloadSelectorFactory.enable(true))
.addAllVector(EmbeddingUtils.toList(queryEmbedding))
.setFilter(filter)
.setScoreThreshold((float) request.getSimilarityThreshold())
@@ -206,9 +203,7 @@ public List doSimilaritySearch(SearchRequest request) {
var queryResponse = this.qdrantClient.searchAsync(searchPoints).get();
- return queryResponse.stream().map(scoredPoint -> {
- return toDocument(scoredPoint);
- }).toList();
+ return queryResponse.stream().map(this::toDocument).toList();
}
catch (InterruptedException | ExecutionException | IllegalArgumentException e) {
@@ -245,7 +240,7 @@ private Document toDocument(ScoredPoint point) {
private Map toPayload(Document document) {
try {
var payload = QdrantValueFactory.toValueMap(document.getMetadata());
- payload.put(CONTENT_FIELD_NAME, value(document.getContent()));
+ payload.put(CONTENT_FIELD_NAME, io.qdrant.client.ValueFactory.value(document.getContent()));
return payload;
}
catch (Exception e) {
@@ -323,7 +318,7 @@ public static QdrantVectorStoreConfig defaultConfig() {
return builder().build();
}
- public static class Builder {
+ public final static class Builder {
private String collectionName;
diff --git a/vector-stores/spring-ai-qdrant-store/src/test/java/org/springframework/ai/vectorstore/qdrant/QdrantImage.java b/vector-stores/spring-ai-qdrant-store/src/test/java/org/springframework/ai/vectorstore/qdrant/QdrantImage.java
index 2045be309f5..a50241bc843 100644
--- a/vector-stores/spring-ai-qdrant-store/src/test/java/org/springframework/ai/vectorstore/qdrant/QdrantImage.java
+++ b/vector-stores/spring-ai-qdrant-store/src/test/java/org/springframework/ai/vectorstore/qdrant/QdrantImage.java
@@ -21,8 +21,12 @@
/**
* @author Thomas Vitale
*/
-public class QdrantImage {
+public final class QdrantImage {
public static final DockerImageName DEFAULT_IMAGE = DockerImageName.parse("qdrant/qdrant:v1.9.7");
+ private QdrantImage() {
+
+ }
+
}
diff --git a/vector-stores/spring-ai-redis-store/pom.xml b/vector-stores/spring-ai-redis-store/pom.xml
index cf0c0e4d2ed..394f00aac60 100644
--- a/vector-stores/spring-ai-redis-store/pom.xml
+++ b/vector-stores/spring-ai-redis-store/pom.xml
@@ -41,6 +41,7 @@
5.1.0
17
17
+ false