Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ You can find more details in the [Reference Documentation](https://docs.spring.i
- [Moderation](https://docs.spring.io/spring-ai/reference/api/index.html#api/moderation)
* Portable API support across AI providers for both synchronous and streaming API options are supported. Access to [model-specific features](https://docs.spring.io/spring-ai/reference/api/chatmodel.html#_chat_options) is also available.
* [Structured Outputs](https://docs.spring.io/spring-ai/reference/api/structured-output-converter.html) - Mapping of AI Model output to POJOs.
* Support for all major [Vector Database providers](https://docs.spring.io/spring-ai/reference/api/vectordbs.html) such as *Apache Cassandra, Azure Vector Search, Chroma, Milvus, MongoDB Atlas, Neo4j, Oracle, PostgreSQL/PGVector, PineCone, Qdrant, Redis, and Weaviate*.
* Support for all major [Vector Database providers](https://docs.spring.io/spring-ai/reference/api/vectordbs.html) such as *Apache Cassandra, Azure Vector Search, Chroma, Milvus, MongoDB Atlas, MariaDB, Neo4j, Oracle, PostgreSQL/PGVector, PineCone, Qdrant, Redis, and Weaviate*.
* Portable API across Vector Store providers, including a novel SQL-like [metadata filter API](https://docs.spring.io/spring-ai/reference/api/vectordbs.html#metadata-filters).
* [Tools/Function Calling](https://docs.spring.io/spring-ai/reference/api/functions.html) - permits the model to request the execution of client-side tools and functions, thereby accessing necessary real-time information as required.
* [Observability](https://docs.spring.io/spring-ai/reference/observability/index.html) - Provides insights into AI-related operations.
Expand Down
29 changes: 16 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<module>vector-stores/spring-ai-elasticsearch-store</module>
<module>vector-stores/spring-ai-gemfire-store</module>
<module>vector-stores/spring-ai-hanadb-store</module>
<module>vector-stores/spring-ai-mariadb-store</module>
<module>vector-stores/spring-ai-milvus-store</module>
<module>vector-stores/spring-ai-mongodb-atlas-store</module>
<module>vector-stores/spring-ai-neo4j-store</module>
Expand All @@ -73,6 +74,7 @@
<module>spring-ai-spring-boot-starters/spring-ai-starter-elasticsearch-store</module>
<module>spring-ai-spring-boot-starters/spring-ai-starter-gemfire-store</module>
<module>spring-ai-spring-boot-starters/spring-ai-starter-hanadb-store</module>
<module>spring-ai-spring-boot-starters/spring-ai-starter-mariadb-store</module>
<module>spring-ai-spring-boot-starters/spring-ai-starter-milvus-store</module>
<module>spring-ai-spring-boot-starters/spring-ai-starter-mongodb-atlas-store</module>
<module>spring-ai-spring-boot-starters/spring-ai-starter-neo4j-store</module>
Expand Down Expand Up @@ -212,6 +214,7 @@
<qdrant.version>1.9.1</qdrant.version>
<typesense.version>0.5.0</typesense.version>
<opensearch-client.version>2.10.1</opensearch-client.version>
<mariadb.version>3.5.1</mariadb.version>
<commonmark.version>0.22.0</commonmark.version>

<!-- also managed by boot bom -->
Expand Down Expand Up @@ -678,28 +681,28 @@
<exclude>org.springframework.ai.vectorstore**/Hana**IT.java</exclude>
<exclude>org.springframework.ai.vectorstore**/Hana**IT.java</exclude>
<exclude>org.springframework.ai.vectorstore**/Milvus**IT.java</exclude>
<exclude>org.springframework.ai.vectorstore**/Mongo**IT.java</exclude>
<exclude>org.springframework.ai.vectorstore**/MariaDB**IT.java</exclude>
<exclude>org.springframework.ai.vectorstore**/Mongo**IT.java</exclude>
<exclude>org.springframework.ai.vectorstore**/Neo4j**IT.java</exclude>
<exclude>org.springframework.ai.vectorstore**/OpenSearch**IT.java</exclude>
<exclude>org.springframework.ai.vectorstore**/Oracle**IT.java</exclude>
<!-- <exclude>org.springframework.ai.vectorstore**/PgVector**IT.java</exclude> -->
<exclude>org.springframework.ai.vectorstore**/Pinecone**IT.java</exclude>
<exclude>org.springframework.ai.vectorstore**/Pinecone**IT.java</exclude>
<exclude>org.springframework.ai.vectorstore.qdrant/**/**IT.java</exclude>
<exclude>org.springframework.ai.vectorstore**/Qdrant**IT.java</exclude>
<exclude>org.springframework.ai.vectorstore**/Redis**IT.java</exclude>
<exclude>org.springframework.ai.vectorstore**/Typesense**IT.java</exclude>
<exclude>org.springframework.ai.vectorstore**/Weaviate**IT.java</exclude>

<!-- Auto-configurations-->

<!-- <exclude>org.springframework.ai.autoconfigure/**/**IT.java</exclude> -->

<exclude>org.springframework.ai.autoconfigure.anthropic/**/**IT.java</exclude>
<exclude>org.springframework.ai.autoconfigure.azure/**/**IT.java</exclude>
<exclude>org.springframework.ai.autoconfigure.bedrock/**/**IT.java</exclude>
<exclude>org.springframework.ai.autoconfigure.huggingface/**/**IT.java</exclude>

<exclude>org.springframework.ai.autoconfigure.chat/**/**IT.java</exclude>
<exclude>org.springframework.ai.autoconfigure.embedding/**/**IT.java</exclude>
<exclude>org.springframework.ai.autoconfigure.image/**/**IT.java</exclude>
Expand All @@ -713,24 +716,24 @@
<!-- <exclude>org.springframework.ai.autoconfigure.openai/**/**IT.java</exclude> -->
<exclude>org.springframework.ai.autoconfigure.postgresml/**/**IT.java</exclude>
<exclude>org.springframework.ai.autoconfigure.qianfan/**/**IT.java</exclude>

<exclude>org.springframework.ai.autoconfigure.retry/**/**IT.java</exclude>

<exclude>org.springframework.ai.autoconfigure.stabilityai/**/**IT.java</exclude>
<exclude>org.springframework.ai.autoconfigure.transformers/**/**IT.java</exclude>
<exclude>org.springframework.ai.autoconfigure.vectorstore/**/**IT.java</exclude>

<exclude>org.springframework.ai.autoconfigure.vectorstore/**/**IT.java</exclude>

<exclude>org.springframework.ai.autoconfigure.vertexai/**/**IT.java</exclude>
<exclude>org.springframework.ai.autoconfigure.watsonxai/**/**IT.java</exclude>
<exclude>org.springframework.ai.autoconfigure.zhipuai/**/**IT.java</exclude>

<exclude>org.springframework.ai.autoconfigure.zhipuai/**/**IT.java</exclude>
<!-- Test Containers -->

<!-- Test Containers -->
<exclude>org.springframework.ai.testcontainers/**/**IT.java</exclude>

<!-- Test Docker Compose -->
<!-- Test Docker Compose -->
<exclude>package org.springframework.ai.docker.compose/**/**IT.java</exclude>

<!-- AI Evaluation -->
Expand Down
12 changes: 12 additions & 0 deletions spring-ai-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-mariadb-store</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Utilities -->
<dependency>
<groupId>org.springframework.ai</groupId>
Expand Down Expand Up @@ -455,6 +461,12 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-mariadb-store-spring-boot-starter</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-stability-ai-spring-boot-starter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public enum VectorStoreProvider {
*/
HANA("hana"),

/**
* Vector store provided by MariaDB.
*/
MARIADB("mariadb"),

/**
* Vector store provided by Milvus.
*/
Expand Down
1 change: 1 addition & 0 deletions spring-ai-docs/src/main/antora/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
** xref:api/vectordbs/chroma.adoc[]
** xref:api/vectordbs/elasticsearch.adoc[]
** xref:api/vectordbs/gemfire.adoc[GemFire]
** xref:api/vectordbs/mariadb.adoc[]
** xref:api/vectordbs/milvus.adoc[]
** xref:api/vectordbs/mongodb.adoc[]
** xref:api/vectordbs/neo4j.adoc[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ These are the available implementations of the `VectorStore` interface:
* xref:api/vectordbs/chroma.adoc[Chroma Vector Store] - The https://www.trychroma.com/[Chroma] vector store.
* xref:api/vectordbs/elasticsearch.adoc[Elasticsearch Vector Store] - The https://www.elastic.co/[Elasticsearch] vector store.
* xref:api/vectordbs/gemfire.adoc[GemFire Vector Store] - The https://tanzu.vmware.com/content/blog/vmware-gemfire-vector-database-extension[GemFire] vector store.
* xref:api/vectordbs/mariadb.adoc[MariaDB Vector Store] - The https://mariadb.com/[MariaDB] vector store.
* xref:api/vectordbs/milvus.adoc[Milvus Vector Store] - The https://milvus.io/[Milvus] vector store.
* xref:api/vectordbs/mongodb.adoc[MongoDB Atlas Vector Store] - The https://www.mongodb.com/atlas/database[MongoDB Atlas] vector store.
* xref:api/vectordbs/neo4j.adoc[Neo4j Vector Store] - The https://neo4j.com/[Neo4j] vector store.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
= MariaDB Vector

This section walks you through setting up the MariaDB `VectorStore` to store document embeddings and perform similarity searches.

link:https://mariadb.org/projects/mariadb-vector/[MariaDB vector] is part of MariaDB 11.7 and enables storing and searching over machine learning-generated embeddings.

== Auto-Configuration

Add the MariaDBVectorStore boot starter dependency to your project:

[source,xml]
----
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-mariadb-store-spring-boot-starter</artifactId>
</dependency>
----

or to your Gradle `build.gradle` build file.

[source,groovy]
----
dependencies {
implementation 'org.springframework.ai:spring-ai-mariadb-store-spring-boot-starter'
}
----

The vector store implementation can initialize the required schema for you, but you must opt-in by specifying the `initializeSchema` boolean in the appropriate constructor or by setting `...initialize-schema=true` in the `application.properties` file.

The Vector Store also requires an `EmbeddingModel` instance to calculate embeddings for the documents.
You can pick one of the available xref:api/embeddings.adoc#available-implementations[EmbeddingModel Implementations].

For example, to use the xref:api/embeddings/openai-embeddings.adoc[OpenAI EmbeddingModel], add the following dependency to your project:

[source,xml]
----
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-openai-spring-boot-starter</artifactId>
</dependency>
----

or to your Gradle `build.gradle` build file.

[source,groovy]
----
dependencies {
implementation 'org.springframework.ai:spring-ai-openai-spring-boot-starter'
}
----

TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Management] section to add the Spring AI BOM to your build file.
Refer to the xref:getting-started.adoc#repositories[Repositories] section to add Milestone and/or Snapshot Repositories to your build file.

To connect to and configure the `MariaDBVectorStore`, you need to provide access details for your instance.
A simple configuration can be provided via Spring Boot's `application.yml`.

[yml]
----
spring:
datasource:
url: jdbc:mariadb://localhost/db
username: myUser
password: myPassword
ai:
vectorstore:
mariadbvector:
distance-type: COSINE
dimensions: 1536
----

TIP: If you run MariaDBvector as a Spring Boot dev service via link:https://docs.spring.io/spring-boot/reference/features/dev-services.html#features.dev-services.docker-compose[Docker Compose]
or link:https://docs.spring.io/spring-boot/reference/features/dev-services.html#features.dev-services.testcontainers[Testcontainers],
you don't need to configure URL, username and password since they are autoconfigured by Spring Boot.

TIP: Check the list of xref:#mariadbvector-properties[configuration parameters] to learn about the default values and configuration options.

Now you can auto-wire the `MariaDBVectorStore` in your application and use it

[source,java]
----
@Autowired VectorStore vectorStore;

// ...

List<Document> documents = List.of(
new Document("Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!!", Map.of("meta1", "meta1")),
new Document("The World is Big and Salvation Lurks Around the Corner"),
new Document("You walk forward facing the past and you turn back toward the future.", Map.of("meta2", "meta2")));

// Add the documents to PGVector
vectorStore.add(documents);

// Retrieve documents similar to a query
List<Document> results = this.vectorStore.similaritySearch(SearchRequest.query("Spring").withTopK(5));
----

[[mariadbvector-properties]]
=== Configuration properties

You can use the following properties in your Spring Boot configuration to customize the MariaDB vector store.

[cols="2,5,1",stripes=even]
|===
|Property| Description | Default value

|`spring.ai.vectorstore.mariadb.distance-type`| Search distance type. Defaults to `COSINE`. But if vectors are normalized to length 1, you can use `EUCLIDEAN` for best performance.| COSINE
|`spring.ai.vectorstore.mariadb.dimensions`| Embeddings dimension. If not specified explicitly the PgVectorStore will retrieve the dimensions form the provided `EmbeddingModel`. Dimensions are set to the embedding column the on table creation. If you change the dimensions your would have to re-create the vector_store table as well. | -
|`spring.ai.vectorstore.mariadb.remove-existing-vector-store-table` | Deletes the existing `vector_store` table on start up. | false
|`spring.ai.vectorstore.mariadb.initialize-schema` | Whether to initialize the required schema | false
|`spring.ai.vectorstore.mariadb.schema-name` | Vector store schema name | null
|`spring.ai.vectorstore.mariadb.table-name` | Vector store table name | `vector_store`
|`spring.ai.vectorstore.mariadb.schema-validation` | Enables schema and table name validation to ensure they are valid and existing objects. | false

|===

TIP: If you configure a custom schema and/or table name, consider enabling schema validation by setting `spring.ai.vectorstore.mariadb.schema-validation=true`.
This ensures the correctness of the names and reduces the risk of SQL injection attacks.

== Metadata filtering

You can leverage the generic, portable link:https://docs.spring.io/spring-ai/reference/api/vectordbs.html#_metadata_filters[metadata filters] with the MariaDB Vector store.

For example, you can use either the text expression language:

[source,java]
----
vectorStore.similaritySearch(
SearchRequest.defaults()
.withQuery("The World")
.withTopK(TOP_K)
.withSimilarityThreshold(SIMILARITY_THRESHOLD)
.withFilterExpression("author in ['john', 'jill'] && article_type == 'blog'"));
----

or programmatically using the `Filter.Expression` DSL:

[source,java]
----
FilterExpressionBuilder b = new FilterExpressionBuilder();

vectorStore.similaritySearch(SearchRequest.defaults()
.withQuery("The World")
.withTopK(TOP_K)
.withSimilarityThreshold(SIMILARITY_THRESHOLD)
.withFilterExpression(b.and(
b.in("author","john", "jill"),
b.eq("article_type", "blog")).build()));
----

NOTE: These filter expressions are converted into the equivalent PgVector filters.

== Manual Configuration

Instead of using the Spring Boot auto-configuration, you can manually configure the `MariaDBVectorStore`.
For this you need to add the MariaDB connector and `JdbcTemplate` auto-configuration dependencies to your project:

[source,xml]
----
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-mariadb-store</artifactId>
</dependency>
----

TIP: Refer to the xref:getting-started.adoc#dependency-management[Dependency Management] section to add the Spring AI BOM to your build file.

To configure MariaDB Vector in your application, you can use the following setup:

[source,java]
----
@Bean
public VectorStore vectorStore(JdbcTemplate jdbcTemplate, EmbeddingModel embeddingModel) {
return new MariaDBVectorStore(jdbcTemplate, embeddingModel);
}
----
3 changes: 1 addition & 2 deletions spring-ai-docs/src/main/antora/modules/ROOT/pages/index.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[[introduction]]
= Introduction

image::spring_ai_logo_with_text.svg[Integration Problem, width=300, align="left"]

Expand All @@ -26,7 +25,7 @@ Spring AI provides the following features:
** xref:api/audio/speech.adoc[Text to Speech]
** xref:api/moderation[Moderation]
* xref:api/structured-output-converter.adoc[Structured Outputs] - Mapping of AI Model output to POJOs.
* Support for all major xref:api/vectordbs.adoc[Vector Database providers] such as Apache Cassandra, Azure Cosmos DB, Azure Vector Search, Chroma, Elasticsearch, GemFire, Milvus, MongoDB Atlas, Neo4j, OpenSearch, Oracle, PostgreSQL/PGVector, PineCone, Qdrant, Redis, SAP Hana, Typesense and Weaviate.
* Support for all major xref:api/vectordbs.adoc[Vector Database providers] such as Apache Cassandra, Azure Cosmos DB, Azure Vector Search, Chroma, Elasticsearch, GemFire, MariaDB, Milvus, MongoDB Atlas, Neo4j, OpenSearch, Oracle, PostgreSQL/PGVector, PineCone, Qdrant, Redis, SAP Hana, Typesense and Weaviate.
* Portable API across Vector Store providers, including a novel SQL-like metadata filter API.
* xref:api/functions.adoc[Tools/Function Calling] - permits the model to request the execution of client-side tools and functions, thereby accessing necessary real-time information as required.
* xref:observability/index.adoc[Observability] - Provides insights into AI-related operations.
Expand Down
20 changes: 20 additions & 0 deletions spring-ai-spring-boot-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,20 @@
<optional>true</optional>
</dependency>

<!-- MariaDB Vector Store-->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-mariadb-store</artifactId>
<version>${project.parent.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>${mariadb.version}</version>
<optional>true</optional>
</dependency>

<!-- Chroma Vector Store -->
<dependency>
<groupId>org.springframework.ai</groupId>
Expand Down Expand Up @@ -457,6 +471,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mariadb</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
Loading
Loading