This section walks you through setting up Neo4jVectorStore to store document embeddings and perform similarity searches.

Neo4j is an open-source NoSQL graph database. It is a fully transactional database (ACID) that stores data structured as graphs consisting of nodes, connected by relationships. Inspired by the structure of the real world, it allows for high query performance on complex data while remaining intuitive and simple for the developer.

The Neo4j’s Vector Search allows users to query vector embeddings from large datasets. An embedding is a numerical representation of a data object, such as text, image, audio, or document. Embeddings can be stored on Node properties and can be queried with the db.index.vector.queryNodes() function. Those indexes are powered by Lucene using a Hierarchical Navigable Small World Graph (HNSW) to perform a k approximate nearest neighbors (k-ANN) query over the vector fields.



Add the Neo4j Vector Store dependency to your project:


or to your Gradle build.gradle build file.

dependencies {
    implementation ''
Refer to the Dependency Management section to add the Spring AI BOM to your build file.


To connect to Neo4j and use the Neo4jVectorStore, you need to provide access details for your instance. A simple configuration can either be provided via Spring Boot’s,

# API key if needed, e.g. OpenAI<api-key>

environment variables,

export SPRING_NEO4J_URI=<uri_for_your_neo4j_instance>
# API key if needed, e.g. OpenAI
export SPRING_AI_OPENAI_API_KEY=<api-key>

or can be a mix of those. For example, if you want to store your API key as an environment variable but keep the rest in the plain file.

If you choose to create a shell script for ease in future work, be sure to run it prior to starting your application by "sourcing" the file, i.e. source <your_script_name>.sh.
Besides and environment variables, Spring Boot offers additional configuration options.

Spring Boot’s auto-configuration feature for the Neo4j Driver will create a bean instance that will be used by the Neo4jVectorStore.


Spring AI provides Spring Boot auto-configuration for the Neo4j Vector Sore. To enable it, add the following dependency to your project’s Maven pom.xml file:


or to your Gradle build.gradle build file.

dependencies {
    implementation ''
Refer to the Dependency Management section to add the Spring AI BOM to your build file.

Please have a look at the list of configuration parameters for the vector store to learn about the default values and configuration options.

Refer to the Repositories section to add Milestone and/or Snapshot Repositories to your build file.

Additionally, you will need a configured EmbeddingClient bean. Refer to the EmbeddingClient section for more information.

Here is an example of the needed bean:

public EmbeddingClient embeddingClient() {
    // Can be any other EmbeddingClient implementation.
    return new OpenAiEmbeddingClient(new OpenAiApi(System.getenv("SPRING_AI_OPENAI_API_KEY")));

In cases where the Spring Boot auto-configured Neo4j Driver bean is not what you want or need, you can still define your own bean. Please read the Neo4j Java Driver reference for more in-depth information about the configuration of a custom driver.

public Driver driver() {
    return GraphDatabase.driver("neo4j://<host>:<bolt-port>",
            AuthTokens.basic("<username>", "<password>"));

Now you can auto-wire the Neo4jVectorStore as a vector store in your application.

Metadata filtering

You can leverage the generic, portable metadata filters with Neo4j store as well.

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

                            .withQuery("The World")
                            .withFilterExpression("author in ['john', 'jill'] && 'article_type' == 'blog'"));

or programmatically using the Filter.Expression DSL:

FilterExpressionBuilder b = new FilterExpressionBuilder();

                    .withQuery("The World")
                  "john", "jill"),
                            b.eq("article_type", "blog")).build()));
Those (portable) filter expressions get automatically converted into the proprietary Neo4j WHERE filter expressions.

For example, this portable filter expression:

author in ['john', 'jill'] && 'article_type' == 'blog'

is converted into the proprietary Neo4j filter format:

node.`` IN ["john","jill"] AND node.`metadata.'article_type'` = "blog"

Neo4jVectorStore properties

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

Property Default value