Class WeaviateVectorStore
java.lang.Object
org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore
org.springframework.ai.vectorstore.weaviate.WeaviateVectorStore
- All Implemented Interfaces:
Consumer<List<Document>>,DocumentWriter,VectorStore,VectorStoreRetriever
A vector store implementation that stores and retrieves vectors in a Weaviate database.
Note: You can assign arbitrary metadata fields with your Documents. Later will be
persisted and managed as Document fields. But only the metadata keys listed in
filterMetadataFields can be used for similarity search
expression filters.
Example usage with builder:
// Create the vector store with builder
WeaviateVectorStore vectorStore = WeaviateVectorStore.builder(weaviateClient, embeddingModel)
.options(options) // Optional: use custom options
.consistencyLevel(ConsistentLevel.QUORUM) // Optional: Set consistency level (default: ONE)
.filterMetadataFields(List.of( // Optional: Configure filterable metadata fields
MetadataField.text("country"),
MetadataField.number("year")
))
.build();
- Since:
- 1.0.0
- Author:
- Christian Tzolov, EddĂș MelĂ©ndez, Josh Long, Soby Chacko, Thomas Vitale, Jonghoon Park
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic enumDefines the consistency levels for Weaviate operations.static final recordRepresents a metadata field configuration for Weaviate vector store. -
Field Summary
Fields inherited from class org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore
batchingStrategy, embeddingModel -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedProtected constructor for creating a WeaviateVectorStore instance using the builder pattern. -
Method Summary
Modifier and TypeMethodDescriptionstatic WeaviateVectorStore.Builderbuilder(io.weaviate.client.WeaviateClient weaviateClient, EmbeddingModel embeddingModel) Creates a new WeaviateBuilder instance.createObservationContextBuilder(String operationName) Create a newVectorStoreObservationContext.Builderinstance.voidPerform the actual add operation.voidPerform the actual delete operation.protected voiddoDelete(Filter.Expression filterExpression) Template method for concrete implementations to provide filter-based deletion logic.doSimilaritySearch(SearchRequest request) Perform the actual similarity search operation.<T> Optional<T> Returns the native client if available in this vector store implementation.Methods inherited from class org.springframework.ai.vectorstore.observation.AbstractObservationVectorStore
add, delete, delete, similaritySearchMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.ai.document.DocumentWriter
writeMethods inherited from interface org.springframework.ai.vectorstore.VectorStore
accept, delete, getNameMethods inherited from interface org.springframework.ai.vectorstore.VectorStoreRetriever
similaritySearch
-
Constructor Details
-
WeaviateVectorStore
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.- Parameters:
builder- theWeaviateVectorStore.Buildercontaining all configuration settings- Throws:
IllegalArgumentException- if the weaviateClient is null- Since:
- 1.0.0
- See Also:
-
-
Method Details
-
builder
public static WeaviateVectorStore.Builder builder(io.weaviate.client.WeaviateClient weaviateClient, EmbeddingModel embeddingModel) Creates a new WeaviateBuilder instance. This is the recommended way to instantiate a WeaviateVectorStore.- Returns:
- a new WeaviateBuilder instance
-
doAdd
Description copied from class:AbstractObservationVectorStorePerform the actual add operation.- Specified by:
doAddin classAbstractObservationVectorStore- Parameters:
documents- the documents to add
-
doDelete
Description copied from class:AbstractObservationVectorStorePerform the actual delete operation.- Specified by:
doDeletein classAbstractObservationVectorStore- Parameters:
documentIds- the list of document IDs to delete
-
doDelete
Description copied from class:AbstractObservationVectorStoreTemplate method for concrete implementations to provide filter-based deletion logic.- Overrides:
doDeletein classAbstractObservationVectorStore- Parameters:
filterExpression- Filter expression to identify documents to delete
-
doSimilaritySearch
Description copied from class:AbstractObservationVectorStorePerform the actual similarity search operation.- Specified by:
doSimilaritySearchin classAbstractObservationVectorStore- Parameters:
request- the search request- Returns:
- the list of documents that match the query request conditions
-
createObservationContextBuilder
Description copied from class:AbstractObservationVectorStoreCreate a newVectorStoreObservationContext.Builderinstance.- Specified by:
createObservationContextBuilderin classAbstractObservationVectorStore- Parameters:
operationName- the operation name- Returns:
- the observation context builder
-
getNativeClient
Description copied from interface:VectorStoreReturns the native client if available in this vector store implementation. Note on usage: 1. Returns empty Optional when no native client is available 2. Due to Java type erasure, runtime type checking is not possible Example usage: When working with implementation with known native client: Optionalclient = vectorStore.getNativeClient(); Note: Using Optionalinvalid input: '<'?> will return the native client if one exists, rather than an empty Optional. For type safety, prefer using the specific client type. - Type Parameters:
T- The type of the native client- Returns:
- Optional containing native client if available, empty Optional otherwise
-