Skip to main content
Neo4j is an open-source graph database with integrated support for vector similarity search. It supports approximate nearest neighbor search, Euclidean and cosine similarity, and hybrid search that combines vector and keyword retrieval. This guide helps you get started with the Neo4j vector store. For detailed documentation of all Neo4jVectorStore features and configurations, see the API reference.

Overview

Integration details

Setup

Install @langchain/neo4j, the MongoDB-compatible neo4j-driver, @langchain/core, and an embeddings provider (this guide uses OpenAI embeddings):

Setup a Neo4j self hosted instance with docker-compose

Neo4j provides a prebuilt Docker image that can be used to quickly setup a self-hosted Neo4j database instance. Create a file below named docker-compose.yml:
docker-compose.yml
And then in the same directory, run docker compose up to start the container. You can find more information on how to setup Neo4j on their website.

Usage

Use retrievalQuery parameter to customize responses

Instantiate Neo4jVectorStore from existing graph

Metadata filtering

Security

Make sure that the database connection uses credentials that are narrowly-scoped to only include necessary permissions. Failure to do so may result in data corruption or loss, since the calling code may attempt commands that would result in deletion, mutation of data if appropriately prompted or reading sensitive data if such data is present in the database. The best way to guard against such negative outcomes is to (as appropriate) limit the permissions granted to the credentials used with this tool. For example, creating read only users for the database is a good way to ensure that the calling code cannot mutate or delete data.

API reference

For detailed documentation of all Neo4jVectorStore features and configurations, see the API reference.