From 9844a18983dc2db667fb84ff4f9a75dcbcc3fb3b Mon Sep 17 00:00:00 2001 From: Soby Chacko Date: Wed, 8 Jan 2025 11:51:42 -0500 Subject: [PATCH] Move batching strategy to base vector store builder Moving BatchingStrategy configuration from individual vector store implementations to the base AbstractVectorStoreBuilder to reduce code duplication and provide consistent batching behavior across all vector stores. The default TokenCountBatchingStrategy is now set in the base builder class. --- .../AbstractVectorStoreBuilder.java | 19 +++++++++++++++++++ .../ai/vectorstore/VectorStore.java | 8 ++++++++ .../AbstractObservationVectorStore.java | 9 +++++++-- .../cosmosdb/CosmosDBVectorStore.java | 6 ------ .../vectorstore/azure/AzureVectorStore.java | 18 ------------------ .../cassandra/CassandraVectorStore.java | 17 ----------------- .../chroma/vectorstore/ChromaVectorStore.java | 17 ----------------- .../ElasticsearchVectorStore.java | 17 ----------------- .../gemfire/GemFireVectorStore.java | 17 ----------------- .../mariadb/MariaDBVectorStore.java | 17 ----------------- .../vectorstore/milvus/MilvusVectorStore.java | 17 ----------------- .../atlas/MongoDBAtlasVectorStore.java | 17 ----------------- .../vectorstore/neo4j/Neo4jVectorStore.java | 17 ----------------- .../opensearch/OpenSearchVectorStore.java | 17 ----------------- .../vectorstore/oracle/OracleVectorStore.java | 17 ----------------- .../vectorstore/pgvector/PgVectorStore.java | 10 ---------- .../pinecone/PineconeVectorStore.java | 17 ----------------- .../vectorstore/qdrant/QdrantVectorStore.java | 17 ----------------- .../vectorstore/redis/RedisVectorStore.java | 17 ----------------- .../typesense/TypesenseVectorStore.java | 17 ----------------- .../TypesenseVectorStoreBuilderTests.java | 2 +- .../weaviate/WeaviateVectorStore.java | 17 ----------------- 22 files changed, 35 insertions(+), 292 deletions(-) diff --git a/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/AbstractVectorStoreBuilder.java b/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/AbstractVectorStoreBuilder.java index 8ee7f88b5..64ffa2043 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/AbstractVectorStoreBuilder.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/AbstractVectorStoreBuilder.java @@ -18,7 +18,9 @@ package org.springframework.ai.vectorstore; import io.micrometer.observation.ObservationRegistry; +import org.springframework.ai.embedding.BatchingStrategy; import org.springframework.ai.embedding.EmbeddingModel; +import org.springframework.ai.embedding.TokenCountBatchingStrategy; import org.springframework.ai.vectorstore.observation.VectorStoreObservationConvention; import org.springframework.lang.Nullable; import org.springframework.util.Assert; @@ -40,6 +42,8 @@ public abstract class AbstractVectorStoreBuilder builder) { - this(builder.getEmbeddingModel(), builder.getObservationRegistry(), builder.getCustomObservationConvention()); + this(builder.getEmbeddingModel(), builder.getObservationRegistry(), builder.getCustomObservationConvention(), + builder.getBatchingStrategy()); } /** diff --git a/vector-stores/spring-ai-azure-cosmos-db-store/src/main/java/org/springframework/ai/vectorstore/cosmosdb/CosmosDBVectorStore.java b/vector-stores/spring-ai-azure-cosmos-db-store/src/main/java/org/springframework/ai/vectorstore/cosmosdb/CosmosDBVectorStore.java index 85658a2b9..6ea4dc1db 100644 --- a/vector-stores/spring-ai-azure-cosmos-db-store/src/main/java/org/springframework/ai/vectorstore/cosmosdb/CosmosDBVectorStore.java +++ b/vector-stores/spring-ai-azure-cosmos-db-store/src/main/java/org/springframework/ai/vectorstore/cosmosdb/CosmosDBVectorStore.java @@ -60,7 +60,6 @@ import org.springframework.ai.document.Document; import org.springframework.ai.embedding.BatchingStrategy; import org.springframework.ai.embedding.EmbeddingModel; import org.springframework.ai.embedding.EmbeddingOptionsBuilder; -import org.springframework.ai.embedding.TokenCountBatchingStrategy; import org.springframework.ai.observation.conventions.VectorStoreProvider; import org.springframework.ai.vectorstore.AbstractVectorStoreBuilder; import org.springframework.ai.vectorstore.SearchRequest; @@ -96,8 +95,6 @@ public class CosmosDBVectorStore extends AbstractObservationVectorStore implemen private final List metadataFieldsList; - private final BatchingStrategy batchingStrategy; - private CosmosAsyncContainer container; /** @@ -120,7 +117,6 @@ public class CosmosDBVectorStore extends AbstractObservationVectorStore implemen this.vectorStoreThroughput = builder.vectorStoreThroughput; this.vectorDimensions = builder.vectorDimensions; this.metadataFieldsList = builder.metadataFieldsList; - this.batchingStrategy = builder.batchingStrategy; this.cosmosClient.createDatabaseIfNotExists(this.databaseName).block(); initializeContainer(this.containerName, this.databaseName, this.vectorStoreThroughput, this.vectorDimensions, @@ -404,8 +400,6 @@ public class CosmosDBVectorStore extends AbstractObservationVectorStore implemen private List metadataFieldsList = new ArrayList<>(); - private BatchingStrategy batchingStrategy = new TokenCountBatchingStrategy(); - private Builder(CosmosAsyncClient cosmosClient, EmbeddingModel embeddingModel) { super(embeddingModel); Assert.notNull(cosmosClient, "CosmosClient must not be null"); diff --git a/vector-stores/spring-ai-azure-store/src/main/java/org/springframework/ai/vectorstore/azure/AzureVectorStore.java b/vector-stores/spring-ai-azure-store/src/main/java/org/springframework/ai/vectorstore/azure/AzureVectorStore.java index 3b9418dda..f983b79b9 100644 --- a/vector-stores/spring-ai-azure-store/src/main/java/org/springframework/ai/vectorstore/azure/AzureVectorStore.java +++ b/vector-stores/spring-ai-azure-store/src/main/java/org/springframework/ai/vectorstore/azure/AzureVectorStore.java @@ -47,10 +47,8 @@ import org.slf4j.LoggerFactory; import org.springframework.ai.document.Document; import org.springframework.ai.document.DocumentMetadata; -import org.springframework.ai.embedding.BatchingStrategy; import org.springframework.ai.embedding.EmbeddingModel; import org.springframework.ai.embedding.EmbeddingOptionsBuilder; -import org.springframework.ai.embedding.TokenCountBatchingStrategy; import org.springframework.ai.model.EmbeddingUtils; import org.springframework.ai.observation.conventions.VectorStoreProvider; import org.springframework.ai.observation.conventions.VectorStoreSimilarityMetric; @@ -108,8 +106,6 @@ public class AzureVectorStore extends AbstractObservationVectorStore implements private final boolean initializeSchema; - private final BatchingStrategy batchingStrategy; - /** * List of metadata fields (as field name and type) that can be used in similarity * search query filter expressions. The {@link Document#getMetadata()} can contain @@ -144,7 +140,6 @@ public class AzureVectorStore extends AbstractObservationVectorStore implements this.searchIndexClient = builder.searchIndexClient; this.initializeSchema = builder.initializeSchema; this.filterMetadataFields = builder.filterMetadataFields; - this.batchingStrategy = builder.batchingStrategy; this.defaultTopK = builder.defaultTopK; this.defaultSimilarityThreshold = builder.defaultSimilarityThreshold; this.indexName = builder.indexName; @@ -387,8 +382,6 @@ public class AzureVectorStore extends AbstractObservationVectorStore implements private List filterMetadataFields = List.of(); - private BatchingStrategy batchingStrategy = new TokenCountBatchingStrategy(); - private int defaultTopK = DEFAULT_TOP_K; private Double defaultSimilarityThreshold = DEFAULT_SIMILARITY_THRESHOLD; @@ -421,17 +414,6 @@ public class AzureVectorStore extends AbstractObservationVectorStore implements return this; } - /** - * Sets the batching strategy. - * @param batchingStrategy the strategy to use - * @return the builder instance - */ - public Builder batchingStrategy(BatchingStrategy batchingStrategy) { - Assert.notNull(batchingStrategy, "BatchingStrategy must not be null"); - this.batchingStrategy = batchingStrategy; - return this; - } - /** * Sets the index name for the Azure Vector Store. * @param indexName the name of the index to use diff --git a/vector-stores/spring-ai-cassandra-store/src/main/java/org/springframework/ai/vectorstore/cassandra/CassandraVectorStore.java b/vector-stores/spring-ai-cassandra-store/src/main/java/org/springframework/ai/vectorstore/cassandra/CassandraVectorStore.java index 72fe06008..d5ecc6f6c 100644 --- a/vector-stores/spring-ai-cassandra-store/src/main/java/org/springframework/ai/vectorstore/cassandra/CassandraVectorStore.java +++ b/vector-stores/spring-ai-cassandra-store/src/main/java/org/springframework/ai/vectorstore/cassandra/CassandraVectorStore.java @@ -215,8 +215,6 @@ public class CassandraVectorStore extends AbstractObservationVectorStore impleme private final boolean closeSessionOnClose; - private final BatchingStrategy batchingStrategy; - private final ConcurrentMap, PreparedStatement> addStmts = new ConcurrentHashMap<>(); private final PreparedStatement deleteStmt; @@ -237,7 +235,6 @@ public class CassandraVectorStore extends AbstractObservationVectorStore impleme this.primaryKeyTranslator = builder.primaryKeyTranslator; this.executor = Executors.newFixedThreadPool(builder.fixedThreadPoolExecutorSize); this.closeSessionOnClose = builder.closeSessionOnClose; - this.batchingStrategy = builder.batchingStrategy; ensureSchemaExists(embeddingModel.dimensions()); prepareAddStatement(Set.of()); @@ -775,8 +772,6 @@ public class CassandraVectorStore extends AbstractObservationVectorStore impleme private int fixedThreadPoolExecutorSize = DEFAULT_ADD_CONCURRENCY; - private BatchingStrategy batchingStrategy = new TokenCountBatchingStrategy(); - private FilterExpressionConverter filterExpressionConverter; private DocumentIdTranslator documentIdTranslator = (String id) -> List.of(id); @@ -915,18 +910,6 @@ public class CassandraVectorStore extends AbstractObservationVectorStore impleme return this; } - /** - * Sets the batching strategy. - * @param batchingStrategy the batching strategy to use - * @return the builder instance - * @throws IllegalArgumentException if batchingStrategy is null - */ - public Builder batchingStrategy(BatchingStrategy batchingStrategy) { - Assert.notNull(batchingStrategy, "BatchingStrategy must not be null"); - this.batchingStrategy = batchingStrategy; - return this; - } - /** * Sets the filter expression converter. * @param converter the filter expression converter to use diff --git a/vector-stores/spring-ai-chroma-store/src/main/java/org/springframework/ai/chroma/vectorstore/ChromaVectorStore.java b/vector-stores/spring-ai-chroma-store/src/main/java/org/springframework/ai/chroma/vectorstore/ChromaVectorStore.java index fe8f34345..14deaf40d 100644 --- a/vector-stores/spring-ai-chroma-store/src/main/java/org/springframework/ai/chroma/vectorstore/ChromaVectorStore.java +++ b/vector-stores/spring-ai-chroma-store/src/main/java/org/springframework/ai/chroma/vectorstore/ChromaVectorStore.java @@ -77,8 +77,6 @@ public class ChromaVectorStore extends AbstractObservationVectorStore implements private final boolean initializeSchema; - private final BatchingStrategy batchingStrategy; - private final ObjectMapper objectMapper; private boolean initialized = false; @@ -93,7 +91,6 @@ public class ChromaVectorStore extends AbstractObservationVectorStore implements this.collectionName = builder.collectionName; this.initializeSchema = builder.initializeSchema; this.filterExpressionConverter = builder.filterExpressionConverter; - this.batchingStrategy = builder.batchingStrategy; this.objectMapper = JsonMapper.builder().addModules(JacksonUtils.instantiateAvailableModules()).build(); if (builder.initializeImmediately) { @@ -230,8 +227,6 @@ public class ChromaVectorStore extends AbstractObservationVectorStore implements private boolean initializeSchema = false; - private BatchingStrategy batchingStrategy = new TokenCountBatchingStrategy(); - private FilterExpressionConverter filterExpressionConverter = new ChromaFilterExpressionConverter(); private boolean initializeImmediately = false; @@ -264,18 +259,6 @@ public class ChromaVectorStore extends AbstractObservationVectorStore implements return this; } - /** - * Sets the batching strategy. - * @param batchingStrategy the batching strategy to use - * @return the builder instance - * @throws IllegalArgumentException if batchingStrategy is null - */ - public Builder batchingStrategy(BatchingStrategy batchingStrategy) { - Assert.notNull(batchingStrategy, "batchingStrategy must not be null"); - this.batchingStrategy = batchingStrategy; - return this; - } - /** * Sets the filter expression converter. * @param converter the filter expression converter to use diff --git a/vector-stores/spring-ai-elasticsearch-store/src/main/java/org/springframework/ai/vectorstore/elasticsearch/ElasticsearchVectorStore.java b/vector-stores/spring-ai-elasticsearch-store/src/main/java/org/springframework/ai/vectorstore/elasticsearch/ElasticsearchVectorStore.java index 8c06f8285..445a7a2e1 100644 --- a/vector-stores/spring-ai-elasticsearch-store/src/main/java/org/springframework/ai/vectorstore/elasticsearch/ElasticsearchVectorStore.java +++ b/vector-stores/spring-ai-elasticsearch-store/src/main/java/org/springframework/ai/vectorstore/elasticsearch/ElasticsearchVectorStore.java @@ -162,8 +162,6 @@ public class ElasticsearchVectorStore extends AbstractObservationVectorStore imp private final boolean initializeSchema; - private final BatchingStrategy batchingStrategy; - protected ElasticsearchVectorStore(Builder builder) { super(builder); @@ -172,7 +170,6 @@ public class ElasticsearchVectorStore extends AbstractObservationVectorStore imp this.initializeSchema = builder.initializeSchema; this.options = builder.options; this.filterExpressionConverter = builder.filterExpressionConverter; - this.batchingStrategy = builder.batchingStrategy; String version = Version.VERSION == null ? "Unknown" : Version.VERSION.toString(); this.elasticsearchClient = new ElasticsearchClient(new RestClientTransport(builder.restClient, @@ -369,8 +366,6 @@ public class ElasticsearchVectorStore extends AbstractObservationVectorStore imp private boolean initializeSchema = false; - private BatchingStrategy batchingStrategy = new TokenCountBatchingStrategy(); - private FilterExpressionConverter filterExpressionConverter = new ElasticsearchAiSearchFilterExpressionConverter(); /** @@ -406,18 +401,6 @@ public class ElasticsearchVectorStore extends AbstractObservationVectorStore imp return this; } - /** - * Sets the batching strategy for vector operations. - * @param batchingStrategy the batching strategy to use - * @return the builder instance - * @throws IllegalArgumentException if batchingStrategy is null - */ - public Builder batchingStrategy(BatchingStrategy batchingStrategy) { - Assert.notNull(batchingStrategy, "batchingStrategy must not be null"); - this.batchingStrategy = batchingStrategy; - return this; - } - /** * Sets the filter expression converter. * @param converter the filter expression converter to use diff --git a/vector-stores/spring-ai-gemfire-store/src/main/java/org/springframework/ai/vectorstore/gemfire/GemFireVectorStore.java b/vector-stores/spring-ai-gemfire-store/src/main/java/org/springframework/ai/vectorstore/gemfire/GemFireVectorStore.java index 239bb882d..93e504a85 100644 --- a/vector-stores/spring-ai-gemfire-store/src/main/java/org/springframework/ai/vectorstore/gemfire/GemFireVectorStore.java +++ b/vector-stores/spring-ai-gemfire-store/src/main/java/org/springframework/ai/vectorstore/gemfire/GemFireVectorStore.java @@ -103,8 +103,6 @@ public class GemFireVectorStore extends AbstractObservationVectorStore implement private final boolean initializeSchema; - private final BatchingStrategy batchingStrategy; - private final ObjectMapper objectMapper; private final String indexName; @@ -134,7 +132,6 @@ public class GemFireVectorStore extends AbstractObservationVectorStore implement this.buckets = builder.buckets; this.vectorSimilarityFunction = builder.vectorSimilarityFunction; this.fields = builder.fields; - this.batchingStrategy = builder.batchingStrategy; String base = UriComponentsBuilder.fromUriString(DEFAULT_URI) .build(builder.sslEnabled ? "s" : "", builder.host, builder.port) @@ -584,8 +581,6 @@ public class GemFireVectorStore extends AbstractObservationVectorStore implement private boolean initializeSchema = false; - private BatchingStrategy batchingStrategy = new TokenCountBatchingStrategy(); - private Builder(EmbeddingModel embeddingModel) { super(embeddingModel); } @@ -708,18 +703,6 @@ public class GemFireVectorStore extends AbstractObservationVectorStore implement return this; } - /** - * Sets the batching strategy. - * @param batchingStrategy the strategy to use - * @return the builder instance - * @throws IllegalArgumentException if batchingStrategy is null - */ - public Builder batchingStrategy(BatchingStrategy batchingStrategy) { - Assert.notNull(batchingStrategy, "BatchingStrategy must not be null"); - this.batchingStrategy = batchingStrategy; - return this; - } - @Override public GemFireVectorStore build() { return new GemFireVectorStore(this); diff --git a/vector-stores/spring-ai-mariadb-store/src/main/java/org/springframework/ai/vectorstore/mariadb/MariaDBVectorStore.java b/vector-stores/spring-ai-mariadb-store/src/main/java/org/springframework/ai/vectorstore/mariadb/MariaDBVectorStore.java index 33067a0c1..e58be3508 100644 --- a/vector-stores/spring-ai-mariadb-store/src/main/java/org/springframework/ai/vectorstore/mariadb/MariaDBVectorStore.java +++ b/vector-stores/spring-ai-mariadb-store/src/main/java/org/springframework/ai/vectorstore/mariadb/MariaDBVectorStore.java @@ -193,8 +193,6 @@ public class MariaDBVectorStore extends AbstractObservationVectorStore implement private final MariaDBSchemaValidator schemaValidator; - private final BatchingStrategy batchingStrategy; - private final int maxDocumentBatchSize; /** @@ -227,7 +225,6 @@ public class MariaDBVectorStore extends AbstractObservationVectorStore implement this.removeExistingVectorStoreTable = builder.removeExistingVectorStoreTable; this.initializeSchema = builder.initializeSchema; this.schemaValidator = new MariaDBSchemaValidator(this.jdbcTemplate); - this.batchingStrategy = builder.batchingStrategy; this.maxDocumentBatchSize = builder.maxDocumentBatchSize; this.contentFieldName = MariaDBSchemaValidator.validateAndEnquoteIdentifier(builder.contentFieldName, false); @@ -513,8 +510,6 @@ public class MariaDBVectorStore extends AbstractObservationVectorStore implement private boolean initializeSchema = false; - private BatchingStrategy batchingStrategy = new TokenCountBatchingStrategy(); - private int maxDocumentBatchSize = MAX_DOCUMENT_BATCH_SIZE; /** @@ -602,18 +597,6 @@ public class MariaDBVectorStore extends AbstractObservationVectorStore implement return this; } - /** - * Configures the strategy for batching operations. - * @param batchingStrategy the batching strategy to use - * @return this builder instance - * @throws IllegalArgumentException if batchingStrategy is null - */ - public MariaDBBuilder batchingStrategy(BatchingStrategy batchingStrategy) { - Assert.notNull(batchingStrategy, "BatchingStrategy must not be null"); - this.batchingStrategy = batchingStrategy; - return this; - } - /** * Configures the maximum batch size for document operations. * @param maxDocumentBatchSize the maximum number of documents to process in a diff --git a/vector-stores/spring-ai-milvus-store/src/main/java/org/springframework/ai/vectorstore/milvus/MilvusVectorStore.java b/vector-stores/spring-ai-milvus-store/src/main/java/org/springframework/ai/vectorstore/milvus/MilvusVectorStore.java index 071dc077a..e16a5de72 100644 --- a/vector-stores/spring-ai-milvus-store/src/main/java/org/springframework/ai/vectorstore/milvus/MilvusVectorStore.java +++ b/vector-stores/spring-ai-milvus-store/src/main/java/org/springframework/ai/vectorstore/milvus/MilvusVectorStore.java @@ -174,8 +174,6 @@ public class MilvusVectorStore extends AbstractObservationVectorStore implements private final boolean initializeSchema; - private final BatchingStrategy batchingStrategy; - private final String databaseName; private final String collectionName; @@ -207,7 +205,6 @@ public class MilvusVectorStore extends AbstractObservationVectorStore implements Assert.notNull(builder.milvusClient, "milvusClient must not be null"); this.milvusClient = builder.milvusClient; - this.batchingStrategy = builder.batchingStrategy; this.initializeSchema = builder.initializeSchema; this.databaseName = builder.databaseName; this.collectionName = builder.collectionName; @@ -564,8 +561,6 @@ public class MilvusVectorStore extends AbstractObservationVectorStore implements private boolean initializeSchema = false; - private BatchingStrategy batchingStrategy = new TokenCountBatchingStrategy(); - /** * @param milvusClient the Milvus service client to use for database operations * @throws IllegalArgumentException if milvusClient is null @@ -713,18 +708,6 @@ public class MilvusVectorStore extends AbstractObservationVectorStore implements return this; } - /** - * Configures the strategy for batching operations. - * @param batchingStrategy the batching strategy to use for grouping operations - * @return this builder instance - * @throws IllegalArgumentException if batchingStrategy is null - */ - public Builder batchingStrategy(BatchingStrategy batchingStrategy) { - Assert.notNull(batchingStrategy, "batchingStrategy must not be null"); - this.batchingStrategy = batchingStrategy; - return this; - } - /** * Builds and returns a new MilvusVectorStore instance with the configured * settings. diff --git a/vector-stores/spring-ai-mongodb-atlas-store/src/main/java/org/springframework/ai/vectorstore/mongodb/atlas/MongoDBAtlasVectorStore.java b/vector-stores/spring-ai-mongodb-atlas-store/src/main/java/org/springframework/ai/vectorstore/mongodb/atlas/MongoDBAtlasVectorStore.java index 0a68df30a..d2a3c637d 100644 --- a/vector-stores/spring-ai-mongodb-atlas-store/src/main/java/org/springframework/ai/vectorstore/mongodb/atlas/MongoDBAtlasVectorStore.java +++ b/vector-stores/spring-ai-mongodb-atlas-store/src/main/java/org/springframework/ai/vectorstore/mongodb/atlas/MongoDBAtlasVectorStore.java @@ -161,8 +161,6 @@ public class MongoDBAtlasVectorStore extends AbstractObservationVectorStore impl private final boolean initializeSchema; - private final BatchingStrategy batchingStrategy; - protected MongoDBAtlasVectorStore(Builder builder) { super(builder); @@ -176,7 +174,6 @@ public class MongoDBAtlasVectorStore extends AbstractObservationVectorStore impl this.metadataFieldsToFilter = builder.metadataFieldsToFilter; this.filterExpressionConverter = builder.filterExpressionConverter; this.initializeSchema = builder.initializeSchema; - this.batchingStrategy = builder.batchingStrategy; } @Override @@ -337,8 +334,6 @@ public class MongoDBAtlasVectorStore extends AbstractObservationVectorStore impl private boolean initializeSchema = false; - private BatchingStrategy batchingStrategy = new TokenCountBatchingStrategy(); - private MongoDBAtlasFilterExpressionConverter filterExpressionConverter = new MongoDBAtlasFilterExpressionConverter(); /** @@ -421,18 +416,6 @@ public class MongoDBAtlasVectorStore extends AbstractObservationVectorStore impl return this; } - /** - * Sets the batching strategy for vector operations. - * @param batchingStrategy the batching strategy to use - * @return the builder instance - * @throws IllegalArgumentException if batchingStrategy is null - */ - public Builder batchingStrategy(BatchingStrategy batchingStrategy) { - Assert.notNull(batchingStrategy, "batchingStrategy must not be null"); - this.batchingStrategy = batchingStrategy; - return this; - } - /** * Sets the filter expression converter. * @param converter the filter expression converter to use diff --git a/vector-stores/spring-ai-neo4j-store/src/main/java/org/springframework/ai/vectorstore/neo4j/Neo4jVectorStore.java b/vector-stores/spring-ai-neo4j-store/src/main/java/org/springframework/ai/vectorstore/neo4j/Neo4jVectorStore.java index 6429bb2f1..2975b1276 100644 --- a/vector-stores/spring-ai-neo4j-store/src/main/java/org/springframework/ai/vectorstore/neo4j/Neo4jVectorStore.java +++ b/vector-stores/spring-ai-neo4j-store/src/main/java/org/springframework/ai/vectorstore/neo4j/Neo4jVectorStore.java @@ -175,8 +175,6 @@ public class Neo4jVectorStore extends AbstractObservationVectorStore implements private final boolean initializeSchema; - private final BatchingStrategy batchingStrategy; - protected Neo4jVectorStore(Builder builder) { super(builder); @@ -193,7 +191,6 @@ public class Neo4jVectorStore extends AbstractObservationVectorStore implements this.idProperty = SchemaNames.sanitize(builder.idProperty).orElseThrow(); this.constraintName = SchemaNames.sanitize(builder.constraintName).orElseThrow(); this.initializeSchema = builder.initializeSchema; - this.batchingStrategy = builder.batchingStrategy; } @Override @@ -391,8 +388,6 @@ public class Neo4jVectorStore extends AbstractObservationVectorStore implements private boolean initializeSchema = false; - private BatchingStrategy batchingStrategy = new TokenCountBatchingStrategy(); - private Builder(Driver driver, EmbeddingModel embeddingModel) { super(embeddingModel); Assert.notNull(driver, "Neo4j driver must not be null"); @@ -516,18 +511,6 @@ public class Neo4jVectorStore extends AbstractObservationVectorStore implements return this; } - /** - * Sets the batching strategy. - * @param batchingStrategy the strategy to use - * @return the builder instance - * @throws IllegalArgumentException if batchingStrategy is null - */ - public Builder batchingStrategy(BatchingStrategy batchingStrategy) { - Assert.notNull(batchingStrategy, "BatchingStrategy must not be null"); - this.batchingStrategy = batchingStrategy; - return this; - } - @Override public Neo4jVectorStore build() { return new Neo4jVectorStore(this); diff --git a/vector-stores/spring-ai-opensearch-store/src/main/java/org/springframework/ai/vectorstore/opensearch/OpenSearchVectorStore.java b/vector-stores/spring-ai-opensearch-store/src/main/java/org/springframework/ai/vectorstore/opensearch/OpenSearchVectorStore.java index b37533887..aea53ed22 100644 --- a/vector-stores/spring-ai-opensearch-store/src/main/java/org/springframework/ai/vectorstore/opensearch/OpenSearchVectorStore.java +++ b/vector-stores/spring-ai-opensearch-store/src/main/java/org/springframework/ai/vectorstore/opensearch/OpenSearchVectorStore.java @@ -164,8 +164,6 @@ public class OpenSearchVectorStore extends AbstractObservationVectorStore implem private final boolean initializeSchema; - private final BatchingStrategy batchingStrategy; - private String similarityFunction; /** @@ -185,7 +183,6 @@ public class OpenSearchVectorStore extends AbstractObservationVectorStore implem // https://opensearch.org/docs/latest/search-plugins/knn/approximate-knn/#spaces this.similarityFunction = builder.similarityFunction; this.initializeSchema = builder.initializeSchema; - this.batchingStrategy = builder.batchingStrategy; } /** @@ -378,8 +375,6 @@ public class OpenSearchVectorStore extends AbstractObservationVectorStore implem private boolean initializeSchema = false; - private BatchingStrategy batchingStrategy = new TokenCountBatchingStrategy(); - private FilterExpressionConverter filterExpressionConverter = new OpenSearchAiSearchFilterExpressionConverter(); private String similarityFunction = COSINE_SIMILARITY_FUNCTION; @@ -429,18 +424,6 @@ public class OpenSearchVectorStore extends AbstractObservationVectorStore implem return this; } - /** - * Sets the batching strategy. - * @param batchingStrategy The batching strategy to use - * @return The builder instance - * @throws IllegalArgumentException if batchingStrategy is null - */ - public Builder batchingStrategy(BatchingStrategy batchingStrategy) { - Assert.notNull(batchingStrategy, "batchingStrategy must not be null"); - this.batchingStrategy = batchingStrategy; - return this; - } - /** * Sets the filter expression converter. * @param converter The filter expression converter to use diff --git a/vector-stores/spring-ai-oracle-store/src/main/java/org/springframework/ai/vectorstore/oracle/OracleVectorStore.java b/vector-stores/spring-ai-oracle-store/src/main/java/org/springframework/ai/vectorstore/oracle/OracleVectorStore.java index 9ea631c81..feac0ece8 100644 --- a/vector-stores/spring-ai-oracle-store/src/main/java/org/springframework/ai/vectorstore/oracle/OracleVectorStore.java +++ b/vector-stores/spring-ai-oracle-store/src/main/java/org/springframework/ai/vectorstore/oracle/OracleVectorStore.java @@ -138,8 +138,6 @@ public class OracleVectorStore extends AbstractObservationVectorStore implements private final int searchAccuracy; - private final BatchingStrategy batchingStrategy; - private final OracleJsonFactory osonFactory = new OracleJsonFactory(); private final ByteArrayOutputStream out = new ByteArrayOutputStream(); @@ -163,7 +161,6 @@ public class OracleVectorStore extends AbstractObservationVectorStore implements this.initializeSchema = builder.initializeSchema; this.removeExistingVectorStoreTable = builder.removeExistingVectorStoreTable; this.forcedNormalization = builder.forcedNormalization; - this.batchingStrategy = builder.batchingStrategy; } public static Builder builder(JdbcTemplate jdbcTemplate, EmbeddingModel embeddingModel) { @@ -674,8 +671,6 @@ public class OracleVectorStore extends AbstractObservationVectorStore implements private boolean forcedNormalization = false; - private BatchingStrategy batchingStrategy = new TokenCountBatchingStrategy(); - /** * Sets the JdbcTemplate to be used for database operations. * @param jdbcTemplate the JdbcTemplate instance @@ -784,18 +779,6 @@ public class OracleVectorStore extends AbstractObservationVectorStore implements return this; } - /** - * Sets the batching strategy for vector operations. - * @param batchingStrategy the strategy to use - * @return the builder instance - * @throws IllegalArgumentException if batchingStrategy is null - */ - public Builder batchingStrategy(BatchingStrategy batchingStrategy) { - Assert.notNull(batchingStrategy, "BatchingStrategy must not be null"); - this.batchingStrategy = batchingStrategy; - return this; - } - @Override public OracleVectorStore build() { return new OracleVectorStore(this); diff --git a/vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/pgvector/PgVectorStore.java b/vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/pgvector/PgVectorStore.java index 55c5f91c5..19b70507d 100644 --- a/vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/pgvector/PgVectorStore.java +++ b/vector-stores/spring-ai-pgvector-store/src/main/java/org/springframework/ai/vectorstore/pgvector/PgVectorStore.java @@ -203,8 +203,6 @@ public class PgVectorStore extends AbstractObservationVectorStore implements Ini private final PgVectorSchemaValidator schemaValidator; - private final BatchingStrategy batchingStrategy; - private final int maxDocumentBatchSize; /** @@ -235,7 +233,6 @@ public class PgVectorStore extends AbstractObservationVectorStore implements Ini this.createIndexMethod = builder.indexType; this.initializeSchema = builder.initializeSchema; this.schemaValidator = new PgVectorSchemaValidator(this.jdbcTemplate); - this.batchingStrategy = builder.batchingStrategy; this.maxDocumentBatchSize = builder.maxDocumentBatchSize; } @@ -599,8 +596,6 @@ public class PgVectorStore extends AbstractObservationVectorStore implements Ini private boolean initializeSchema; - private BatchingStrategy batchingStrategy = new TokenCountBatchingStrategy(); - private int maxDocumentBatchSize = MAX_DOCUMENT_BATCH_SIZE; private PgVectorStoreBuilder(JdbcTemplate jdbcTemplate, EmbeddingModel embeddingModel) { @@ -649,11 +644,6 @@ public class PgVectorStore extends AbstractObservationVectorStore implements Ini return this; } - public PgVectorStoreBuilder batchingStrategy(BatchingStrategy batchingStrategy) { - this.batchingStrategy = batchingStrategy; - return this; - } - public PgVectorStoreBuilder maxDocumentBatchSize(int maxDocumentBatchSize) { this.maxDocumentBatchSize = maxDocumentBatchSize; return this; diff --git a/vector-stores/spring-ai-pinecone-store/src/main/java/org/springframework/ai/vectorstore/pinecone/PineconeVectorStore.java b/vector-stores/spring-ai-pinecone-store/src/main/java/org/springframework/ai/vectorstore/pinecone/PineconeVectorStore.java index 9bb37d3bd..b78c89fd2 100644 --- a/vector-stores/spring-ai-pinecone-store/src/main/java/org/springframework/ai/vectorstore/pinecone/PineconeVectorStore.java +++ b/vector-stores/spring-ai-pinecone-store/src/main/java/org/springframework/ai/vectorstore/pinecone/PineconeVectorStore.java @@ -82,8 +82,6 @@ public class PineconeVectorStore extends AbstractObservationVectorStore { private final ObjectMapper objectMapper; - private final BatchingStrategy batchingStrategy; - /** * Creates a new PineconeVectorStore using the builder pattern. * @param builder The configured builder instance @@ -110,7 +108,6 @@ public class PineconeVectorStore extends AbstractObservationVectorStore { this.pineconeConnection = new PineconeClient(clientConfig).connect(connectionConfig); this.objectMapper = new ObjectMapper(); - this.batchingStrategy = builder.batchingStrategy; } /** @@ -317,8 +314,6 @@ public class PineconeVectorStore extends AbstractObservationVectorStore { private Duration serverSideTimeout = Duration.ofSeconds(20); - private BatchingStrategy batchingStrategy = new TokenCountBatchingStrategy(); - private Builder(EmbeddingModel embeddingModel, String apiKey, String projectId, String environment, String indexName) { super(embeddingModel); @@ -376,18 +371,6 @@ public class PineconeVectorStore extends AbstractObservationVectorStore { return this; } - /** - * Sets the batching strategy. - * @param batchingStrategy The batching strategy to use - * @return The builder instance - * @throws IllegalArgumentException if batchingStrategy is null - */ - public Builder batchingStrategy(BatchingStrategy batchingStrategy) { - Assert.notNull(batchingStrategy, "BatchingStrategy must not be null"); - this.batchingStrategy = batchingStrategy; - return this; - } - /** * Builds a new PineconeVectorStore instance with the configured properties. * @return A new PineconeVectorStore instance 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 93486feea..9c8733040 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 @@ -138,8 +138,6 @@ public class QdrantVectorStore extends AbstractObservationVectorStore implements private final boolean initializeSchema; - private final BatchingStrategy batchingStrategy; - /** * Protected constructor for creating a QdrantVectorStore instance using the builder * pattern. @@ -156,7 +154,6 @@ public class QdrantVectorStore extends AbstractObservationVectorStore implements this.qdrantClient = builder.qdrantClient; this.collectionName = builder.collectionName; this.initializeSchema = builder.initializeSchema; - this.batchingStrategy = builder.batchingStrategy; } /** @@ -337,8 +334,6 @@ public class QdrantVectorStore extends AbstractObservationVectorStore implements private boolean initializeSchema = false; - private BatchingStrategy batchingStrategy = new TokenCountBatchingStrategy(); - /** * Creates a new builder instance with the required QdrantClient and * EmbeddingModel. @@ -374,18 +369,6 @@ public class QdrantVectorStore extends AbstractObservationVectorStore implements return this; } - /** - * Configures the strategy for batching operations. - * @param batchingStrategy the batching strategy to use - * @return this builder instance - * @throws IllegalArgumentException if batchingStrategy is null - */ - public Builder batchingStrategy(BatchingStrategy batchingStrategy) { - Assert.notNull(batchingStrategy, "BatchingStrategy must not be null"); - this.batchingStrategy = batchingStrategy; - return this; - } - /** * Builds and returns a new QdrantVectorStore instance with the configured * settings. diff --git a/vector-stores/spring-ai-redis-store/src/main/java/org/springframework/ai/vectorstore/redis/RedisVectorStore.java b/vector-stores/spring-ai-redis-store/src/main/java/org/springframework/ai/vectorstore/redis/RedisVectorStore.java index 88b409f56..fd28c7fc5 100644 --- a/vector-stores/spring-ai-redis-store/src/main/java/org/springframework/ai/vectorstore/redis/RedisVectorStore.java +++ b/vector-stores/spring-ai-redis-store/src/main/java/org/springframework/ai/vectorstore/redis/RedisVectorStore.java @@ -228,8 +228,6 @@ public class RedisVectorStore extends AbstractObservationVectorStore implements private final List metadataFields; - private final BatchingStrategy batchingStrategy; - private final FilterExpressionConverter filterExpressionConverter; protected RedisVectorStore(Builder builder) { @@ -245,7 +243,6 @@ public class RedisVectorStore extends AbstractObservationVectorStore implements this.vectorAlgorithm = builder.vectorAlgorithm; this.metadataFields = builder.metadataFields; this.initializeSchema = builder.initializeSchema; - this.batchingStrategy = builder.batchingStrategy; this.filterExpressionConverter = new RedisFilterExpressionConverter(this.metadataFields); } @@ -475,8 +472,6 @@ public class RedisVectorStore extends AbstractObservationVectorStore implements private boolean initializeSchema = false; - private BatchingStrategy batchingStrategy = new TokenCountBatchingStrategy(); - private Builder(JedisPooled jedis, EmbeddingModel embeddingModel) { super(embeddingModel); Assert.notNull(jedis, "JedisPooled must not be null"); @@ -574,18 +569,6 @@ public class RedisVectorStore extends AbstractObservationVectorStore implements return this; } - /** - * Sets the batching strategy. - * @param batchingStrategy the strategy to use - * @return the builder instance - * @throws IllegalArgumentException if batchingStrategy is null - */ - public Builder batchingStrategy(BatchingStrategy batchingStrategy) { - Assert.notNull(batchingStrategy, "BatchingStrategy must not be null"); - this.batchingStrategy = batchingStrategy; - return this; - } - @Override public RedisVectorStore build() { return new RedisVectorStore(this); diff --git a/vector-stores/spring-ai-typesense-store/src/main/java/org/springframework/ai/vectorstore/typesense/TypesenseVectorStore.java b/vector-stores/spring-ai-typesense-store/src/main/java/org/springframework/ai/vectorstore/typesense/TypesenseVectorStore.java index f6c062896..e32ef4e55 100644 --- a/vector-stores/spring-ai-typesense-store/src/main/java/org/springframework/ai/vectorstore/typesense/TypesenseVectorStore.java +++ b/vector-stores/spring-ai-typesense-store/src/main/java/org/springframework/ai/vectorstore/typesense/TypesenseVectorStore.java @@ -102,8 +102,6 @@ public class TypesenseVectorStore extends AbstractObservationVectorStore impleme private final boolean initializeSchema; - private final BatchingStrategy batchingStrategy; - private final String collectionName; private final int embeddingDimension; @@ -125,7 +123,6 @@ public class TypesenseVectorStore extends AbstractObservationVectorStore impleme this.client = builder.client; this.initializeSchema = builder.initializeSchema; - this.batchingStrategy = builder.batchingStrategy; this.collectionName = builder.collectionName; this.embeddingDimension = builder.embeddingDimension; } @@ -363,8 +360,6 @@ public class TypesenseVectorStore extends AbstractObservationVectorStore impleme private boolean initializeSchema = false; - private BatchingStrategy batchingStrategy = new TokenCountBatchingStrategy(); - /** * Constructs a new TypesenseBuilder instance. * @param client The Typesense client instance used for database operations. Must @@ -412,18 +407,6 @@ public class TypesenseVectorStore extends AbstractObservationVectorStore impleme return this; } - /** - * Configures the strategy for batching operations. - * @param batchingStrategy the batching strategy to use - * @return this builder instance - * @throws IllegalArgumentException if batchingStrategy is null - */ - public Builder batchingStrategy(BatchingStrategy batchingStrategy) { - Assert.notNull(batchingStrategy, "batchingStrategy must not be null"); - this.batchingStrategy = batchingStrategy; - return this; - } - @Override public TypesenseVectorStore build() { return new TypesenseVectorStore(this); diff --git a/vector-stores/spring-ai-typesense-store/src/test/java/org/springframework/ai/vectorstore/typesense/TypesenseVectorStoreBuilderTests.java b/vector-stores/spring-ai-typesense-store/src/test/java/org/springframework/ai/vectorstore/typesense/TypesenseVectorStoreBuilderTests.java index 6b37a0e4d..5dd626d49 100644 --- a/vector-stores/spring-ai-typesense-store/src/test/java/org/springframework/ai/vectorstore/typesense/TypesenseVectorStoreBuilderTests.java +++ b/vector-stores/spring-ai-typesense-store/src/test/java/org/springframework/ai/vectorstore/typesense/TypesenseVectorStoreBuilderTests.java @@ -109,7 +109,7 @@ class TypesenseVectorStoreBuilderTests { assertThatThrownBy( () -> TypesenseVectorStore.builder(this.client, this.embeddingModel).batchingStrategy(null).build()) .isInstanceOf(IllegalArgumentException.class) - .hasMessage("batchingStrategy must not be null"); + .hasMessage("BatchingStrategy must not be null"); } } diff --git a/vector-stores/spring-ai-weaviate-store/src/main/java/org/springframework/ai/vectorstore/weaviate/WeaviateVectorStore.java b/vector-stores/spring-ai-weaviate-store/src/main/java/org/springframework/ai/vectorstore/weaviate/WeaviateVectorStore.java index 10fecdfbc..b8610620b 100644 --- a/vector-stores/spring-ai-weaviate-store/src/main/java/org/springframework/ai/vectorstore/weaviate/WeaviateVectorStore.java +++ b/vector-stores/spring-ai-weaviate-store/src/main/java/org/springframework/ai/vectorstore/weaviate/WeaviateVectorStore.java @@ -113,8 +113,6 @@ public class WeaviateVectorStore extends AbstractObservationVectorStore { private final String weaviateObjectClass; - private final BatchingStrategy batchingStrategy; - /** * List of metadata fields (as field name and type) that can be used in similarity * search query filter expressions. The {@link Document#getMetadata()} can contain @@ -161,7 +159,6 @@ public class WeaviateVectorStore extends AbstractObservationVectorStore { this.consistencyLevel = builder.consistencyLevel; this.weaviateObjectClass = builder.weaviateObjectClass; this.filterMetadataFields = builder.filterMetadataFields; - this.batchingStrategy = builder.batchingStrategy; this.filterExpressionConverter = new WeaviateFilterExpressionConverter( this.filterMetadataFields.stream().map(MetadataField::name).toList()); this.weaviateSimilaritySearchFields = buildWeaviateSimilaritySearchFields(); @@ -497,8 +494,6 @@ public class WeaviateVectorStore extends AbstractObservationVectorStore { private final WeaviateClient weaviateClient; - private BatchingStrategy batchingStrategy = new TokenCountBatchingStrategy(); - /** * Constructs a new WeaviateBuilder instance. * @param weaviateClient The Weaviate client instance used for database @@ -548,18 +543,6 @@ public class WeaviateVectorStore extends AbstractObservationVectorStore { return this; } - /** - * Configures the batching strategy. - * @param batchingStrategy the strategy for batching operations - * @return this builder instance - * @throws IllegalArgumentException if batchingStrategy is null - */ - public Builder batchingStrategy(BatchingStrategy batchingStrategy) { - Assert.notNull(batchingStrategy, "batchingStrategy must not be null"); - this.batchingStrategy = batchingStrategy; - return this; - } - /** * Builds and returns a new WeaviateVectorStore instance with the configured * settings.