GemFire Vector Store

This section walks you through setting up the GemFireVectorStore to store document embeddings and perform similarity searches.spring-doc.cn

GemFire is a distributed, in-memory, key-value store performing read and write operations at blazingly fast speeds. It offers highly available parallel message queues, continuous availability, and an event-driven architecture you can scale dynamically without downtime. As your data size requirements increase to support high-performance, real-time apps, GemFire can easily scale linearly.spring-doc.cn

GemFire VectorDB extends GemFire’s capabilities, serving as a versatile vector database that efficiently stores, retrieves, and performs vector similarity searches.spring-doc.cn

Prerequisites

  1. A GemFire cluster with the GemFire VectorDB extension enabledspring-doc.cn

  2. An EmbeddingModel bean to compute the document embeddings. Refer to the EmbeddingModel section for more information. An option that runs locally on your machine is ONNX and the all-MiniLM-L6-v2 Sentence Transformers.spring-doc.cn

Auto-configuration

Add the GemFire VectorStore Spring Boot starter to you project’s Maven build file pom.xml:spring-doc.cn

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-gemfire-store-spring-boot-starter</artifactId>
</dependency>

or to your Gradle build.gradle filespring-doc.cn

dependencies {
    implementation 'org.springframework.ai:spring-ai-gemfire-store-spring-boot-starter'
}

Configuration properties

You can use the following properties in your Spring Boot configuration to further configure the GemFireVectorStore.spring-doc.cn

Property Default value

spring.ai.vectorstore.gemfire.hostspring-doc.cn

localhostspring-doc.cn

spring.ai.vectorstore.gemfire.portspring-doc.cn

8080spring-doc.cn

spring.ai.vectorstore.gemfire.initialize-schemaspring-doc.cn

falsespring-doc.cn

spring.ai.vectorstore.gemfire.index-namespring-doc.cn

spring-ai-gemfire-storespring-doc.cn

spring.ai.vectorstore.gemfire.beam-widthspring-doc.cn

100spring-doc.cn

spring.ai.vectorstore.gemfire.max-connectionsspring-doc.cn

16spring-doc.cn

spring.ai.vectorstore.gemfire.vector-similarity-functionspring-doc.cn

COSINEspring-doc.cn

spring.ai.vectorstore.gemfire.fieldsspring-doc.cn

[]spring-doc.cn

spring.ai.vectorstore.gemfire.bucketsspring-doc.cn

0spring-doc.cn

Manual Configuration

To use just the GemFireVectorStore, without Spring Boot’s Auto-configuration add the following dependency to your project’s Maven pom.xml:spring-doc.cn

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

For Gradle users, add the following to your build.gradle file under the dependencies block to use just the GemFireVectorStore:spring-doc.cn

dependencies {
    implementation 'org.springframework.ai:spring-ai-gemfire-store'
}

Usage

Here is a sample that creates an instance of the GemfireVectorStore instead of using AutoConfigurationspring-doc.cn

@Bean
public VectorStore vectorStore(EmbeddingModel embeddingModel) {
    return new GemFireVectorStore(new GemFireVectorStoreConfig()
                                    .setIndexName("my-vector-index")
                                    .setPort(7071), embeddingClient);
}

The GemFire VectorStore does not yet support metadata filters.spring-doc.cn

The default configuration connects to a GemFire cluster at localhost:8080spring-doc.cn

List<Document> documents = List.of(
   new Document("Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!!", Map.of("country", "UK", "year", 2020)),
   new Document("The World is Big and Salvation Lurks Around the Corner", Map.of()),
   new Document("You walk forward facing the past and you turn back toward the future.", Map.of("country", "NL", "year", 2023)));
vectorStore.add(documents);
  • And to retrieve documents using similarity search:spring-doc.cn

List<Document> results = vectorStore.similaritySearch(
   SearchRequest.query("Spring").withTopK(5));

You should retrieve the document containing the text "Spring AI rocks!!".spring-doc.cn

You can also limit the number of results using a similarity threshold:spring-doc.cn

List<Document> results = vectorStore.similaritySearch(
   SearchRequest.query("Spring").withTopK(5)
      .withSimilarityThreshold(0.5d));