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.
This commit is contained in:
Soby Chacko
2025-01-08 11:51:42 -05:00
committed by Ilayaperumal Gopinathan
parent 6a5326816c
commit 9844a18983
22 changed files with 35 additions and 292 deletions

View File

@@ -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<T extends AbstractVectorStoreBu
@Nullable
protected VectorStoreObservationConvention customObservationConvention;
protected BatchingStrategy batchingStrategy = new TokenCountBatchingStrategy();
public AbstractVectorStoreBuilder(EmbeddingModel embeddingModel) {
Assert.notNull(embeddingModel, "EmbeddingModel must be configured");
this.embeddingModel = embeddingModel;
@@ -49,6 +53,10 @@ public abstract class AbstractVectorStoreBuilder<T extends AbstractVectorStoreBu
return this.embeddingModel;
}
public BatchingStrategy getBatchingStrategy() {
return this.batchingStrategy;
}
public ObservationRegistry getObservationRegistry() {
return this.observationRegistry;
}
@@ -81,4 +89,15 @@ public abstract class AbstractVectorStoreBuilder<T extends AbstractVectorStoreBu
return self();
}
/**
* Sets the batching strategy.
* @param batchingStrategy the strategy to use
* @return the builder instance
*/
public T batchingStrategy(BatchingStrategy batchingStrategy) {
Assert.notNull(batchingStrategy, "BatchingStrategy must not be null");
this.batchingStrategy = batchingStrategy;
return self();
}
}

View File

@@ -23,6 +23,7 @@ import io.micrometer.observation.ObservationRegistry;
import org.springframework.ai.document.Document;
import org.springframework.ai.document.DocumentWriter;
import org.springframework.ai.embedding.BatchingStrategy;
import org.springframework.ai.vectorstore.observation.DefaultVectorStoreObservationConvention;
import org.springframework.ai.vectorstore.observation.VectorStoreObservationConvention;
import org.springframework.lang.Nullable;
@@ -108,6 +109,13 @@ public interface VectorStore extends DocumentWriter {
*/
T customObservationConvention(VectorStoreObservationConvention convention);
/**
* Sets the batching strategy.
* @param batchingStrategy the strategy to use
* @return the builder instance for method chaining
*/
T batchingStrategy(BatchingStrategy batchingStrategy);
/**
* Builds and returns a new VectorStore instance with the configured settings.
* @return a new VectorStore instance

View File

@@ -22,6 +22,7 @@ import java.util.Optional;
import io.micrometer.observation.ObservationRegistry;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.BatchingStrategy;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.AbstractVectorStoreBuilder;
import org.springframework.ai.vectorstore.SearchRequest;
@@ -47,11 +48,14 @@ public abstract class AbstractObservationVectorStore implements VectorStore {
protected final EmbeddingModel embeddingModel;
protected final BatchingStrategy batchingStrategy;
private AbstractObservationVectorStore(EmbeddingModel embeddingModel, ObservationRegistry observationRegistry,
@Nullable VectorStoreObservationConvention customObservationConvention) {
@Nullable VectorStoreObservationConvention customObservationConvention, BatchingStrategy batchingStrategy) {
this.embeddingModel = embeddingModel;
this.observationRegistry = observationRegistry;
this.customObservationConvention = customObservationConvention;
this.batchingStrategy = batchingStrategy;
}
/**
@@ -60,7 +64,8 @@ public abstract class AbstractObservationVectorStore implements VectorStore {
* @param builder the builder containing configuration settings
*/
public AbstractObservationVectorStore(AbstractVectorStoreBuilder<?> builder) {
this(builder.getEmbeddingModel(), builder.getObservationRegistry(), builder.getCustomObservationConvention());
this(builder.getEmbeddingModel(), builder.getObservationRegistry(), builder.getCustomObservationConvention(),
builder.getBatchingStrategy());
}
/**

View File

@@ -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<String> 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<String> metadataFieldsList = new ArrayList<>();
private BatchingStrategy batchingStrategy = new TokenCountBatchingStrategy();
private Builder(CosmosAsyncClient cosmosClient, EmbeddingModel embeddingModel) {
super(embeddingModel);
Assert.notNull(cosmosClient, "CosmosClient must not be null");

View File

@@ -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<MetadataField> 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

View File

@@ -215,8 +215,6 @@ public class CassandraVectorStore extends AbstractObservationVectorStore impleme
private final boolean closeSessionOnClose;
private final BatchingStrategy batchingStrategy;
private final ConcurrentMap<Set<String>, 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

View File

@@ -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

View File

@@ -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

View File

@@ -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);

View File

@@ -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

View File

@@ -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.

View File

@@ -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

View File

@@ -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);

View File

@@ -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

View File

@@ -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);

View File

@@ -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;

View File

@@ -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

View File

@@ -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.

View File

@@ -228,8 +228,6 @@ public class RedisVectorStore extends AbstractObservationVectorStore implements
private final List<MetadataField> 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);

View File

@@ -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);

View File

@@ -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");
}
}

View File

@@ -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.