/** * The {@code VectorStore} interface defines the operations for managing and querying * documents in a vector database. It extends {@link DocumentWriter} to support document * writing operations. Vector databases are specialized for AI applications, performing * similarity searches based on vector representations of data rather than exact matches. * This interface allows for adding, deleting, and searching documents based on their * similarity to a given query. */publicinterfaceVectorStoreextendsDocumentWriter, VectorStoreRetriever {
defaultStringgetName() {
returnthis.getClass().getSimpleName();
}
/** * Adds list of {@link Document}s to the vector store. * @param documents the list of documents to store. Throws an exception if the * underlying provider checks for duplicate IDs. */voidadd(List<Document> documents);
@Overridedefaultvoidaccept(List<Document> documents) {
add(documents);
}
/** * Deletes documents from the vector store. * @param idList list of document ids for which documents will be removed. */voiddelete(List<String> idList);
/** * Deletes documents from the vector store based on filter criteria. * @param filterExpression Filter expression to identify documents to delete * @throws IllegalStateException if the underlying delete causes an exception */voiddelete(Filter.ExpressionfilterExpression);
/** * Deletes documents from the vector store using a string filter expression. Converts * the string filter to an Expression object and delegates to * {@link #delete(Filter.Expression)}. * @param filterExpression String representation of the filter criteria * @throws IllegalArgumentException if the filter expression is null * @throws IllegalStateException if the underlying delete causes an exception */defaultvoiddelete(StringfilterExpression) {
SearchRequestsearchRequest = SearchRequest.builder().filterExpression(filterExpression).build();
Filter.ExpressiontextExpression = searchRequest.getFilterExpression();
Assert.notNull(textExpression, "Filter expression must not be null");
this.delete(textExpression);
}
/** * Returns 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: * Optional<NativeClientType> client = vectorStore.getNativeClient(); * * Note: Using Optional<?> will return the native client if one exists, rather than an * empty Optional. For type safety, prefer using the specific client type. * @return Optional containing native client if available, empty Optional otherwise * @param <T> The type of the native client */default <T> Optional<T> getNativeClient() {
returnOptional.empty();
}
/** * Builder interface for creating VectorStore instances. Implements a fluent builder * pattern for configuring observation-related settings. * * @param <T> the concrete builder type, enabling method chaining with the correct * return type */interfaceBuilder<TextendsBuilder<T>> {
/** * Sets the registry for collecting observations and metrics. Defaults to * {@link ObservationRegistry#NOOP} if not specified. * @param observationRegistry the registry to use for observations * @return the builder instance for method chaining */TobservationRegistry(ObservationRegistryobservationRegistry);
/** * Sets a custom convention for creating observations. If not specified, * {@link DefaultVectorStoreObservationConvention} will be used. * @param convention the custom observation convention to use * @return the builder instance for method chaining */TcustomObservationConvention(VectorStoreObservationConventionconvention);
/** * Sets the batching strategy. * @param batchingStrategy the strategy to use * @return the builder instance for method chaining */TbatchingStrategy(BatchingStrategybatchingStrategy);
/** * Builds and returns a new VectorStore instance with the configured settings. * @return a new VectorStore instance */VectorStorebuild();
}
}