+ * Example usage with builder: + *
+ *{@code
+ * // Create the vector store with builder
+ * WeaviateVectorStore vectorStore = WeaviateVectorStore.builder()
+ * .weaviateClient(weaviateClient) // Required: Configure Weaviate client
+ * .embeddingModel(embeddingModel) // Required: Configure embedding model
+ * .objectClass("CustomClass") // Optional: Custom class name (default: SpringAiWeaviate)
+ * .consistencyLevel(ConsistentLevel.QUORUM) // Optional: Set consistency level (default: ONE)
+ * .filterMetadataFields(List.of( // Optional: Configure filterable metadata fields
+ * MetadataField.text("country"),
+ * MetadataField.number("year")
+ * ))
+ * .build();
+ * }
+ *
* @author Christian Tzolov
* @author EddĂș MelĂ©ndez
* @author Josh Long
* @author Soby Chacko
* @author Thomas Vitale
+ * @since 1.0.0
*/
public class WeaviateVectorStore extends AbstractObservationVectorStore {
@@ -92,8 +110,6 @@ public class WeaviateVectorStore extends AbstractObservationVectorStore {
private static final String ADDITIONAL_VECTOR_FIELD_NAME = "vector";
- private final EmbeddingModel embeddingModel;
-
private final WeaviateClient weaviateClient;
private final ConsistentLevel consistencyLevel;
@@ -131,11 +147,16 @@ public class WeaviateVectorStore extends AbstractObservationVectorStore {
private final ObjectMapper objectMapper = new ObjectMapper();
/**
- * Constructs a new WeaviateVectorStore.
- * @param vectorStoreConfig The configuration for the store.
- * @param embeddingModel The client for embedding operations.
- * @param weaviateClient The client for Weaviate operations.
+ * Constructs a new WeaviateVectorStore with default settings.
+ * @param vectorStoreConfig The configuration for the store
+ * @param embeddingModel The client for embedding operations
+ * @param weaviateClient The client for Weaviate operations
+ * @deprecated Use {@link #builder()} instead to create instances of
+ * WeaviateVectorStore. This constructor will be removed in a future release.
+ * @see #builder()
+ * @since 1.0.0
*/
+ @Deprecated(forRemoval = true, since = "1.0.0-M5")
public WeaviateVectorStore(WeaviateVectorStoreConfig vectorStoreConfig, EmbeddingModel embeddingModel,
WeaviateClient weaviateClient) {
this(vectorStoreConfig, embeddingModel, weaviateClient, ObservationRegistry.NOOP, null,
@@ -143,31 +164,61 @@ public class WeaviateVectorStore extends AbstractObservationVectorStore {
}
/**
- * Constructs a new WeaviateVectorStore.
- * @param vectorStoreConfig The configuration for the store.
- * @param embeddingModel The client for embedding operations.
- * @param weaviateClient The client for Weaviate operations.
- * @param observationRegistry The registry for observations.
- * @param customObservationConvention The custom observation convention.
+ * Constructs a new WeaviateVectorStore with custom settings.
+ * @param vectorStoreConfig The configuration for the store
+ * @param embeddingModel The client for embedding operations
+ * @param weaviateClient The client for Weaviate operations
+ * @param observationRegistry The registry for observations
+ * @param customObservationConvention The custom observation convention
+ * @param batchingStrategy The strategy for batching operations
+ * @deprecated Use {@link #builder()} instead to create instances of
+ * WeaviateVectorStore. This constructor will be removed in a future release.
+ * @see #builder()
+ * @since 1.0.0
*/
+ @Deprecated(forRemoval = true, since = "1.0.0-M5")
public WeaviateVectorStore(WeaviateVectorStoreConfig vectorStoreConfig, EmbeddingModel embeddingModel,
WeaviateClient weaviateClient, ObservationRegistry observationRegistry,
VectorStoreObservationConvention customObservationConvention, BatchingStrategy batchingStrategy) {
- super(observationRegistry, customObservationConvention);
+ this(builder().embeddingModel(embeddingModel)
+ .weaviateClient(weaviateClient)
+ .observationRegistry(observationRegistry)
+ .customObservationConvention(customObservationConvention)
+ .batchingStrategy(batchingStrategy));
+ }
- Assert.notNull(vectorStoreConfig, "WeaviateVectorStoreConfig must not be null");
- Assert.notNull(embeddingModel, "EmbeddingModel must not be null");
+ /**
+ * Protected constructor for creating a WeaviateVectorStore instance using the builder
+ * pattern. This constructor initializes the vector store with the configured settings
+ * from the builder and performs necessary validations.
+ * @param builder the {@link WeaviateBuilder} containing all configuration settings
+ * @throws IllegalArgumentException if the weaviateClient is null
+ * @see WeaviateBuilder
+ * @since 1.0.0
+ */
+ protected WeaviateVectorStore(WeaviateBuilder builder) {
+ super(builder);
- this.embeddingModel = embeddingModel;
- this.consistencyLevel = vectorStoreConfig.consistencyLevel;
- this.weaviateObjectClass = vectorStoreConfig.weaviateObjectClass;
- this.filterMetadataFields = vectorStoreConfig.filterMetadataFields;
+ Assert.notNull(builder.weaviateClient, "WeaviateClient must not be null");
+
+ this.weaviateClient = builder.weaviateClient;
+ 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.weaviateClient = weaviateClient;
this.weaviateSimilaritySearchFields = buildWeaviateSimilaritySearchFields();
- this.batchingStrategy = batchingStrategy;
+ }
+
+ /**
+ * Creates a new WeaviateBuilder instance. This is the recommended way to instantiate
+ * a WeaviateVectorStore.
+ * @return a new WeaviateBuilder instance
+ */
+ public static WeaviateBuilder builder() {
+ return new WeaviateBuilder();
}
private Field[] buildWeaviateSimilaritySearchFields() {
@@ -402,8 +453,193 @@ public class WeaviateVectorStore extends AbstractObservationVectorStore {
}
/**
- * Configuration class for the WeaviateVectorStore.
+ * Defines the consistency levels for Weaviate operations.
+ *
+ * @see Weaviate
+ * Consistency Strategies
*/
+ public enum ConsistentLevel {
+
+ /**
+ * Write must receive an acknowledgement from at least one replica node. This is
+ * the fastest (most available), but least consistent option.
+ */
+ ONE,
+
+ /**
+ * Write must receive an acknowledgement from at least QUORUM replica nodes.
+ * QUORUM is calculated as n / 2 + 1, where n is the number of replicas.
+ */
+ QUORUM,
+
+ /**
+ * Write must receive an acknowledgement from all replica nodes. This is the most
+ * consistent, but 'slowest'.
+ */
+ ALL
+
+ }
+
+ /**
+ * Represents a metadata field configuration for Weaviate vector store.
+ *
+ * @param name the name of the metadata field
+ * @param type the type of the metadata field
+ */
+ public record MetadataField(String name, Type type) {
+
+ /**
+ * Creates a metadata field of type TEXT.
+ * @param name the name of the field
+ * @return a new MetadataField instance of type TEXT
+ * @throws IllegalArgumentException if name is null or empty
+ */
+ public static MetadataField text(String name) {
+ Assert.hasText(name, "Text field must not be empty");
+ return new MetadataField(name, Type.TEXT);
+ }
+
+ /**
+ * Creates a metadata field of type NUMBER.
+ * @param name the name of the field
+ * @return a new MetadataField instance of type NUMBER
+ * @throws IllegalArgumentException if name is null or empty
+ */
+ public static MetadataField number(String name) {
+ Assert.hasText(name, "Number field must not be empty");
+ return new MetadataField(name, Type.NUMBER);
+ }
+
+ /**
+ * Creates a metadata field of type BOOLEAN.
+ * @param name the name of the field
+ * @return a new MetadataField instance of type BOOLEAN
+ * @throws IllegalArgumentException if name is null or empty
+ */
+ public static MetadataField bool(String name) {
+ Assert.hasText(name, "Boolean field name must not be empty");
+ return new MetadataField(name, Type.BOOLEAN);
+ }
+
+ /**
+ * Defines the supported types for metadata fields.
+ */
+ public enum Type {
+
+ TEXT, NUMBER, BOOLEAN
+
+ }
+ }
+
+ public static final class WeaviateBuilder extends AbstractVectorStoreBuilder{@code
+ * // Old approach:
+ * WeaviateVectorStoreConfig config = WeaviateVectorStoreConfig.builder()
+ * .withObjectClass("CustomClass")
+ * .withConsistencyLevel(ConsistentLevel.QUORUM)
+ * .build();
+ *
+ * // New approach:
+ * WeaviateVectorStore store = WeaviateVectorStore.builder()
+ * .objectClass("CustomClass")
+ * .consistencyLevel(ConsistentLevel.QUORUM)
+ * .build();
+ * }
+ * @see WeaviateVectorStore#builder()
+ * @since 1.0.0
+ */
+ @Deprecated(forRemoval = true, since = "1.0.0-M5")
public static final class WeaviateVectorStoreConfig {
private final String weaviateObjectClass;
@@ -421,8 +657,10 @@ public class WeaviateVectorStore extends AbstractObservationVectorStore {
/**
* Constructor using the builder.
- * @param builder The configuration builder.
+ * @param builder The configuration builder
+ * @deprecated Use {@link WeaviateVectorStore#builder()} instead
*/
+ @Deprecated(forRemoval = true, since = "1.0.0-M5")
public WeaviateVectorStoreConfig(Builder builder) {
this.weaviateObjectClass = builder.objectClass;
this.consistencyLevel = builder.consistencyLevel;
@@ -432,22 +670,43 @@ public class WeaviateVectorStore extends AbstractObservationVectorStore {
/**
* Start building a new configuration.
- * @return The entry point for creating a new configuration.
+ * @return The entry point for creating a new configuration
+ * @deprecated Use {@link WeaviateVectorStore#builder()} instead to configure and
+ * create instances of WeaviateVectorStore
*/
+ @Deprecated(forRemoval = true, since = "1.0.0-M5")
public static Builder builder() {
return new Builder();
}
/**
- * {@return the default config}
+ * Returns the default configuration.
+ * @return the default configuration
+ * @deprecated Use {@link WeaviateVectorStore#builder()} instead to configure and
+ * create instances of WeaviateVectorStore with default settings
*/
+ @Deprecated(forRemoval = true, since = "1.0.0-M5")
public static WeaviateVectorStoreConfig defaultConfig() {
return builder().build();
}
/**
- * https://weaviate.io/developers/weaviate/concepts/replication-architecture/consistency#tunable-consistency-strategies
+ * Defines the consistency levels for Weaviate operations.
+ *
+ * @see Weaviate
+ * Consistency Strategies
+ * @deprecated Use {@link WeaviateVectorStore.ConsistentLevel} instead. This enum
+ * will be removed in a future release. Example migration: {@code
+ * // Old approach:
+ * WeaviateVectorStoreConfig.ConsistentLevel level = WeaviateVectorStoreConfig.ConsistentLevel.QUORUM;
+ *
+ * // New approach:
+ * WeaviateVectorStore.ConsistentLevel level = WeaviateVectorStore.ConsistentLevel.QUORUM;
+ * }
+ * @since 1.0.0
*/
+ @Deprecated(forRemoval = true, since = "1.0.0-M5")
public enum ConsistentLevel {
/**
@@ -470,33 +729,91 @@ public class WeaviateVectorStore extends AbstractObservationVectorStore {
}
+ /**
+ * Represents a metadata field configuration for Weaviate vector store.
+ *
+ * @param name the name of the metadata field
+ * @param type the type of the metadata field
+ * @deprecated Use {@link WeaviateVectorStore.MetadataField} instead. This record
+ * will be removed in a future release. Example migration: {@code
+ * // Old approach:
+ * WeaviateVectorStoreConfig.MetadataField field = WeaviateVectorStoreConfig.MetadataField.text("field");
+ *
+ * // New approach:
+ * WeaviateVectorStore.MetadataField field = WeaviateVectorStore.MetadataField.text("field");
+ * }
+ * @since 1.0.0
+ */
+ @Deprecated(forRemoval = true, since = "1.0.0-M5")
public record MetadataField(String name, Type type) {
+ /**
+ * Creates a metadata field of type TEXT.
+ * @param name the name of the field
+ * @return a new MetadataField instance of type TEXT
+ * @throws IllegalArgumentException if name is null or empty
+ * @deprecated Use {@link WeaviateVectorStore.MetadataField#text(String)}
+ * instead
+ */
+ @Deprecated(forRemoval = true, since = "1.0.0-M5")
public static MetadataField text(String name) {
return new MetadataField(name, Type.TEXT);
}
+ /**
+ * Creates a metadata field of type NUMBER.
+ * @param name the name of the field
+ * @return a new MetadataField instance of type NUMBER
+ * @throws IllegalArgumentException if name is null or empty
+ * @deprecated Use {@link WeaviateVectorStore.MetadataField#number(String)}
+ * instead
+ */
+ @Deprecated(forRemoval = true, since = "1.0.0-M5")
public static MetadataField number(String name) {
return new MetadataField(name, Type.NUMBER);
}
+ /**
+ * Creates a metadata field of type BOOLEAN.
+ * @param name the name of the field
+ * @return a new MetadataField instance of type BOOLEAN
+ * @throws IllegalArgumentException if name is null or empty
+ * @deprecated Use {@link WeaviateVectorStore.MetadataField#bool(String)}
+ * instead
+ */
+ @Deprecated(forRemoval = true, since = "1.0.0-M5")
public static MetadataField bool(String name) {
return new MetadataField(name, Type.BOOLEAN);
}
+ /**
+ * Defines the supported types for metadata fields.
+ *
+ * @deprecated Use {@link WeaviateVectorStore.MetadataField.Type} instead.
+ * This enum will be removed in a future release.
+ * @since 1.0.0
+ */
+ @Deprecated(forRemoval = true, since = "1.0.0-M5")
public enum Type {
TEXT, NUMBER, BOOLEAN
}
-
}
+ /**
+ * Builder for WeaviateVectorStoreConfig.
+ *
+ * @deprecated Use {@link WeaviateVectorStore#builder()} instead to configure and
+ * create instances of WeaviateVectorStore
+ * @since 1.0.0
+ */
+ @Deprecated(forRemoval = true, since = "1.0.0-M5")
public static final class Builder {
private String objectClass = "SpringAiWeaviate";
- private ConsistentLevel consistencyLevel = WeaviateVectorStoreConfig.ConsistentLevel.ONE;
+ private ConsistentLevel consistencyLevel = ConsistentLevel.ONE;
private List